Plugin Directory

Changeset 1709145 for leaflet-map


Ignore:
Timestamp:
08/06/2017 03:31:13 PM (9 years ago)
Author:
bozdoz
Message:

2.8.1 removed paragraph tags from shortcodes

Location:
leaflet-map
Files:
1 deleted
3 edited
13 copied

Legend:

Unmodified
Added
Removed
  • leaflet-map/tags/2.8.1/leaflet-map.php

    r1708977 r1709145  
    66    Author: bozdoz
    77    Author URI: https://twitter.com/bozdoz/
    8     Version: 2.8.0
     8    Version: 2.8.1
    99    License: GPL2
    1010
     
    636636
    637637            /* should be iterated for multiple maps */
    638             $content = '<div id="leaflet-wordpress-map-'.$leaflet_map_count.'" class="leaflet-wordpress-map" style="height:'.$height.'; width:'.$width.';"></div>';
    639 
    640             $content .= "<script>
     638            ob_start(); ?>
     639            <div
     640                id="leaflet-wordpress-map-<?php echo $leaflet_map_count; ?>"
     641                class="leaflet-wordpress-map"
     642                style="height:<?php echo $height; ?>; width:<?php echo $width; ?>;"></div>
     643            <script>
    641644            WPLeafletMapPlugin.add(function () {
    642                 var baseUrl = '{$tileurl}',
     645                var baseUrl = '<?php echo $tileurl; ?>',
    643646                    base = (!baseUrl && window.MQ) ? MQ.mapLayer() : L.tileLayer(baseUrl, {
    644                        subdomains: '{$subdomains}'
     647                       subdomains: '<?php echo $subdomains; ?>'
    645648                    }),
    646649                    options = L.Util.extend({}, {
    647                         maxZoom: {$max_zoom},
    648                         minZoom: {$min_zoom},
     650                        maxZoom: <?php echo $max_zoom; ?>,
     651                        minZoom: <?php echo $min_zoom; ?>,
    649652                        layers: [base],
    650                         zoomControl: {$zoomcontrol},
    651                         scrollWheelZoom: {$scrollwheel},
    652                         doubleClickZoom: {$doubleclickzoom},
     653                        zoomControl: <?php echo $zoomcontrol; ?>,
     654                        scrollWheelZoom: <?php echo $scrollwheel; ?>,
     655                        doubleClickZoom: <?php echo $doubleclickzoom; ?>,
    653656                        attributionControl: false
    654                     }, {$more_options}),
    655                     map = L.map('leaflet-wordpress-map-{$leaflet_map_count}', options).setView([{$lat}, {$lng}], {$zoom});
    656                 if ({$fit_markers}) {
     657                    }, <?php echo $more_options; ?>),
     658                    map = L.map('leaflet-wordpress-map-<?php echo $leaflet_map_count; ?>', options).setView([<?php echo $lat . ',' . $lng . '],' . $zoom; ?>);
     659                if (<?php echo $fit_markers; ?>) {
    657660                    map.fit_markers = true;
    658661                }
    659                 ";
    660                
     662            <?php
    661663                if ($attribution) {
    662664                    /* add any attributions, semi-colon-separated */
    663665                    $attributions = explode(';', $attribution);
    664666
    665                     $content .= "var attControl = L.control.attribution({prefix:false}).addTo(map);";
     667                    ?>
     668                    var attControl = L.control.attribution({prefix:false}).addTo(map);
     669                    <?php
    666670
    667671                    foreach ($attributions as $a) {
    668                         $a = trim($a);
    669                         $content .= "attControl.addAttribution('{$a}');";
     672                        ?>
     673                        attControl.addAttribution('<?php echo trim($a); ?>');
     674                        <?php
    670675                    }
    671676                }
    672 
    673                 $content .= "
    674                 WPLeafletMapPlugin.maps.push(map);
     677            ?>
     678            WPLeafletMapPlugin.maps.push(map);
    675679            }); // end add
    676             </script>";
    677 
    678             return $content;
     680            </script> <?php
     681
     682            return ob_get_clean();
    679683        }
    680684
     
    728732            $width .= is_numeric($width) ? 'px' : '';   
    729733           
    730             $content = '<div id="leaflet-wordpress-image-'.$leaflet_map_count.'" class="leaflet-wordpress-map" style="height:'.$height.'; width:'.$width.';"></div>';
    731 
    732             $content .= "<script>
     734            ob_start();
     735            ?>
     736            <div
     737                id="leaflet-wordpress-image-<?php echo leaflet_map_count; ?>"
     738                class="leaflet-wordpress-map"
     739                style="height:<?php echo height; ?>; width:<?php echo width; ?>;"></div>
     740            <script>
    733741            WPLeafletMapPlugin.add(function () {
    734742                var map,
    735                     image_src = '$source',
     743                    image_src = '<?php echo $source; ?>',
    736744                    img = new Image(),
    737                     zoom = $zoom;
    738 
     745                    zoom = <?php echo $zoom; ?>;
    739746                img.onload = function() {
    740747                    var center_h = img.height / (zoom * 4),
     
    748755                };
    749756                img.src = image_src;
    750 
    751                 map = L.map('leaflet-wordpress-image-{$leaflet_map_count}', {
     757                map = L.map('leaflet-wordpress-image-<?php echo $leaflet_map_count; ?>', {
    752758                    maxZoom: 10,
    753759                    minZoom: 1,
    754760                    crs: L.CRS.Simple,
    755                     zoomControl: {$zoomcontrol},
    756                     scrollWheelZoom: {$scrollwheel}
     761                    zoomControl: <?php echo $zoomcontrol ?>,
     762                    scrollWheelZoom: <?php echo $scrollwheel ?>
    757763                }).setView([0, 0], zoom);
    758764
     
    763769                WPLeafletMapPlugin.images.push( img );
    764770            }); // end add
    765             </script>";
    766 
    767             return $content;
     771            </script>
     772            <?php
     773            return ob_get_clean();
    768774        }
    769775
     
    862868            }
    863869
     870            if ($content) {
     871                $content = htmlspecialchars($content);
     872            }
     873
    864874            /* only required field for geojson */
    865875            $src = empty($src) ? $default : $src;
     
    878888            $popup_property = empty($popup_property) ? '' : $popup_property;
    879889
    880             $geojson_script = "<script>
     890            $popup_text = trim($popup_text);
     891
     892            ob_start();
     893            ?>
     894            <script>
    881895                WPLeafletMapPlugin.add(function () {
    882896                    var previous_map = WPLeafletMapPlugin.getCurrentMap(),
    883                         src = '{$src}',
    884                         default_style = {$style_json},
     897                        src = '<?php echo $src; ?>',
     898                        default_style = <?php echo $style_json; ?>,
    885899                        rewrite_keys = {
    886900                            fill : 'fillColor',
     
    890904                            'stroke-width' : 'width',
    891905                        },
    892                         layer = L.{$L_method}(src, {
     906                        layer = L.<?php echo $L_method; ?>(src, {
    893907                            style : layerStyle,
    894908                            onEachFeature : onEachFeature
    895909                        }),
    896                         fitbounds = {$fitbounds},
    897                         popup_text = '{$popup_text}',
    898                         popup_property = '{$popup_property}';
     910                        fitbounds = <?php echo $fitbounds; ?>,
     911                        popup_text = WPLeafletMapPlugin.unescape('<?php echo $popup_text; ?>'),
     912                        popup_property = '<?php echo $popup_property; ?>';
    899913                    if (fitbounds) {
    900914                        layer.on('ready', function () {
     
    929943                    }         
    930944                });
    931                 </script>";
    932 
    933             return $geojson_script;
     945            </script>
     946            <?php
     947
     948            return ob_get_clean();
    934949        }
    935950
     
    958973
    959974        public function kml_shortcode ( $atts, $content = null ) {
    960            
    961975            return self::get_shape( $atts, $content, 'leaflet_ajax_kml_js', 'ajaxKML', 'https://cdn.rawgit.com/mapbox/togeojson/master/test/data/polygon.kml');
    962            
    963976        }
    964977
     
    970983        * @param string $content    text to display
    971984        * @param string $shape      JavaScript variable for shape
    972         * @return string JavaScript
     985        * @return null
    973986        */
    974987
     
    977990
    978991            $message = empty($message) ? (empty($content) ? '' : $content) : $message;
     992            $message = htmlspecialchars($message);
    979993            $visible = empty($visible) ? false : ($visible == 'true');
    980994
    981             $output = '';
    982 
    983995            if (!empty($message)) {
     996                /*
    984997                $message = str_replace("\n", '', $message);
    985 
    986                 $output .= "$shape.bindPopup('$message')";
     998                */
     999
     1000                echo "{$shape}.bindPopup(WPLeafletMapPlugin.unescape('{$message}'))";
    9871001
    9881002                if ($visible) {
    989                     $output .= ".openPopup()";
     1003                    echo ".openPopup()";
    9901004                }
    9911005
    992                 $output .= ";";
    993             }
    994 
    995             return $output;
     1006                echo ";";
     1007            }
    9961008        }
    9971009
     
    10641076                $options = '{}';
    10651077            }
    1066 
    1067             $marker_script = "<script>
     1078            ob_start();
     1079            ?>
     1080            <script>
    10681081            WPLeafletMapPlugin.add(function () {
    10691082                var marker_options = (function () {
    1070                         var _options = {$options},
    1071                             iconArrays = ['iconSize', 'iconAnchor', 'shadowSize', 'shadowAnchor'];
     1083                        var _options = <?php echo $options; ?>,
     1084                            iconArrays = ['iconSize', 'iconAnchor',
     1085                                'shadowSize', 'shadowAnchor'];
    10721086                        if (_options.iconUrl) {
    10731087                            // arrays are strings, unfortunately...
     
    10841098                    })(),
    10851099                    draggable = marker_options.draggable,
    1086                     marker = L.marker([{$lat}, {$lng}], marker_options),
     1100                    marker = L.marker([<?php echo $lat . ',' . $lng; ?>], marker_options),
    10871101                    previous_map = WPLeafletMapPlugin.getCurrentMap(),
    10881102                    is_image = previous_map.is_image_map,
    10891103                    previous_map_onload,
    10901104                    markergroup = WPLeafletMapPlugin.getCurrentMarkerGroup();
    1091                 ";
    1092 
     1105            <?php
    10931106                if (empty($lat) && empty($lng)) {
    10941107                    /* update lat lng to previous map's center */
    1095                     $marker_script .= "
    1096                     if ( is_image &&
     1108            ?>
     1109                    if (is_image &&
    10971110                        !previous_map.is_loaded) {
    10981111                        previous_map_onload = previous_map.onload;
     
    11061119                        marker.setLatLng( previous_map.getCenter() );
    11071120                    }
    1108                     ";
     1121            <?php
    11091122                }
    1110 
    1111             $marker_script .= "
    1112             if (draggable) {
    1113                 marker.on('dragend', function () {
    1114                     var latlng = this.getLatLng(),
    1115                         lat = latlng.lat,
    1116                         lng = latlng.lng;
    1117                     if (is_image) {
    1118                         console.log('leaflet-marker y=' + lat + ' x=' + lng);
    1119                     } else {
    1120                         console.log('leaflet-marker lat=' + lat + ' lng=' + lng);
    1121                     }
    1122                 });
    1123             }
    1124 
    1125             marker.addTo( markergroup );
    1126             ";
    1127            
    1128             $marker_script .= self::add_popup_to_shape($atts, $content, 'marker');
    1129 
    1130             $marker_script .= "
    1131                     WPLeafletMapPlugin.markers.push( marker );
     1123            ?>
     1124                if (draggable) {
     1125                    marker.on('dragend', function () {
     1126                        var latlng = this.getLatLng(),
     1127                            lat = latlng.lat,
     1128                            lng = latlng.lng;
     1129                        if (is_image) {
     1130                            console.log('leaflet-marker y=' + lat + ' x=' + lng);
     1131                        } else {
     1132                            console.log('leaflet-marker lat=' + lat + ' lng=' + lng);
     1133                        }
     1134                    });
     1135                }
     1136
     1137                marker.addTo( markergroup );
     1138            <?php
     1139                self::add_popup_to_shape($atts, $content, 'marker');
     1140            ?>
     1141                WPLeafletMapPlugin.markers.push( marker );
    11321142            }); // end add function
    1133             </script>";
    1134 
    1135             return $marker_script;
     1143            </script>
     1144            <?php
     1145
     1146            return ob_get_clean();
    11361147        }
    11371148
     
    11841195
    11851196            $location_json = json_encode($locations);
    1186 
    1187             $line_script = "<script>
     1197            ob_start();
     1198            ?>
     1199            <script>
    11881200            WPLeafletMapPlugin.add(function () {
    11891201                var previous_map = WPLeafletMapPlugin.getCurrentMap(),
    1190                     line = L.polyline($location_json, {$style_json}),
    1191                     fitbounds = $fitbounds;
     1202                    line = L.polyline(<?php echo $location_json; ?>, <?php echo $style_json; ?>),
     1203                    fitbounds = <?php echo $fitbounds; ?>;
    11921204                line.addTo( previous_map );
    11931205                if (fitbounds) {
    11941206                    // zoom the map to the polyline
    11951207                    previous_map.fitBounds( line.getBounds() );
    1196                 }";
    1197 
    1198             $line_script .= self::add_popup_to_shape($atts, $content, 'line');
    1199 
    1200             $line_script .= "
     1208                }
     1209            <?php
     1210                self::add_popup_to_shape($atts, $content, 'line');
     1211            ?>
    12011212                WPLeafletMapPlugin.lines.push( line );
    12021213            });
    1203             </script>";
    1204 
    1205             return $line_script;
     1214            </script>
     1215            <?php
     1216
     1217            return ob_get_clean();
    12061218        }
    12071219    } // end class
  • leaflet-map/tags/2.8.1/readme.txt

    r1708977 r1709145  
    88Requires at least: 3.0.1
    99Tested up to: 4.8
    10 Version: 2.8.0
    11 Stable tag: 2.8.0
     10Version: 2.8.1
     11Stable tag: 2.8.1
    1212License: GPLv2
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    121121== Changelog ==
    122122
     123= 2.8.1 =
     124* Code cleanup
     125* Added server-side and client-side methods to prevent WordPress from adding paragraph tags within shortcode tags
     126
    123127= 2.8.0 =
    124128* Added Fit Markers to settings and map shortcode: [leaflet-map fit_markers=1]
  • leaflet-map/tags/2.8.1/scripts/construct-leaflet-map.js

    r1708977 r1709145  
    1 (function () {
     1(function() {
    22    // holds a function queue to call once page is loaded
    3     function Main () {
     3    function Main() {
    44        var init_functions = [];
    55
     
    2525            // marker groups are mapid -> feature group
    2626            var mapid = this.maps.length;
    27             if (!this.markergroups[ mapid ]) {
    28                 this.markergroups[ mapid ] = this.newMarkerGroup(this.maps[mapid - 1]);
    29             } 
    30             return this.markergroups[ mapid ];
     27            if (!this.markergroups[mapid]) {
     28                this.markergroups[mapid] = this.newMarkerGroup(this.maps[mapid - 1]);
     29            }
     30            return this.markergroups[mapid];
    3131        };
    3232
    33         this.newMarkerGroup = function (map) {
    34             var mg = new L.FeatureGroup().addTo( map );
     33        this.newMarkerGroup = function(map) {
     34            var mg = new L.FeatureGroup().addTo(map);
    3535
    3636            mg.timeout = null;
     
    3838            // custom attribute
    3939            if (map.fit_markers) {
    40                 mg.on('layeradd', function (d) {
     40                mg.on('layeradd', function(d) {
    4141                    // needs a timeout so that it doesn't
    4242                    // opt out of a bound change
    4343                    window.clearTimeout(this.timeout);
    44                     this.timeout = window.setTimeout(function () {
    45                         map.fitBounds( mg.getBounds() );
     44                    this.timeout = window.setTimeout(function() {
     45                        map.fitBounds(mg.getBounds());
    4646                    }, 100);
    4747                }, mg);
     
    5959    }
    6060
     61    Main.prototype.unescape = function(str) {
     62        var div = document.createElement('div');
     63        div.innerHTML = str;
     64        return div.innerText;
     65    };
     66
    6167    window.WPLeafletMapPlugin = new Main();
    6268
  • leaflet-map/trunk/leaflet-map.php

    r1708977 r1709145  
    66    Author: bozdoz
    77    Author URI: https://twitter.com/bozdoz/
    8     Version: 2.8.0
     8    Version: 2.8.1
    99    License: GPL2
    1010
     
    636636
    637637            /* should be iterated for multiple maps */
    638             $content = '<div id="leaflet-wordpress-map-'.$leaflet_map_count.'" class="leaflet-wordpress-map" style="height:'.$height.'; width:'.$width.';"></div>';
    639 
    640             $content .= "<script>
     638            ob_start(); ?>
     639            <div
     640                id="leaflet-wordpress-map-<?php echo $leaflet_map_count; ?>"
     641                class="leaflet-wordpress-map"
     642                style="height:<?php echo $height; ?>; width:<?php echo $width; ?>;"></div>
     643            <script>
    641644            WPLeafletMapPlugin.add(function () {
    642                 var baseUrl = '{$tileurl}',
     645                var baseUrl = '<?php echo $tileurl; ?>',
    643646                    base = (!baseUrl && window.MQ) ? MQ.mapLayer() : L.tileLayer(baseUrl, {
    644                        subdomains: '{$subdomains}'
     647                       subdomains: '<?php echo $subdomains; ?>'
    645648                    }),
    646649                    options = L.Util.extend({}, {
    647                         maxZoom: {$max_zoom},
    648                         minZoom: {$min_zoom},
     650                        maxZoom: <?php echo $max_zoom; ?>,
     651                        minZoom: <?php echo $min_zoom; ?>,
    649652                        layers: [base],
    650                         zoomControl: {$zoomcontrol},
    651                         scrollWheelZoom: {$scrollwheel},
    652                         doubleClickZoom: {$doubleclickzoom},
     653                        zoomControl: <?php echo $zoomcontrol; ?>,
     654                        scrollWheelZoom: <?php echo $scrollwheel; ?>,
     655                        doubleClickZoom: <?php echo $doubleclickzoom; ?>,
    653656                        attributionControl: false
    654                     }, {$more_options}),
    655                     map = L.map('leaflet-wordpress-map-{$leaflet_map_count}', options).setView([{$lat}, {$lng}], {$zoom});
    656                 if ({$fit_markers}) {
     657                    }, <?php echo $more_options; ?>),
     658                    map = L.map('leaflet-wordpress-map-<?php echo $leaflet_map_count; ?>', options).setView([<?php echo $lat . ',' . $lng . '],' . $zoom; ?>);
     659                if (<?php echo $fit_markers; ?>) {
    657660                    map.fit_markers = true;
    658661                }
    659                 ";
    660                
     662            <?php
    661663                if ($attribution) {
    662664                    /* add any attributions, semi-colon-separated */
    663665                    $attributions = explode(';', $attribution);
    664666
    665                     $content .= "var attControl = L.control.attribution({prefix:false}).addTo(map);";
     667                    ?>
     668                    var attControl = L.control.attribution({prefix:false}).addTo(map);
     669                    <?php
    666670
    667671                    foreach ($attributions as $a) {
    668                         $a = trim($a);
    669                         $content .= "attControl.addAttribution('{$a}');";
     672                        ?>
     673                        attControl.addAttribution('<?php echo trim($a); ?>');
     674                        <?php
    670675                    }
    671676                }
    672 
    673                 $content .= "
    674                 WPLeafletMapPlugin.maps.push(map);
     677            ?>
     678            WPLeafletMapPlugin.maps.push(map);
    675679            }); // end add
    676             </script>";
    677 
    678             return $content;
     680            </script> <?php
     681
     682            return ob_get_clean();
    679683        }
    680684
     
    728732            $width .= is_numeric($width) ? 'px' : '';   
    729733           
    730             $content = '<div id="leaflet-wordpress-image-'.$leaflet_map_count.'" class="leaflet-wordpress-map" style="height:'.$height.'; width:'.$width.';"></div>';
    731 
    732             $content .= "<script>
     734            ob_start();
     735            ?>
     736            <div
     737                id="leaflet-wordpress-image-<?php echo leaflet_map_count; ?>"
     738                class="leaflet-wordpress-map"
     739                style="height:<?php echo height; ?>; width:<?php echo width; ?>;"></div>
     740            <script>
    733741            WPLeafletMapPlugin.add(function () {
    734742                var map,
    735                     image_src = '$source',
     743                    image_src = '<?php echo $source; ?>',
    736744                    img = new Image(),
    737                     zoom = $zoom;
    738 
     745                    zoom = <?php echo $zoom; ?>;
    739746                img.onload = function() {
    740747                    var center_h = img.height / (zoom * 4),
     
    748755                };
    749756                img.src = image_src;
    750 
    751                 map = L.map('leaflet-wordpress-image-{$leaflet_map_count}', {
     757                map = L.map('leaflet-wordpress-image-<?php echo $leaflet_map_count; ?>', {
    752758                    maxZoom: 10,
    753759                    minZoom: 1,
    754760                    crs: L.CRS.Simple,
    755                     zoomControl: {$zoomcontrol},
    756                     scrollWheelZoom: {$scrollwheel}
     761                    zoomControl: <?php echo $zoomcontrol ?>,
     762                    scrollWheelZoom: <?php echo $scrollwheel ?>
    757763                }).setView([0, 0], zoom);
    758764
     
    763769                WPLeafletMapPlugin.images.push( img );
    764770            }); // end add
    765             </script>";
    766 
    767             return $content;
     771            </script>
     772            <?php
     773            return ob_get_clean();
    768774        }
    769775
     
    862868            }
    863869
     870            if ($content) {
     871                $content = htmlspecialchars($content);
     872            }
     873
    864874            /* only required field for geojson */
    865875            $src = empty($src) ? $default : $src;
     
    878888            $popup_property = empty($popup_property) ? '' : $popup_property;
    879889
    880             $geojson_script = "<script>
     890            $popup_text = trim($popup_text);
     891
     892            ob_start();
     893            ?>
     894            <script>
    881895                WPLeafletMapPlugin.add(function () {
    882896                    var previous_map = WPLeafletMapPlugin.getCurrentMap(),
    883                         src = '{$src}',
    884                         default_style = {$style_json},
     897                        src = '<?php echo $src; ?>',
     898                        default_style = <?php echo $style_json; ?>,
    885899                        rewrite_keys = {
    886900                            fill : 'fillColor',
     
    890904                            'stroke-width' : 'width',
    891905                        },
    892                         layer = L.{$L_method}(src, {
     906                        layer = L.<?php echo $L_method; ?>(src, {
    893907                            style : layerStyle,
    894908                            onEachFeature : onEachFeature
    895909                        }),
    896                         fitbounds = {$fitbounds},
    897                         popup_text = '{$popup_text}',
    898                         popup_property = '{$popup_property}';
     910                        fitbounds = <?php echo $fitbounds; ?>,
     911                        popup_text = WPLeafletMapPlugin.unescape('<?php echo $popup_text; ?>'),
     912                        popup_property = '<?php echo $popup_property; ?>';
    899913                    if (fitbounds) {
    900914                        layer.on('ready', function () {
     
    929943                    }         
    930944                });
    931                 </script>";
    932 
    933             return $geojson_script;
     945            </script>
     946            <?php
     947
     948            return ob_get_clean();
    934949        }
    935950
     
    958973
    959974        public function kml_shortcode ( $atts, $content = null ) {
    960            
    961975            return self::get_shape( $atts, $content, 'leaflet_ajax_kml_js', 'ajaxKML', 'https://cdn.rawgit.com/mapbox/togeojson/master/test/data/polygon.kml');
    962            
    963976        }
    964977
     
    970983        * @param string $content    text to display
    971984        * @param string $shape      JavaScript variable for shape
    972         * @return string JavaScript
     985        * @return null
    973986        */
    974987
     
    977990
    978991            $message = empty($message) ? (empty($content) ? '' : $content) : $message;
     992            $message = htmlspecialchars($message);
    979993            $visible = empty($visible) ? false : ($visible == 'true');
    980994
    981             $output = '';
    982 
    983995            if (!empty($message)) {
     996                /*
    984997                $message = str_replace("\n", '', $message);
    985 
    986                 $output .= "$shape.bindPopup('$message')";
     998                */
     999
     1000                echo "{$shape}.bindPopup(WPLeafletMapPlugin.unescape('{$message}'))";
    9871001
    9881002                if ($visible) {
    989                     $output .= ".openPopup()";
     1003                    echo ".openPopup()";
    9901004                }
    9911005
    992                 $output .= ";";
    993             }
    994 
    995             return $output;
     1006                echo ";";
     1007            }
    9961008        }
    9971009
     
    10641076                $options = '{}';
    10651077            }
    1066 
    1067             $marker_script = "<script>
     1078            ob_start();
     1079            ?>
     1080            <script>
    10681081            WPLeafletMapPlugin.add(function () {
    10691082                var marker_options = (function () {
    1070                         var _options = {$options},
    1071                             iconArrays = ['iconSize', 'iconAnchor', 'shadowSize', 'shadowAnchor'];
     1083                        var _options = <?php echo $options; ?>,
     1084                            iconArrays = ['iconSize', 'iconAnchor',
     1085                                'shadowSize', 'shadowAnchor'];
    10721086                        if (_options.iconUrl) {
    10731087                            // arrays are strings, unfortunately...
     
    10841098                    })(),
    10851099                    draggable = marker_options.draggable,
    1086                     marker = L.marker([{$lat}, {$lng}], marker_options),
     1100                    marker = L.marker([<?php echo $lat . ',' . $lng; ?>], marker_options),
    10871101                    previous_map = WPLeafletMapPlugin.getCurrentMap(),
    10881102                    is_image = previous_map.is_image_map,
    10891103                    previous_map_onload,
    10901104                    markergroup = WPLeafletMapPlugin.getCurrentMarkerGroup();
    1091                 ";
    1092 
     1105            <?php
    10931106                if (empty($lat) && empty($lng)) {
    10941107                    /* update lat lng to previous map's center */
    1095                     $marker_script .= "
    1096                     if ( is_image &&
     1108            ?>
     1109                    if (is_image &&
    10971110                        !previous_map.is_loaded) {
    10981111                        previous_map_onload = previous_map.onload;
     
    11061119                        marker.setLatLng( previous_map.getCenter() );
    11071120                    }
    1108                     ";
     1121            <?php
    11091122                }
    1110 
    1111             $marker_script .= "
    1112             if (draggable) {
    1113                 marker.on('dragend', function () {
    1114                     var latlng = this.getLatLng(),
    1115                         lat = latlng.lat,
    1116                         lng = latlng.lng;
    1117                     if (is_image) {
    1118                         console.log('leaflet-marker y=' + lat + ' x=' + lng);
    1119                     } else {
    1120                         console.log('leaflet-marker lat=' + lat + ' lng=' + lng);
    1121                     }
    1122                 });
    1123             }
    1124 
    1125             marker.addTo( markergroup );
    1126             ";
    1127            
    1128             $marker_script .= self::add_popup_to_shape($atts, $content, 'marker');
    1129 
    1130             $marker_script .= "
    1131                     WPLeafletMapPlugin.markers.push( marker );
     1123            ?>
     1124                if (draggable) {
     1125                    marker.on('dragend', function () {
     1126                        var latlng = this.getLatLng(),
     1127                            lat = latlng.lat,
     1128                            lng = latlng.lng;
     1129                        if (is_image) {
     1130                            console.log('leaflet-marker y=' + lat + ' x=' + lng);
     1131                        } else {
     1132                            console.log('leaflet-marker lat=' + lat + ' lng=' + lng);
     1133                        }
     1134                    });
     1135                }
     1136
     1137                marker.addTo( markergroup );
     1138            <?php
     1139                self::add_popup_to_shape($atts, $content, 'marker');
     1140            ?>
     1141                WPLeafletMapPlugin.markers.push( marker );
    11321142            }); // end add function
    1133             </script>";
    1134 
    1135             return $marker_script;
     1143            </script>
     1144            <?php
     1145
     1146            return ob_get_clean();
    11361147        }
    11371148
     
    11841195
    11851196            $location_json = json_encode($locations);
    1186 
    1187             $line_script = "<script>
     1197            ob_start();
     1198            ?>
     1199            <script>
    11881200            WPLeafletMapPlugin.add(function () {
    11891201                var previous_map = WPLeafletMapPlugin.getCurrentMap(),
    1190                     line = L.polyline($location_json, {$style_json}),
    1191                     fitbounds = $fitbounds;
     1202                    line = L.polyline(<?php echo $location_json; ?>, <?php echo $style_json; ?>),
     1203                    fitbounds = <?php echo $fitbounds; ?>;
    11921204                line.addTo( previous_map );
    11931205                if (fitbounds) {
    11941206                    // zoom the map to the polyline
    11951207                    previous_map.fitBounds( line.getBounds() );
    1196                 }";
    1197 
    1198             $line_script .= self::add_popup_to_shape($atts, $content, 'line');
    1199 
    1200             $line_script .= "
     1208                }
     1209            <?php
     1210                self::add_popup_to_shape($atts, $content, 'line');
     1211            ?>
    12011212                WPLeafletMapPlugin.lines.push( line );
    12021213            });
    1203             </script>";
    1204 
    1205             return $line_script;
     1214            </script>
     1215            <?php
     1216
     1217            return ob_get_clean();
    12061218        }
    12071219    } // end class
  • leaflet-map/trunk/readme.txt

    r1708977 r1709145  
    88Requires at least: 3.0.1
    99Tested up to: 4.8
    10 Version: 2.8.0
    11 Stable tag: 2.8.0
     10Version: 2.8.1
     11Stable tag: 2.8.1
    1212License: GPLv2
    1313License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    121121== Changelog ==
    122122
     123= 2.8.1 =
     124* Code cleanup
     125* Added server-side and client-side methods to prevent WordPress from adding paragraph tags within shortcode tags
     126
    123127= 2.8.0 =
    124128* Added Fit Markers to settings and map shortcode: [leaflet-map fit_markers=1]
  • leaflet-map/trunk/scripts/construct-leaflet-map.js

    r1708977 r1709145  
    1 (function () {
     1(function() {
    22    // holds a function queue to call once page is loaded
    3     function Main () {
     3    function Main() {
    44        var init_functions = [];
    55
     
    2525            // marker groups are mapid -> feature group
    2626            var mapid = this.maps.length;
    27             if (!this.markergroups[ mapid ]) {
    28                 this.markergroups[ mapid ] = this.newMarkerGroup(this.maps[mapid - 1]);
    29             } 
    30             return this.markergroups[ mapid ];
     27            if (!this.markergroups[mapid]) {
     28                this.markergroups[mapid] = this.newMarkerGroup(this.maps[mapid - 1]);
     29            }
     30            return this.markergroups[mapid];
    3131        };
    3232
    33         this.newMarkerGroup = function (map) {
    34             var mg = new L.FeatureGroup().addTo( map );
     33        this.newMarkerGroup = function(map) {
     34            var mg = new L.FeatureGroup().addTo(map);
    3535
    3636            mg.timeout = null;
     
    3838            // custom attribute
    3939            if (map.fit_markers) {
    40                 mg.on('layeradd', function (d) {
     40                mg.on('layeradd', function(d) {
    4141                    // needs a timeout so that it doesn't
    4242                    // opt out of a bound change
    4343                    window.clearTimeout(this.timeout);
    44                     this.timeout = window.setTimeout(function () {
    45                         map.fitBounds( mg.getBounds() );
     44                    this.timeout = window.setTimeout(function() {
     45                        map.fitBounds(mg.getBounds());
    4646                    }, 100);
    4747                }, mg);
     
    5959    }
    6060
     61    Main.prototype.unescape = function(str) {
     62        var div = document.createElement('div');
     63        div.innerHTML = str;
     64        return div.innerText;
     65    };
     66
    6167    window.WPLeafletMapPlugin = new Main();
    6268
Note: See TracChangeset for help on using the changeset viewer.