Changeset 1709145 for leaflet-map
- Timestamp:
- 08/06/2017 03:31:13 PM (9 years ago)
- Location:
- leaflet-map
- Files:
-
- 1 deleted
- 3 edited
- 13 copied
-
tags/2.8.1 (copied) (copied from leaflet-map/trunk)
-
tags/2.8.1/CODE_OF_CONDUCT.md (copied) (copied from leaflet-map/trunk/CODE_OF_CONDUCT.md)
-
tags/2.8.1/CONTRIBUTING.md (copied) (copied from leaflet-map/trunk/CONTRIBUTING.md)
-
tags/2.8.1/LICENSE (copied) (copied from leaflet-map/trunk/LICENSE)
-
tags/2.8.1/README.md (copied) (copied from leaflet-map/trunk/README.md)
-
tags/2.8.1/admin (copied) (copied from leaflet-map/trunk/admin)
-
tags/2.8.1/leaflet-map.php (copied) (copied from leaflet-map/trunk/leaflet-map.php) (16 diffs)
-
tags/2.8.1/readme.txt (copied) (copied from leaflet-map/trunk/readme.txt) (2 diffs)
-
tags/2.8.1/scripts/construct-leaflet-map.js (copied) (copied from leaflet-map/trunk/scripts/construct-leaflet-map.js) (4 diffs)
-
tags/2.8.1/scripts/get-shortcode.js (copied) (copied from leaflet-map/trunk/scripts/get-shortcode.js)
-
tags/2.8.1/scripts/leaflet-ajax-geojson.js (copied) (copied from leaflet-map/trunk/scripts/leaflet-ajax-geojson.js)
-
tags/2.8.1/scripts/leaflet-ajax-kml.js (copied) (copied from leaflet-map/trunk/scripts/leaflet-ajax-kml.js)
-
tags/2.8.1/templates/find-on-map.php (deleted)
-
tags/2.8.1/templates/shortcode-helper.php (copied) (copied from leaflet-map/trunk/templates/shortcode-helper.php)
-
trunk/leaflet-map.php (modified) (16 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/scripts/construct-leaflet-map.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
leaflet-map/tags/2.8.1/leaflet-map.php
r1708977 r1709145 6 6 Author: bozdoz 7 7 Author URI: https://twitter.com/bozdoz/ 8 Version: 2.8. 08 Version: 2.8.1 9 9 License: GPL2 10 10 … … 636 636 637 637 /* 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> 641 644 WPLeafletMapPlugin.add(function () { 642 var baseUrl = ' {$tileurl}',645 var baseUrl = '<?php echo $tileurl; ?>', 643 646 base = (!baseUrl && window.MQ) ? MQ.mapLayer() : L.tileLayer(baseUrl, { 644 subdomains: ' {$subdomains}'647 subdomains: '<?php echo $subdomains; ?>' 645 648 }), 646 649 options = L.Util.extend({}, { 647 maxZoom: {$max_zoom},648 minZoom: {$min_zoom},650 maxZoom: <?php echo $max_zoom; ?>, 651 minZoom: <?php echo $min_zoom; ?>, 649 652 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; ?>, 653 656 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; ?>) { 657 660 map.fit_markers = true; 658 661 } 659 "; 660 662 <?php 661 663 if ($attribution) { 662 664 /* add any attributions, semi-colon-separated */ 663 665 $attributions = explode(';', $attribution); 664 666 665 $content .= "var attControl = L.control.attribution({prefix:false}).addTo(map);"; 667 ?> 668 var attControl = L.control.attribution({prefix:false}).addTo(map); 669 <?php 666 670 667 671 foreach ($attributions as $a) { 668 $a = trim($a); 669 $content .= "attControl.addAttribution('{$a}');"; 672 ?> 673 attControl.addAttribution('<?php echo trim($a); ?>'); 674 <?php 670 675 } 671 676 } 672 673 $content .= " 674 WPLeafletMapPlugin.maps.push(map); 677 ?> 678 WPLeafletMapPlugin.maps.push(map); 675 679 }); // end add 676 </script> ";677 678 return $content;680 </script> <?php 681 682 return ob_get_clean(); 679 683 } 680 684 … … 728 732 $width .= is_numeric($width) ? 'px' : ''; 729 733 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> 733 741 WPLeafletMapPlugin.add(function () { 734 742 var map, 735 image_src = ' $source',743 image_src = '<?php echo $source; ?>', 736 744 img = new Image(), 737 zoom = $zoom; 738 745 zoom = <?php echo $zoom; ?>; 739 746 img.onload = function() { 740 747 var center_h = img.height / (zoom * 4), … … 748 755 }; 749 756 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; ?>', { 752 758 maxZoom: 10, 753 759 minZoom: 1, 754 760 crs: L.CRS.Simple, 755 zoomControl: {$zoomcontrol},756 scrollWheelZoom: {$scrollwheel}761 zoomControl: <?php echo $zoomcontrol ?>, 762 scrollWheelZoom: <?php echo $scrollwheel ?> 757 763 }).setView([0, 0], zoom); 758 764 … … 763 769 WPLeafletMapPlugin.images.push( img ); 764 770 }); // end add 765 </script> ";766 767 return $content;771 </script> 772 <?php 773 return ob_get_clean(); 768 774 } 769 775 … … 862 868 } 863 869 870 if ($content) { 871 $content = htmlspecialchars($content); 872 } 873 864 874 /* only required field for geojson */ 865 875 $src = empty($src) ? $default : $src; … … 878 888 $popup_property = empty($popup_property) ? '' : $popup_property; 879 889 880 $geojson_script = "<script> 890 $popup_text = trim($popup_text); 891 892 ob_start(); 893 ?> 894 <script> 881 895 WPLeafletMapPlugin.add(function () { 882 896 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; ?>, 885 899 rewrite_keys = { 886 900 fill : 'fillColor', … … 890 904 'stroke-width' : 'width', 891 905 }, 892 layer = L. {$L_method}(src, {906 layer = L.<?php echo $L_method; ?>(src, { 893 907 style : layerStyle, 894 908 onEachFeature : onEachFeature 895 909 }), 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; ?>'; 899 913 if (fitbounds) { 900 914 layer.on('ready', function () { … … 929 943 } 930 944 }); 931 </script>"; 932 933 return $geojson_script; 945 </script> 946 <?php 947 948 return ob_get_clean(); 934 949 } 935 950 … … 958 973 959 974 public function kml_shortcode ( $atts, $content = null ) { 960 961 975 return self::get_shape( $atts, $content, 'leaflet_ajax_kml_js', 'ajaxKML', 'https://cdn.rawgit.com/mapbox/togeojson/master/test/data/polygon.kml'); 962 963 976 } 964 977 … … 970 983 * @param string $content text to display 971 984 * @param string $shape JavaScript variable for shape 972 * @return string JavaScript985 * @return null 973 986 */ 974 987 … … 977 990 978 991 $message = empty($message) ? (empty($content) ? '' : $content) : $message; 992 $message = htmlspecialchars($message); 979 993 $visible = empty($visible) ? false : ($visible == 'true'); 980 994 981 $output = '';982 983 995 if (!empty($message)) { 996 /* 984 997 $message = str_replace("\n", '', $message); 985 986 $output .= "$shape.bindPopup('$message')"; 998 */ 999 1000 echo "{$shape}.bindPopup(WPLeafletMapPlugin.unescape('{$message}'))"; 987 1001 988 1002 if ($visible) { 989 $output .=".openPopup()";1003 echo ".openPopup()"; 990 1004 } 991 1005 992 $output .= ";"; 993 } 994 995 return $output; 1006 echo ";"; 1007 } 996 1008 } 997 1009 … … 1064 1076 $options = '{}'; 1065 1077 } 1066 1067 $marker_script = "<script> 1078 ob_start(); 1079 ?> 1080 <script> 1068 1081 WPLeafletMapPlugin.add(function () { 1069 1082 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']; 1072 1086 if (_options.iconUrl) { 1073 1087 // arrays are strings, unfortunately... … … 1084 1098 })(), 1085 1099 draggable = marker_options.draggable, 1086 marker = L.marker([ {$lat}, {$lng}], marker_options),1100 marker = L.marker([<?php echo $lat . ',' . $lng; ?>], marker_options), 1087 1101 previous_map = WPLeafletMapPlugin.getCurrentMap(), 1088 1102 is_image = previous_map.is_image_map, 1089 1103 previous_map_onload, 1090 1104 markergroup = WPLeafletMapPlugin.getCurrentMarkerGroup(); 1091 "; 1092 1105 <?php 1093 1106 if (empty($lat) && empty($lng)) { 1094 1107 /* update lat lng to previous map's center */ 1095 $marker_script .= "1096 if ( is_image &&1108 ?> 1109 if (is_image && 1097 1110 !previous_map.is_loaded) { 1098 1111 previous_map_onload = previous_map.onload; … … 1106 1119 marker.setLatLng( previous_map.getCenter() ); 1107 1120 } 1108 ";1121 <?php 1109 1122 } 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 ); 1132 1142 }); // end add function 1133 </script>"; 1134 1135 return $marker_script; 1143 </script> 1144 <?php 1145 1146 return ob_get_clean(); 1136 1147 } 1137 1148 … … 1184 1195 1185 1196 $location_json = json_encode($locations); 1186 1187 $line_script = "<script> 1197 ob_start(); 1198 ?> 1199 <script> 1188 1200 WPLeafletMapPlugin.add(function () { 1189 1201 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; ?>; 1192 1204 line.addTo( previous_map ); 1193 1205 if (fitbounds) { 1194 1206 // zoom the map to the polyline 1195 1207 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 ?> 1201 1212 WPLeafletMapPlugin.lines.push( line ); 1202 1213 }); 1203 </script>"; 1204 1205 return $line_script; 1214 </script> 1215 <?php 1216 1217 return ob_get_clean(); 1206 1218 } 1207 1219 } // end class -
leaflet-map/tags/2.8.1/readme.txt
r1708977 r1709145 8 8 Requires at least: 3.0.1 9 9 Tested up to: 4.8 10 Version: 2.8. 011 Stable tag: 2.8. 010 Version: 2.8.1 11 Stable tag: 2.8.1 12 12 License: GPLv2 13 13 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 121 121 == Changelog == 122 122 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 123 127 = 2.8.0 = 124 128 * 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() { 2 2 // holds a function queue to call once page is loaded 3 function Main () {3 function Main() { 4 4 var init_functions = []; 5 5 … … 25 25 // marker groups are mapid -> feature group 26 26 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]; 31 31 }; 32 32 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); 35 35 36 36 mg.timeout = null; … … 38 38 // custom attribute 39 39 if (map.fit_markers) { 40 mg.on('layeradd', function (d) {40 mg.on('layeradd', function(d) { 41 41 // needs a timeout so that it doesn't 42 42 // opt out of a bound change 43 43 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()); 46 46 }, 100); 47 47 }, mg); … … 59 59 } 60 60 61 Main.prototype.unescape = function(str) { 62 var div = document.createElement('div'); 63 div.innerHTML = str; 64 return div.innerText; 65 }; 66 61 67 window.WPLeafletMapPlugin = new Main(); 62 68 -
leaflet-map/trunk/leaflet-map.php
r1708977 r1709145 6 6 Author: bozdoz 7 7 Author URI: https://twitter.com/bozdoz/ 8 Version: 2.8. 08 Version: 2.8.1 9 9 License: GPL2 10 10 … … 636 636 637 637 /* 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> 641 644 WPLeafletMapPlugin.add(function () { 642 var baseUrl = ' {$tileurl}',645 var baseUrl = '<?php echo $tileurl; ?>', 643 646 base = (!baseUrl && window.MQ) ? MQ.mapLayer() : L.tileLayer(baseUrl, { 644 subdomains: ' {$subdomains}'647 subdomains: '<?php echo $subdomains; ?>' 645 648 }), 646 649 options = L.Util.extend({}, { 647 maxZoom: {$max_zoom},648 minZoom: {$min_zoom},650 maxZoom: <?php echo $max_zoom; ?>, 651 minZoom: <?php echo $min_zoom; ?>, 649 652 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; ?>, 653 656 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; ?>) { 657 660 map.fit_markers = true; 658 661 } 659 "; 660 662 <?php 661 663 if ($attribution) { 662 664 /* add any attributions, semi-colon-separated */ 663 665 $attributions = explode(';', $attribution); 664 666 665 $content .= "var attControl = L.control.attribution({prefix:false}).addTo(map);"; 667 ?> 668 var attControl = L.control.attribution({prefix:false}).addTo(map); 669 <?php 666 670 667 671 foreach ($attributions as $a) { 668 $a = trim($a); 669 $content .= "attControl.addAttribution('{$a}');"; 672 ?> 673 attControl.addAttribution('<?php echo trim($a); ?>'); 674 <?php 670 675 } 671 676 } 672 673 $content .= " 674 WPLeafletMapPlugin.maps.push(map); 677 ?> 678 WPLeafletMapPlugin.maps.push(map); 675 679 }); // end add 676 </script> ";677 678 return $content;680 </script> <?php 681 682 return ob_get_clean(); 679 683 } 680 684 … … 728 732 $width .= is_numeric($width) ? 'px' : ''; 729 733 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> 733 741 WPLeafletMapPlugin.add(function () { 734 742 var map, 735 image_src = ' $source',743 image_src = '<?php echo $source; ?>', 736 744 img = new Image(), 737 zoom = $zoom; 738 745 zoom = <?php echo $zoom; ?>; 739 746 img.onload = function() { 740 747 var center_h = img.height / (zoom * 4), … … 748 755 }; 749 756 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; ?>', { 752 758 maxZoom: 10, 753 759 minZoom: 1, 754 760 crs: L.CRS.Simple, 755 zoomControl: {$zoomcontrol},756 scrollWheelZoom: {$scrollwheel}761 zoomControl: <?php echo $zoomcontrol ?>, 762 scrollWheelZoom: <?php echo $scrollwheel ?> 757 763 }).setView([0, 0], zoom); 758 764 … … 763 769 WPLeafletMapPlugin.images.push( img ); 764 770 }); // end add 765 </script> ";766 767 return $content;771 </script> 772 <?php 773 return ob_get_clean(); 768 774 } 769 775 … … 862 868 } 863 869 870 if ($content) { 871 $content = htmlspecialchars($content); 872 } 873 864 874 /* only required field for geojson */ 865 875 $src = empty($src) ? $default : $src; … … 878 888 $popup_property = empty($popup_property) ? '' : $popup_property; 879 889 880 $geojson_script = "<script> 890 $popup_text = trim($popup_text); 891 892 ob_start(); 893 ?> 894 <script> 881 895 WPLeafletMapPlugin.add(function () { 882 896 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; ?>, 885 899 rewrite_keys = { 886 900 fill : 'fillColor', … … 890 904 'stroke-width' : 'width', 891 905 }, 892 layer = L. {$L_method}(src, {906 layer = L.<?php echo $L_method; ?>(src, { 893 907 style : layerStyle, 894 908 onEachFeature : onEachFeature 895 909 }), 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; ?>'; 899 913 if (fitbounds) { 900 914 layer.on('ready', function () { … … 929 943 } 930 944 }); 931 </script>"; 932 933 return $geojson_script; 945 </script> 946 <?php 947 948 return ob_get_clean(); 934 949 } 935 950 … … 958 973 959 974 public function kml_shortcode ( $atts, $content = null ) { 960 961 975 return self::get_shape( $atts, $content, 'leaflet_ajax_kml_js', 'ajaxKML', 'https://cdn.rawgit.com/mapbox/togeojson/master/test/data/polygon.kml'); 962 963 976 } 964 977 … … 970 983 * @param string $content text to display 971 984 * @param string $shape JavaScript variable for shape 972 * @return string JavaScript985 * @return null 973 986 */ 974 987 … … 977 990 978 991 $message = empty($message) ? (empty($content) ? '' : $content) : $message; 992 $message = htmlspecialchars($message); 979 993 $visible = empty($visible) ? false : ($visible == 'true'); 980 994 981 $output = '';982 983 995 if (!empty($message)) { 996 /* 984 997 $message = str_replace("\n", '', $message); 985 986 $output .= "$shape.bindPopup('$message')"; 998 */ 999 1000 echo "{$shape}.bindPopup(WPLeafletMapPlugin.unescape('{$message}'))"; 987 1001 988 1002 if ($visible) { 989 $output .=".openPopup()";1003 echo ".openPopup()"; 990 1004 } 991 1005 992 $output .= ";"; 993 } 994 995 return $output; 1006 echo ";"; 1007 } 996 1008 } 997 1009 … … 1064 1076 $options = '{}'; 1065 1077 } 1066 1067 $marker_script = "<script> 1078 ob_start(); 1079 ?> 1080 <script> 1068 1081 WPLeafletMapPlugin.add(function () { 1069 1082 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']; 1072 1086 if (_options.iconUrl) { 1073 1087 // arrays are strings, unfortunately... … … 1084 1098 })(), 1085 1099 draggable = marker_options.draggable, 1086 marker = L.marker([ {$lat}, {$lng}], marker_options),1100 marker = L.marker([<?php echo $lat . ',' . $lng; ?>], marker_options), 1087 1101 previous_map = WPLeafletMapPlugin.getCurrentMap(), 1088 1102 is_image = previous_map.is_image_map, 1089 1103 previous_map_onload, 1090 1104 markergroup = WPLeafletMapPlugin.getCurrentMarkerGroup(); 1091 "; 1092 1105 <?php 1093 1106 if (empty($lat) && empty($lng)) { 1094 1107 /* update lat lng to previous map's center */ 1095 $marker_script .= "1096 if ( is_image &&1108 ?> 1109 if (is_image && 1097 1110 !previous_map.is_loaded) { 1098 1111 previous_map_onload = previous_map.onload; … … 1106 1119 marker.setLatLng( previous_map.getCenter() ); 1107 1120 } 1108 ";1121 <?php 1109 1122 } 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 ); 1132 1142 }); // end add function 1133 </script>"; 1134 1135 return $marker_script; 1143 </script> 1144 <?php 1145 1146 return ob_get_clean(); 1136 1147 } 1137 1148 … … 1184 1195 1185 1196 $location_json = json_encode($locations); 1186 1187 $line_script = "<script> 1197 ob_start(); 1198 ?> 1199 <script> 1188 1200 WPLeafletMapPlugin.add(function () { 1189 1201 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; ?>; 1192 1204 line.addTo( previous_map ); 1193 1205 if (fitbounds) { 1194 1206 // zoom the map to the polyline 1195 1207 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 ?> 1201 1212 WPLeafletMapPlugin.lines.push( line ); 1202 1213 }); 1203 </script>"; 1204 1205 return $line_script; 1214 </script> 1215 <?php 1216 1217 return ob_get_clean(); 1206 1218 } 1207 1219 } // end class -
leaflet-map/trunk/readme.txt
r1708977 r1709145 8 8 Requires at least: 3.0.1 9 9 Tested up to: 4.8 10 Version: 2.8. 011 Stable tag: 2.8. 010 Version: 2.8.1 11 Stable tag: 2.8.1 12 12 License: GPLv2 13 13 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 121 121 == Changelog == 122 122 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 123 127 = 2.8.0 = 124 128 * 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() { 2 2 // holds a function queue to call once page is loaded 3 function Main () {3 function Main() { 4 4 var init_functions = []; 5 5 … … 25 25 // marker groups are mapid -> feature group 26 26 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]; 31 31 }; 32 32 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); 35 35 36 36 mg.timeout = null; … … 38 38 // custom attribute 39 39 if (map.fit_markers) { 40 mg.on('layeradd', function (d) {40 mg.on('layeradd', function(d) { 41 41 // needs a timeout so that it doesn't 42 42 // opt out of a bound change 43 43 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()); 46 46 }, 100); 47 47 }, mg); … … 59 59 } 60 60 61 Main.prototype.unescape = function(str) { 62 var div = document.createElement('div'); 63 div.innerHTML = str; 64 return div.innerText; 65 }; 66 61 67 window.WPLeafletMapPlugin = new Main(); 62 68
Note: See TracChangeset
for help on using the changeset viewer.