diff --git a/assets/js/admin/sp-geocoder.js b/assets/js/admin/sp-geocoder.js
index 1cb263573..31fd98080 100644
--- a/assets/js/admin/sp-geocoder.js
+++ b/assets/js/admin/sp-geocoder.js
@@ -16,9 +16,9 @@ var map = L.map( 'sp-location-picker' ).setView( [latitude, longitude], 15
marker = L.marker( [latitude, longitude],{draggable: true, autoPan: true} ).addTo( map );
L.tileLayer(
- 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
+ sp_osm_settings["tile_server"],
{
- attribution: '© OpenStreetMap contributors'
+ attribution: sp_osm_settings["attribution"]
}
).addTo( map );
diff --git a/includes/admin/settings/class-sp-settings-general.php b/includes/admin/settings/class-sp-settings-general.php
index 37aa0fe4e..5f6d3b6e4 100644
--- a/includes/admin/settings/class-sp-settings-general.php
+++ b/includes/admin/settings/class-sp-settings-general.php
@@ -247,6 +247,42 @@ public function get_settings() {
);
}
+ $options = array_merge(
+ $options,
+ array(
+ array(
+ 'type' => 'sectionend',
+ 'id' => 'general_options',
+ ),
+ array(
+ 'title' => esc_attr__( 'OpenStreetMap', 'sportspress' ),
+ 'type' => 'title',
+ 'desc' => '',
+ 'id' => 'osm_options',
+ ),
+ array(
+ 'title' => esc_attr__( 'Tile server', 'sportspress' ),
+ 'id' => 'sportspress_osm_tile_server',
+ 'placeholder' => 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
+ 'css' => 'width:100%;',
+ 'type' => 'text',
+ 'desc' => esc_attr__('Leave empty to use the default', 'sportspress'),
+ ),
+ array(
+ 'title' => esc_attr__( 'Attributions', 'sportspress' ),
+ 'id' => 'sportspress_osm_attribution',
+ 'placeholder' => 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
+ 'css' => 'width:100%;',
+ 'type' => 'text',
+ 'desc' => esc_attr__('Leave empty to use the default', 'sportspress'),
+ ),
+ array(
+ 'type' => 'sectionend',
+ 'id' => 'general_options',
+ ),
+ )
+ );
+
$settings = array_merge(
$settings,
apply_filters( 'sportspress_script_styling_options', $options ),
diff --git a/modules/sportspress-openstreetmap.php b/modules/sportspress-openstreetmap.php
index ab37e5b50..1d6ebf3f3 100644
--- a/modules/sportspress-openstreetmap.php
+++ b/modules/sportspress-openstreetmap.php
@@ -36,7 +36,7 @@ public function __construct() {
add_action( 'sp_admin_venue_scripts', array( $this, 'admin_venue_scripts' ) );
add_action( 'sp_frontend_venue_scripts', array( $this, 'frontend_venue_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
- add_action( 'sp_venue_show_map', array( $this, 'show_venue_map' ), 10, 5 );
+ add_action( 'sp_venue_show_map', array( $this, 'show_venue_map' ), 10, 6 );
add_action( 'sp_admin_geocoder_scripts', array( $this, 'admin_geocoder_scripts' ), 10 );
add_action( 'sp_setup_geocoder_scripts', array( $this, 'setup_geocoder_scripts' ), 10 );
add_action( 'sp_setup_venue_geocoder_scripts', array( $this, 'setup_venue_geocoder_scripts' ), 10 );
@@ -70,7 +70,25 @@ public function admin_scripts() {
* Enqueue admin venue scripts
*/
public function admin_venue_scripts() {
- $screen = get_current_screen();
+ $screen = get_current_screen();
+
+ $maptype = get_option( 'sportspress_map_type', 'roadmap' );
+ $maptype = strtolower( $maptype );
+ $osm_tile = get_option( 'sportspress_osm_tile_server', '' );
+ $osm_tile = strtolower( $osm_tile );
+ $osm_tile = empty( $osm_tile ) ? 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' : $osm_tile;
+ $osm_attribution = get_option( 'sportspress_osm_attribution', '' );
+ $osm_attribution = empty( $osm_attribution ) ? 'Map data © OpenStreetMap contributors' : $osm_attribution;
+ if ( 'satellite' === $maptype ) {
+ $osm_tile = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
+ $osm_attribution = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';
+ }
+ $osm_config = [
+ 'tile_server' => $osm_tile,
+ 'attribution' => $osm_attribution,
+ ];
+
+
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.8.0' );
@@ -81,6 +99,7 @@ public function admin_venue_scripts() {
wp_register_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.8.0' );
wp_register_script( 'control-geocoder', SP()->plugin_url() . '/assets/js/Control.Geocoder.min.js', array( 'leaflet_js' ), '1.13.0' );
wp_register_script( 'sportspress-admin-geocoder', SP()->plugin_url() . '/assets/js/admin/sp-geocoder.js', array( 'leaflet_js', 'control-geocoder' ), SP_VERSION, true );
+ wp_localize_script( 'sportspress-admin-geocoder', 'sp_osm_settings', $osm_config );
}
if ( in_array( $screen->id, array( 'edit-sp_venue' ) ) ) {
@@ -113,7 +132,7 @@ public function frontend_venue_scripts() {
*
* @return mix
*/
- public function show_venue_map( $latitude, $longitude, $address, $zoom, $maptype ) {
+ public function show_venue_map( $latitude, $longitude, $address, $zoom, $osm_tile, $osm_attribution ) {
$lat = abs( $latitude );
$lat_deg = floor( $lat );
$lat_sec = ( $lat - $lat_deg ) * 3600;
@@ -136,17 +155,10 @@ public function show_venue_map( $latitude, $longitude, $address, $zoom, $maptype
// initialize map
map = L.map('sp_openstreetmaps_container', { zoomControl:false }).setView([lat, lon], );
// set map tiles source
-
- L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
- attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community',
- maxZoom: 18,
- }).addTo(map);
-
- L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
- attribution: 'Map data © OpenStreetMap contributors',
+ L.tileLayer('', {
+ attribution: '',
maxZoom: 18,
}).addTo(map);
-
// add marker to the map
marker = L.marker([lat, lon]).addTo(map);
map.dragging.disable();
diff --git a/templates/venue-map.php b/templates/venue-map.php
index d86250fad..1d4283e42 100644
--- a/templates/venue-map.php
+++ b/templates/venue-map.php
@@ -26,16 +26,23 @@
$zoom = get_option( 'sportspress_map_zoom', 15 );
$maptype = get_option( 'sportspress_map_type', 'roadmap' );
$maptype = strtolower( $maptype );
+$osm_tile = get_option( 'sportspress_osm_tile_server', '' );
+$osm_tile = strtolower( $osm_tile );
+$osm_tile = empty( $osm_tile ) ? 'https://tile.openstreetmap.org/{z}/{x}/{y}.png' : $osm_tile;
+$osm_attribution = get_option( 'sportspress_osm_attribution', '' );
+$osm_attribution = empty( $osm_attribution ) ? 'Map data © OpenStreetMap contributors' : $osm_attribution;
if ( '' === $address ) {
$address = '+';
}
-if ( 'satellite' !== $maptype ) {
- $maptype = 'roadmap';
+if ( 'satellite' === $maptype ) {
+ $osm_tile = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}';
+ $osm_attribution = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community';
}
+
if ( $latitude != null && $longitude != null ) {
- do_action( 'sp_venue_show_map', $latitude, $longitude, $address, $zoom, $maptype );
+ do_action( 'sp_venue_show_map', $latitude, $longitude, $address, $zoom, $osm_tile, $osm_attribution );
}
if ( is_tax( 'sp_venue' ) ) {
do_action( 'sportspress_after_venue_map' );