Skip to content

Commit

Permalink
adds detect retina; refs bozdoz#100
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin DeLong committed Mar 25, 2020
1 parent cc38b07 commit 0d7d156
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
10 changes: 10 additions & 0 deletions class.plugin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ private function __construct()
$foreachmap
)
),
'detect_retina' => array(
'display_name' => __('Detect Retina', 'leaflet-map'),
'default' => '0',
'type' => 'checkbox',
'helptext' => sprintf(
'%1$s %2$s <br /> <code>[leaflet-map detect-retina]</code>',
__('Fetch tiles at different zoom levels to appear smoother on retina displays.', '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
5 changes: 4 additions & 1 deletion shortcodes/class.map-shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ protected function getHTML($atts='', $content=null)
$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;
}

/* should be iterated for multiple maps */
Expand All @@ -220,7 +222,8 @@ protected function getHTML($atts='', $content=null)
var baseUrl = '<?php echo $tileurl; ?>',
base = (!baseUrl && window.MQ) ?
MQ.mapLayer() : L.tileLayer(baseUrl, {
subdomains: '<?php echo $subdomains; ?>'
subdomains: '<?php echo $subdomains; ?>',
detectRetina: <?php echo $detect_retina; ?>,
}),
options = L.Util.extend({}, {
maxZoom: <?php echo $max_zoom; ?>,
Expand Down
14 changes: 11 additions & 3 deletions shortcodes/class.shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@ public static function shortcode($atts = '', $content = null)
!!$v
) {
// false if starts with !, else true
if ($v[0] == '!') {
$atts[substr($v, 1)] = 0;
if ($v[0] === '!') {
$k = substr($v, 1);
$v = 0;
} else {
$atts[$v] = 1;
$k = $v;
$v = 1;
}
$atts[$k] = $v;
}
// change hyphens to underscores for `extract()`
if (strpos($k, '-')) {
$k = str_replace('-', '_', $k);
$atts[$k] = $v;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions templates/shortcode-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
'[leaflet-marker draggable]',
),
__("Marker Icon", 'leaflet-map') => array(
'[leaflet-map zoom=14 address="Ha Ling, canmore" scrollwheel]',
'[leaflet-map zoom=14 address="Ha Ling, canmore" scrollwheel !detect-retina]',
'[leaflet-marker iconUrl="https://i.imgur.com/Q54ueuO.png" iconSize="80,50" iconAnchor="40,60"]'
),
__("SVG Marker Icon", 'leaflet-map') => array(
'[leaflet-map address="twilight lane, nova scotia" scrollwheel]',
'[leaflet-marker svg background="#777" iconClass="dashicons dashicons-star-filled" color="gold"]My Favorite Place in the World[/leaflet-marker]'
),
__("Zoom Buttons", 'leaflet-map') => array(
'[leaflet-map zoom=9 lat=48.855 lng=2.35 zoomcontrol]',
'[leaflet-map zoom=10 lat=48.855 lng=2.35 zoomcontrol !detect-retina]',
),
__("Alternate Map Tiles w/scrollwheel", 'leaflet-map') => array(
'[leaflet-map zoom=2 scrollwheel lat=-2.507 lng=32.902 tileurl=https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg subdomains=abcd attribution="Map tiles by Stamen Design, under CC BY 3.0."]',
Expand All @@ -74,7 +74,7 @@
'[leaflet-marker]OSLO![/leaflet-marker]',
),
__("Links In Marker Messages (visible)", 'leaflet-map') => array(
'[leaflet-map lat=28.41 lng=-81.58 zoom=15]',
'[leaflet-map lat=28.41 lng=-81.58 zoom=15 detect-retina]',
'[leaflet-marker visible] Disney World! <a href="https://disneyworld.disney.go.com">Link</a> [/leaflet-marker]',
),
__("Basic Lines w/Scrollwheel", 'leaflet-map') => array(
Expand Down

0 comments on commit 0d7d156

Please sign in to comment.