Skip to content

Commit

Permalink
adds tilesize, mapid, accesstoken, zoomoffset, tile_no_wrap to leafle…
Browse files Browse the repository at this point in the history
…t-map shortcode and default settings
  • Loading branch information
bozdoz committed Nov 24, 2020
1 parent 484a7d9 commit 2c7bf93
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ However, you can also just give it an address, and the chosen geocoder (default:
| `tileurl` | 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' |
| `subdomains` | 'abc' |
| `tap` | true |
| `tilesize` | 256 |
| `mapid` | null |
| `accesstoken` | null |
| `zoomoffset` | 0 |
| `nowrap` | false |

---

Expand Down
60 changes: 55 additions & 5 deletions class.plugin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private function __construct()
'default_lat' => array(
'display_name'=>__('Default Latitude', 'leaflet-map'),
'default'=>'44.67',
'type' => 'text',
'type' => 'number',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map lat="44.67"]</code>',
__('Default latitude for maps.', 'leaflet-map'),
Expand All @@ -90,7 +90,7 @@ private function __construct()
'default_lng' => array(
'display_name'=>__('Default Longitude', 'leaflet-map'),
'default'=>'-63.61',
'type' => 'text',
'type' => 'number',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map lng="-63.61"]</code>',
__('Default longitude for maps.', 'leaflet-map'),
Expand All @@ -100,7 +100,7 @@ private function __construct()
'default_zoom' => array(
'display_name'=>__('Default Zoom', 'leaflet-map'),
'default'=>'12',
'type' => 'text',
'type' => 'number',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map zoom="5"]</code>',
__('Default zoom for maps.', 'leaflet-map'),
Expand Down Expand Up @@ -170,7 +170,7 @@ private function __construct()
'default_min_zoom' => array(
'display_name'=>__('Default Min Zoom', 'leaflet-map'),
'default' => '0',
'type' => 'text',
'type' => 'number',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map min_zoom="1"]</code>',
__('Restrict the viewer from zooming in past the minimum zoom. Can set per map in shortcode or adjust for all maps here.', 'leaflet-map'),
Expand All @@ -180,7 +180,7 @@ private function __construct()
'default_max_zoom' => array(
'display_name'=>__('Default Max Zoom', 'leaflet-map'),
'default' => '20',
'type' => 'text',
'type' => 'number',
'helptext' => sprintf(
'%1$s %2%s <br /> <code>%3$s</code>',
__('Restrict the viewer from zooming out past the maximum zoom. Can set per map in shortcode or adjust for all maps here', 'leaflet-map'),
Expand Down Expand Up @@ -245,6 +245,56 @@ private function __construct()
$foreachmap
)
),
'tilesize' => array(
'display_name' => __('Tile Size', 'leaflet-map'),
'default' => null,
'type' => 'text',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map tilesize=512]</code>',
__('Width and height of tiles (in pixels) in the grid. Default is 256', 'leaflet-map'),
$foreachmap
)
),
'mapid' => array(
'display_name' => __('Tile Id', 'leaflet-map'),
'default' => null,
'type' => 'text',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map mapid="mapbox/streets-v11"]</code>',
__('An id that is passed to L.tileLayer; useful for Mapbox', 'leaflet-map'),
$foreachmap
)
),
'accesstoken' => array(
'display_name' => __('Access Token', 'leaflet-map'),
'default' => null,
'type' => 'text',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map accesstoken="your.mapbox.access.token"]</code>',
__('An access token that is passed to L.tileLayer; useful for Mapbox tiles', 'leaflet-map'),
$foreachmap
)
),
'zoomoffset' => array(
'display_name' => __('Zoom Offset', 'leaflet-map'),
'default' => null,
'type' => 'number',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map zoomoffset="-1"]</code>',
__('The zoom number used in tile URLs will be offset with this value', 'leaflet-map'),
$foreachmap
)
),
'tile_no_wrap' => array(
'display_name' => __('No Wrap (tiles)', 'leaflet-map'),
'default' => '0',
'type' => 'checkbox',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map nowrap]</code>',
__('Boolean for whether the layer is wrapped around the antimeridian', 'leaflet-map'),
$foreachmap
)
),
'js_url' => array(
'display_name'=>__('JavaScript URL', 'leaflet-map'),
'default' => sprintf('https://unpkg.com/leaflet@%s/dist/leaflet.js', $leaflet_version),
Expand Down
30 changes: 21 additions & 9 deletions shortcodes/class.map-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ protected function getAtts($atts='')

$atts['raw_map_options'] = $this->LM->rawDict($raw_map_options);

$tile_layer_options = array(
'tileSize' => empty($tilesize) ? $settings->get('tilesize') : $tilesize,
'subdomains' => empty($subdomains) ? $settings->get('map_tile_url_subdomains') : $subdomains,
'id' => empty($mapid) ? $settings->get('mapid') : $mapid,
'accessToken' => empty($accesstoken) ? $settings->get('accesstoken') : $accesstoken,
'zoomOffset' => empty($zoomoffset) ? $settings->get('zoomoffset') : $zoomoffset,
'noWrap' => filter_var(empty($nowrap) ? $settings->get('tile_no_wrap') : $nowrap, FILTER_VALIDATE_BOOLEAN),
);

$tile_layer_options = $this->LM->filter_empty_string($tile_layer_options);
$tile_layer_options = $this->LM->filter_null($tile_layer_options);

$atts['tile_layer_options'] = json_encode($tile_layer_options);

return $atts;
}

Expand Down Expand Up @@ -227,11 +241,8 @@ protected function getHTML($atts='', $content=null)
*/
if (wp_script_is('leaflet_mapquest_plugin', 'registered')) {
$tileurl = '';
$subdomains = '';
} else {
$tileurl = empty($tileurl) ? $settings->get('map_tile_url') : $tileurl;
$subdomains = empty($subdomains) ?
$settings->get('map_tile_url_subdomains') : $subdomains;
}

$detect_retina = empty($detect_retina) ? $settings->get('detect_retina') : $detect_retina;
Expand Down Expand Up @@ -259,12 +270,13 @@ protected function getHTML($atts='', $content=null)
window.WPLeafletMapPlugin.push(function () {
var baseUrl = '<?php echo $tileurl; ?>';
var base = (!baseUrl && window.MQ) ?
MQ.mapLayer() : L.tileLayer(baseUrl, {
subdomains: '<?php echo $subdomains; ?>',
detectRetina: <?php echo $detect_retina; ?>,
minZoom: <?php echo $tile_min_zoom; ?>,
maxZoom: <?php echo $tile_max_zoom; ?>,
});
MQ.mapLayer() : L.tileLayer(baseUrl,
L.Util.extend({}, {
detectRetina: <?php echo $detect_retina; ?>,
minZoom: <?php echo $tile_min_zoom; ?>,
maxZoom: <?php echo $tile_max_zoom; ?>,
}, <?php echo $tile_layer_options; ?>)
);
var options = L.Util.extend({}, {
maxZoom: <?php echo $max_zoom; ?>,
minZoom: <?php echo $min_zoom; ?>,
Expand Down

0 comments on commit 2c7bf93

Please sign in to comment.