Version Description
[2013-01-29] = * fixed: infowindow auto-pans on load, to prevent the top of the bubble being cropped * added: WordPress filter 'flexmap_google_maps_api_args' for filtering array of arguments before building Google Maps API URL * added: function flexmap_show_map() accepts an attribute "echo", and returns a string without output to screen when "echo"=>"false" * changed: all scripts now loaded through wp_enqueue_scripts, including language scripts (thanks to a tip from toscho) * changed: bump version of Google Maps API to 3.11
Download this release
Release Info
Developer | webaware |
Plugin | Flexible Map |
Version | 1.6.1 |
Comparing to | |
See all releases |
Code changes from version 1.6.0 to 1.6.1
- class.FlxMapPlugin.php +39 -31
- flexible-map.js +8 -3
- flexible-map.min.js +2 -2
- flexible-map.php +12 -4
- readme.txt +17 -7
class.FlxMapPlugin.php
CHANGED
@@ -5,8 +5,7 @@
|
|
5 |
class FlxMapPlugin {
|
6 |
public $urlBase; // string: base URL path to files in plugin
|
7 |
|
8 |
-
|
9 |
-
private $locale;
|
10 |
|
11 |
/**
|
12 |
* static method for getting the instance of this singleton object
|
@@ -38,8 +37,8 @@ class FlxMapPlugin {
|
|
38 |
}
|
39 |
else {
|
40 |
// non-admin actions and filters for this plugin
|
41 |
-
add_action('wp_footer', array($this, 'actionFooter'), 100); // NB: must come after footer enqueued scripts!
|
42 |
add_action('wp_enqueue_scripts', array($this, 'actionEnqueueScripts'));
|
|
|
43 |
|
44 |
// custom actions and filters for this plugin
|
45 |
add_filter('flexmap_getmap', array($this, 'getMap'), 10, 1);
|
@@ -56,11 +55,19 @@ class FlxMapPlugin {
|
|
56 |
*/
|
57 |
public function actionInit() {
|
58 |
// start off required locales with this website's WP locale
|
59 |
-
$this->locales = array();
|
60 |
$this->locale = get_locale();
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
|
|
64 |
}
|
65 |
|
66 |
/**
|
@@ -69,7 +76,7 @@ class FlxMapPlugin {
|
|
69 |
*/
|
70 |
public function setLocales($locales) {
|
71 |
foreach ($locales as $locale) {
|
72 |
-
$this->
|
73 |
}
|
74 |
}
|
75 |
|
@@ -79,7 +86,8 @@ class FlxMapPlugin {
|
|
79 |
public function actionEnqueueScripts() {
|
80 |
// allow others to override the Google Maps API URL
|
81 |
$protocol = is_ssl() ? 'https' : 'http';
|
82 |
-
$
|
|
|
83 |
if (!empty($apiURL)) {
|
84 |
wp_register_script('google-maps', $apiURL, false, null, true);
|
85 |
}
|
@@ -91,23 +99,19 @@ class FlxMapPlugin {
|
|
91 |
}
|
92 |
|
93 |
/**
|
94 |
-
*
|
|
|
95 |
*/
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
if (file_exists(FLXMAP_PLUGIN_ROOT . "i18n/$locale.js")) {
|
103 |
-
|
104 |
-
}
|
105 |
-
else {
|
106 |
-
// not found, so check for generic locale, e.g. 'zh'
|
107 |
-
$locale = substr($locale, 0, 2);
|
108 |
-
if (file_exists(FLXMAP_PLUGIN_ROOT . "i18n/$locale.js")) {
|
109 |
-
echo "<script charset='utf-8' src=\"{$this->urlBase}i18n/$locale.js?v=$version\"></script>\n";
|
110 |
-
}
|
111 |
}
|
112 |
}
|
113 |
}
|
@@ -251,12 +255,12 @@ HTML;
|
|
251 |
|
252 |
if (isset($attrs['locale'])) {
|
253 |
$script .= " f.setlocale(\"{$this->str2js($attrs['locale'])}\");\n";
|
254 |
-
$this->
|
255 |
}
|
256 |
else if ($this->locale != '' || $this->locale != 'en-US') {
|
257 |
$locale = self::str2js(str_replace('_', '-', $this->locale));
|
258 |
$script .= " f.setlocale(\"$locale\");\n";
|
259 |
-
$this->
|
260 |
}
|
261 |
|
262 |
// add map based on coordinates, with optional marker coordinates
|
@@ -357,7 +361,11 @@ HTML;
|
|
357 |
// allow others to change the generated html
|
358 |
$html = apply_filters('flexmap_shortcode_html', $html, $attrs);
|
359 |
|
|
|
360 |
wp_enqueue_script('flxmap');
|
|
|
|
|
|
|
361 |
|
362 |
return $html;
|
363 |
}
|
@@ -367,7 +375,7 @@ HTML;
|
|
367 |
* @param string $units
|
368 |
* @return string
|
369 |
*/
|
370 |
-
|
371 |
$units = trim($units);
|
372 |
|
373 |
// check for valid CSS units
|
@@ -391,7 +399,7 @@ HTML;
|
|
391 |
* @param string $text
|
392 |
* @return boolean
|
393 |
*/
|
394 |
-
|
395 |
return preg_match('/^(?:y|yes|true|1)$/i', $text);
|
396 |
}
|
397 |
|
@@ -400,7 +408,7 @@ HTML;
|
|
400 |
* @param string $text
|
401 |
* @return boolean
|
402 |
*/
|
403 |
-
|
404 |
return preg_match('/^(?:n|no|false|0)$/i', $text);
|
405 |
}
|
406 |
|
@@ -409,7 +417,7 @@ HTML;
|
|
409 |
* @param string $text
|
410 |
* @return boolean
|
411 |
*/
|
412 |
-
|
413 |
return preg_match('/^-?\\d+(?:\\.\\d+),-?\\d+(?:\\.\\d+)$/', $text);
|
414 |
}
|
415 |
|
@@ -418,7 +426,7 @@ HTML;
|
|
418 |
* @param string $text
|
419 |
* @return string
|
420 |
*/
|
421 |
-
|
422 |
return self::str2js(html_entity_decode($text, ENT_QUOTES, get_option('blog_charset')));
|
423 |
}
|
424 |
|
@@ -427,7 +435,7 @@ HTML;
|
|
427 |
* @param string $text
|
428 |
* @return string
|
429 |
*/
|
430 |
-
|
431 |
return addcslashes($text, "\\/\'\"&\n\r<>");
|
432 |
}
|
433 |
}
|
5 |
class FlxMapPlugin {
|
6 |
public $urlBase; // string: base URL path to files in plugin
|
7 |
|
8 |
+
protected $locale;
|
|
|
9 |
|
10 |
/**
|
11 |
* static method for getting the instance of this singleton object
|
37 |
}
|
38 |
else {
|
39 |
// non-admin actions and filters for this plugin
|
|
|
40 |
add_action('wp_enqueue_scripts', array($this, 'actionEnqueueScripts'));
|
41 |
+
add_filter('clean_url', array($this, 'filterCleanURL'), 11);
|
42 |
|
43 |
// custom actions and filters for this plugin
|
44 |
add_filter('flexmap_getmap', array($this, 'getMap'), 10, 1);
|
55 |
*/
|
56 |
public function actionInit() {
|
57 |
// start off required locales with this website's WP locale
|
|
|
58 |
$this->locale = get_locale();
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* hack: add charset='utf-8' to i18n scripts
|
63 |
+
* @param string $url
|
64 |
+
* @return string
|
65 |
+
*/
|
66 |
+
public function filterCleanURL($url) {
|
67 |
+
if (stripos($url, $this->urlBase . 'i18n/') !== false) {
|
68 |
+
return "$url' charset='utf-8";
|
69 |
}
|
70 |
+
return $url;
|
71 |
}
|
72 |
|
73 |
/**
|
76 |
*/
|
77 |
public function setLocales($locales) {
|
78 |
foreach ($locales as $locale) {
|
79 |
+
$this->enqueueLocale(strtr($locale, '_', '-'));
|
80 |
}
|
81 |
}
|
82 |
|
86 |
public function actionEnqueueScripts() {
|
87 |
// allow others to override the Google Maps API URL
|
88 |
$protocol = is_ssl() ? 'https' : 'http';
|
89 |
+
$args = apply_filters('flexmap_google_maps_api_args', array('v' => '3.11', 'sensor' => 'false'));
|
90 |
+
$apiURL = apply_filters('flexmap_google_maps_api_url', add_query_arg($args, "$protocol://maps.google.com/maps/api/js"));
|
91 |
if (!empty($apiURL)) {
|
92 |
wp_register_script('google-maps', $apiURL, false, null, true);
|
93 |
}
|
99 |
}
|
100 |
|
101 |
/**
|
102 |
+
* enqueue an i18n script
|
103 |
+
* @param string $locale
|
104 |
*/
|
105 |
+
protected function enqueueLocale($locale) {
|
106 |
+
// check for specific locale first, e.g. 'zh-CN'
|
107 |
+
if (file_exists(FLXMAP_PLUGIN_ROOT . "i18n/$locale.js")) {
|
108 |
+
wp_enqueue_script('flxmap-' . $locale, $this->urlBase . "i18n/$locale.js", array('flxmap'), FLXMAP_PLUGIN_VERSION, true);
|
109 |
+
}
|
110 |
+
else {
|
111 |
+
// not found, so check for generic locale, e.g. 'zh'
|
112 |
+
$locale = substr($locale, 0, 2);
|
113 |
if (file_exists(FLXMAP_PLUGIN_ROOT . "i18n/$locale.js")) {
|
114 |
+
wp_enqueue_script('flxmap-' . $locale, $this->urlBase . "i18n/$locale.js", array('flxmap'), FLXMAP_PLUGIN_VERSION, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
}
|
116 |
}
|
117 |
}
|
255 |
|
256 |
if (isset($attrs['locale'])) {
|
257 |
$script .= " f.setlocale(\"{$this->str2js($attrs['locale'])}\");\n";
|
258 |
+
$this->enqueueLocale($attrs['locale']);
|
259 |
}
|
260 |
else if ($this->locale != '' || $this->locale != 'en-US') {
|
261 |
$locale = self::str2js(str_replace('_', '-', $this->locale));
|
262 |
$script .= " f.setlocale(\"$locale\");\n";
|
263 |
+
$this->enqueueLocale($locale);
|
264 |
}
|
265 |
|
266 |
// add map based on coordinates, with optional marker coordinates
|
361 |
// allow others to change the generated html
|
362 |
$html = apply_filters('flexmap_shortcode_html', $html, $attrs);
|
363 |
|
364 |
+
// enqueue scripts
|
365 |
wp_enqueue_script('flxmap');
|
366 |
+
if ($this->locale != '' && $this->locale != 'en_US') {
|
367 |
+
$this->enqueueLocale($this->locale);
|
368 |
+
}
|
369 |
|
370 |
return $html;
|
371 |
}
|
375 |
* @param string $units
|
376 |
* @return string
|
377 |
*/
|
378 |
+
protected static function getUnits($units) {
|
379 |
$units = trim($units);
|
380 |
|
381 |
// check for valid CSS units
|
399 |
* @param string $text
|
400 |
* @return boolean
|
401 |
*/
|
402 |
+
public static function isYes($text) {
|
403 |
return preg_match('/^(?:y|yes|true|1)$/i', $text);
|
404 |
}
|
405 |
|
408 |
* @param string $text
|
409 |
* @return boolean
|
410 |
*/
|
411 |
+
public static function isNo($text) {
|
412 |
return preg_match('/^(?:n|no|false|0)$/i', $text);
|
413 |
}
|
414 |
|
417 |
* @param string $text
|
418 |
* @return boolean
|
419 |
*/
|
420 |
+
public static function isCoordinates($text) {
|
421 |
return preg_match('/^-?\\d+(?:\\.\\d+),-?\\d+(?:\\.\\d+)$/', $text);
|
422 |
}
|
423 |
|
426 |
* @param string $text
|
427 |
* @return string
|
428 |
*/
|
429 |
+
protected static function unhtml($text) {
|
430 |
return self::str2js(html_entity_decode($text, ENT_QUOTES, get_option('blog_charset')));
|
431 |
}
|
432 |
|
435 |
* @param string $text
|
436 |
* @return string
|
437 |
*/
|
438 |
+
protected static function str2js($text) {
|
439 |
return addcslashes($text, "\\/\'\"&\n\r<>");
|
440 |
}
|
441 |
}
|
flexible-map.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
/*!
|
2 |
JavaScript for the WordPress plugin wp-flexible-map
|
3 |
-
copyright (c) 2011-
|
4 |
*/
|
5 |
|
6 |
function FlexibleMap() {
|
@@ -415,8 +415,13 @@ FlexibleMap.prototype = (function() {
|
|
415 |
}
|
416 |
|
417 |
infowin = new google.maps.InfoWindow({content: container});
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
google.maps.event.addListener(point, "click", function() {
|
422 |
infowin.open(map, point);
|
1 |
/*!
|
2 |
JavaScript for the WordPress plugin wp-flexible-map
|
3 |
+
copyright (c) 2011-2013 WebAware Pty Ltd, released under LGPL v2.1
|
4 |
*/
|
5 |
|
6 |
function FlexibleMap() {
|
415 |
}
|
416 |
|
417 |
infowin = new google.maps.InfoWindow({content: container});
|
418 |
+
|
419 |
+
if (this.markerShowInfo) {
|
420 |
+
// open after map is loaded, so that infowindow will auto-pan and won't be cropped at top
|
421 |
+
google.maps.event.addListenerOnce(map, "tilesloaded", function() {
|
422 |
+
infowin.open(map, point);
|
423 |
+
});
|
424 |
+
}
|
425 |
|
426 |
google.maps.event.addListener(point, "click", function() {
|
427 |
infowin.open(map, point);
|
flexible-map.min.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
/*!
|
2 |
JavaScript for the WordPress plugin wp-flexible-map
|
3 |
-
copyright (c) 2011-
|
4 |
*/
|
5 |
-
function FlexibleMap(){var d,b,c,a=false;this.getMap=function(){return d};this.getCenter=function(){return b};this.setCenter=function(e){b=e;d.setCenter(b)};this.getKmlLayer=function(){return c};this.redrawOnce=function(){if(!a){a=true;this.redraw()}};this.showMap=function(e,f){b=new google.maps.LatLng(f[0],f[1]);d=new google.maps.Map(document.getElementById(e),{mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,panControl:this.panControl,zoomControl:this.zoomControl,draggable:this.draggable,disableDoubleClickZoom:!this.dblclickZoom,scrollwheel:this.scrollwheel,streetViewControl:this.streetViewControl,navigationControlOptions:this.navigationControlOptions,center:b,zoom:this.zoom});return d};this.loadKmlMap=function(e){c=new google.maps.KmlLayer(e);c.setMap(d);google.maps.event.addListenerOnce(c,"defaultviewport_changed",function(){b=c.getDefaultViewport().getCenter()});return c};this.mapTypeId=google.maps.MapTypeId.ROADMAP;this.mapTypeControl=true;this.scaleControl=false;this.panControl=false;this.zoomControl=true;this.streetViewControl=false;this.scrollwheel=false;this.draggable=true;this.dblclickZoom=true;this.zoom=16;this.markerTitle="";this.markerDescription="";this.markerHTML="";this.markerLink="";this.markerShowInfo=true;this.markerDirections=false;this.markerDirectionsShow=false;this.markerDirectionsDefault="";this.markerAddress="";this.targetFix=true;this.navigationControlOptions={style:google.maps.NavigationControlStyle.SMALL};this.dirService=false;this.dirPanel=false;this.region="";this.locale="en";this.localeActive="en"}FlexibleMap.prototype=(function(){var d,c,b;if(document.addEventListener){d=function(f,e,g){f.addEventListener(e,g,false)};c=function(e){e.stopPropagation();e.preventDefault()};b=function(f,e){var g=document.createEvent("HTMLEvents");g.initEvent(e,true,true);f.dispatchEvent(g)}}else{if(document.attachEvent){d=function(e,f,g){e.attachEvent("on"+f,function(){g.call(e,window.event)})};c=function(e){e.cancelBubble=true;e.returnValue=0};b=function(f,e){var g=document.createEventObject();g.eventType=e;f.fireEvent("on"+e,g)}}}var a=(function(){function e(g){var h=g.charCodeAt(0),f=h.toString(16);if(h<256){return"\\x"+("00"+f).slice(-2)}return"\\u"+("0000"+f).slice(-4)}return function(f){return f.replace(/[\\\/"'&<>\x00-\x1f\x7f-\xa0\u2000-\u200f\u2028-\u202f]/g,e)}})();return{constructor:FlexibleMap,i18n:{en:{"Click for details":"Click for details",Directions:"Directions",From:"From","Get directions":"Get directions"}},setlocale:function(e){this.locale=e;if(e in this.i18n){this.localeActive=e}else{e=e.substr(0,2);if(e in this.i18n){this.localeActive=e}else{this.localeActive="en"}}return this.localeActive},gettext:function(f){var e=this.i18n[this.localeActive];if(f in e){return e[f]}return f},showKML:function(e,h,i){var g=this,f=document.getElementById(e),l=f.getAttribute("data-flxmap"),k=this.showMap(e,[0,0]),j=this.loadKmlMap(h);if(typeof i!="undefined"){google.maps.event.addListenerOnce(k,"tilesloaded",function(){k.setZoom(i);g.zoom=i})}if(this.markerDirections){this.startDirService(k)}google.maps.event.addListener(j,"click",function(r){var p=r.featureData;if(!p._flxmapOnce){p._flxmapOnce=true;if(g.targetFix){var o=/ target="_blank"/ig;p.description=p.description.replace(o,"");p.infoWindowHtml=p.infoWindowHtml.replace(o,"")}if(g.markerDirections){var n=r.latLng,q=n.lat()+","+n.lng()+",'"+a(p.name)+"'",m='<br /><a href="#" data-flxmap-fix-opera="1" onclick="'+l+".showDirections("+q+'); return false;">'+g.gettext("Directions")+"</a>";p.infoWindowHtml=p.infoWindowHtml.replace(/<\/div><\/div>$/i,m+"</div></div>")}}});if(window.opera&&this.markerDirections){d(f,"click",function(m){if(m.target.getAttribute("data-flxmap-fix-opera")){c(m)}})}},showMarker:function(h,g,m){var f=this.showMap(h,g),p=new google.maps.Marker({map:f,position:new google.maps.LatLng(m[0],m[1])});if(!this.markerTitle){this.markerTitle=this.markerAddress}if(this.markerTitle){var l,n,r,j,k,o,q=this,e=document.createElement("DIV");e.className="flxmap-infowin";p.setTitle(this.markerTitle);k=document.createElement("DIV");k.className="flxmap-marker-title";k.appendChild(document.createTextNode(this.markerTitle));e.appendChild(k);if(this.markerHTML){k=document.createElement("DIV");k.innerHTML=this.markerHTML;e.appendChild(k)}if(this.markerDescription||this.markerLink){k=document.createElement("DIV");k.className="flxmap-marker-link";if(this.markerDescription){r=this.markerDescription.split("\n");for(l=0,n=r.length;l<n;l++){if(l>0){k.appendChild(document.createElement("BR"))}k.appendChild(document.createTextNode(r[l]))}if(this.markerLink){k.appendChild(document.createElement("BR"))}}if(this.markerLink){o=document.createElement("A");o.href=this.markerLink;o.appendChild(document.createTextNode(this.gettext("Click for details")));k.appendChild(o)}e.appendChild(k)}if(this.markerDirections){k=document.createElement("DIV");k.className="flxmap-directions-link";o=document.createElement("A");o.href="#";o.dataLatitude=m[0];o.dataLongitude=m[1];o.dataTitle=this.markerTitle;d(o,"click",function(i){c(i);q.showDirections(this.dataLatitude,this.dataLongitude,this.dataTitle)});o.appendChild(document.createTextNode(this.gettext("Directions")));k.appendChild(o);e.appendChild(k)}if(this.markerDirections||this.markerDirectionsShow){this.startDirService(f);if(this.markerDirectionsShow){this.showDirections(m[0],m[1],this.markerTitle)}}j=new google.maps.InfoWindow({content:e});if(this.markerShowInfo){j.open(f,p)}google.maps.event.addListener(p,"click",function(){j.open(f,p)})}},showAddress:function(e,f){var g=this,h=new google.maps.Geocoder();this.markerAddress=f;if(this.markerTitle===""){this.markerTitle=f}h.geocode({address:f,region:this.region},function(k,j){if(j==google.maps.GeocoderStatus.OK){var i=k[0].geometry.location,l=[i.lat(),i.lng()];g.showMarker(e,l,l)}else{alert("Map address returns error: "+j)}})},redraw:function(){var f=this.getMap(),e=this.getKmlLayer();google.maps.event.trigger(f,"resize");if(e){f.fitBounds(e.getDefaultViewport())}else{f.setCenter(this.getCenter());f.setZoom(this.zoom)}},startDirService:function(e){if(!this.dirService){this.dirService=new google.maps.DirectionsService()}if(!this.dirPanel){this.dirPanel=new google.maps.DirectionsRenderer({map:e,panel:document.getElementById(this.markerDirections)})}},showDirections:function(i,e,k){var f=document.getElementById(this.markerDirections),h=document.createElement("form"),n=this,j=this.region||"",l,g,m;while(!!(g=f.lastChild)){f.removeChild(g)}g=document.createElement("p");g.appendChild(document.createTextNode(this.gettext("From")+": "));m=document.createElement("input");m.type="text";m.name="from";m.value=this.markerDirectionsDefault;g.appendChild(m);l=document.createElement("input");l.type="submit";l.value=this.gettext("Get directions");g.appendChild(l);h.appendChild(g);f.appendChild(h);if(typeof h.elements.from=="undefined"){h.elements.from=m}d(h,"submit",function(q){c(q);var r=this.elements.from.value;if(/\S/.test(r)){var o=(n.markerAddress==="")?new google.maps.LatLng(i,e):n.markerAddress,p={origin:r,region:j,destination:o,travelMode:google.maps.DirectionsTravelMode.DRIVING};n.dirService.route(p,function(u,s){var t=google.maps.DirectionsStatus;switch(s){case t.OK:n.dirPanel.setDirections(u);break;case t.ZERO_RESULTS:alert("No route could be found between the origin and destination.");break;case t.OVER_QUERY_LIMIT:alert("The webpage has gone over the requests limit in too short a period of time.");break;case t.REQUEST_DENIED:alert("The webpage is not allowed to use the directions service.");break;case t.INVALID_REQUEST:alert("Invalid directions request.");break;case t.NOT_FOUND:alert("Origin or destination was not found.");break;default:alert("A directions request could not be processed due to a server error. The request may succeed if you try again.");break}})}});if(m.value){b(h,"submit")}}}})();
|
1 |
/*!
|
2 |
JavaScript for the WordPress plugin wp-flexible-map
|
3 |
+
copyright (c) 2011-2013 WebAware Pty Ltd, released under LGPL v2.1
|
4 |
*/
|
5 |
+
function FlexibleMap(){var d,b,c,a=false;this.getMap=function(){return d};this.getCenter=function(){return b};this.setCenter=function(e){b=e;d.setCenter(b)};this.getKmlLayer=function(){return c};this.redrawOnce=function(){if(!a){a=true;this.redraw()}};this.showMap=function(e,f){b=new google.maps.LatLng(f[0],f[1]);d=new google.maps.Map(document.getElementById(e),{mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,panControl:this.panControl,zoomControl:this.zoomControl,draggable:this.draggable,disableDoubleClickZoom:!this.dblclickZoom,scrollwheel:this.scrollwheel,streetViewControl:this.streetViewControl,navigationControlOptions:this.navigationControlOptions,center:b,zoom:this.zoom});return d};this.loadKmlMap=function(e){c=new google.maps.KmlLayer(e);c.setMap(d);google.maps.event.addListenerOnce(c,"defaultviewport_changed",function(){b=c.getDefaultViewport().getCenter()});return c};this.mapTypeId=google.maps.MapTypeId.ROADMAP;this.mapTypeControl=true;this.scaleControl=false;this.panControl=false;this.zoomControl=true;this.streetViewControl=false;this.scrollwheel=false;this.draggable=true;this.dblclickZoom=true;this.zoom=16;this.markerTitle="";this.markerDescription="";this.markerHTML="";this.markerLink="";this.markerShowInfo=true;this.markerDirections=false;this.markerDirectionsShow=false;this.markerDirectionsDefault="";this.markerAddress="";this.targetFix=true;this.navigationControlOptions={style:google.maps.NavigationControlStyle.SMALL};this.dirService=false;this.dirPanel=false;this.region="";this.locale="en";this.localeActive="en"}FlexibleMap.prototype=(function(){var d,c,b;if(document.addEventListener){d=function(f,e,g){f.addEventListener(e,g,false)};c=function(e){e.stopPropagation();e.preventDefault()};b=function(f,e){var g=document.createEvent("HTMLEvents");g.initEvent(e,true,true);f.dispatchEvent(g)}}else{if(document.attachEvent){d=function(e,f,g){e.attachEvent("on"+f,function(){g.call(e,window.event)})};c=function(e){e.cancelBubble=true;e.returnValue=0};b=function(f,e){var g=document.createEventObject();g.eventType=e;f.fireEvent("on"+e,g)}}}var a=(function(){function e(g){var h=g.charCodeAt(0),f=h.toString(16);if(h<256){return"\\x"+("00"+f).slice(-2)}return"\\u"+("0000"+f).slice(-4)}return function(f){return f.replace(/[\\\/"'&<>\x00-\x1f\x7f-\xa0\u2000-\u200f\u2028-\u202f]/g,e)}})();return{constructor:FlexibleMap,i18n:{en:{"Click for details":"Click for details",Directions:"Directions",From:"From","Get directions":"Get directions"}},setlocale:function(e){this.locale=e;if(e in this.i18n){this.localeActive=e}else{e=e.substr(0,2);if(e in this.i18n){this.localeActive=e}else{this.localeActive="en"}}return this.localeActive},gettext:function(f){var e=this.i18n[this.localeActive];if(f in e){return e[f]}return f},showKML:function(e,h,i){var g=this,f=document.getElementById(e),l=f.getAttribute("data-flxmap"),k=this.showMap(e,[0,0]),j=this.loadKmlMap(h);if(typeof i!="undefined"){google.maps.event.addListenerOnce(k,"tilesloaded",function(){k.setZoom(i);g.zoom=i})}if(this.markerDirections){this.startDirService(k)}google.maps.event.addListener(j,"click",function(r){var p=r.featureData;if(!p._flxmapOnce){p._flxmapOnce=true;if(g.targetFix){var o=/ target="_blank"/ig;p.description=p.description.replace(o,"");p.infoWindowHtml=p.infoWindowHtml.replace(o,"")}if(g.markerDirections){var n=r.latLng,q=n.lat()+","+n.lng()+",'"+a(p.name)+"'",m='<br /><a href="#" data-flxmap-fix-opera="1" onclick="'+l+".showDirections("+q+'); return false;">'+g.gettext("Directions")+"</a>";p.infoWindowHtml=p.infoWindowHtml.replace(/<\/div><\/div>$/i,m+"</div></div>")}}});if(window.opera&&this.markerDirections){d(f,"click",function(m){if(m.target.getAttribute("data-flxmap-fix-opera")){c(m)}})}},showMarker:function(h,g,m){var f=this.showMap(h,g),p=new google.maps.Marker({map:f,position:new google.maps.LatLng(m[0],m[1])});if(!this.markerTitle){this.markerTitle=this.markerAddress}if(this.markerTitle){var l,n,r,j,k,o,q=this,e=document.createElement("DIV");e.className="flxmap-infowin";p.setTitle(this.markerTitle);k=document.createElement("DIV");k.className="flxmap-marker-title";k.appendChild(document.createTextNode(this.markerTitle));e.appendChild(k);if(this.markerHTML){k=document.createElement("DIV");k.innerHTML=this.markerHTML;e.appendChild(k)}if(this.markerDescription||this.markerLink){k=document.createElement("DIV");k.className="flxmap-marker-link";if(this.markerDescription){r=this.markerDescription.split("\n");for(l=0,n=r.length;l<n;l++){if(l>0){k.appendChild(document.createElement("BR"))}k.appendChild(document.createTextNode(r[l]))}if(this.markerLink){k.appendChild(document.createElement("BR"))}}if(this.markerLink){o=document.createElement("A");o.href=this.markerLink;o.appendChild(document.createTextNode(this.gettext("Click for details")));k.appendChild(o)}e.appendChild(k)}if(this.markerDirections){k=document.createElement("DIV");k.className="flxmap-directions-link";o=document.createElement("A");o.href="#";o.dataLatitude=m[0];o.dataLongitude=m[1];o.dataTitle=this.markerTitle;d(o,"click",function(i){c(i);q.showDirections(this.dataLatitude,this.dataLongitude,this.dataTitle)});o.appendChild(document.createTextNode(this.gettext("Directions")));k.appendChild(o);e.appendChild(k)}if(this.markerDirections||this.markerDirectionsShow){this.startDirService(f);if(this.markerDirectionsShow){this.showDirections(m[0],m[1],this.markerTitle)}}j=new google.maps.InfoWindow({content:e});if(this.markerShowInfo){google.maps.event.addListenerOnce(f,"tilesloaded",function(){j.open(f,p)})}google.maps.event.addListener(p,"click",function(){j.open(f,p)})}},showAddress:function(e,f){var g=this,h=new google.maps.Geocoder();this.markerAddress=f;if(this.markerTitle===""){this.markerTitle=f}h.geocode({address:f,region:this.region},function(k,j){if(j==google.maps.GeocoderStatus.OK){var i=k[0].geometry.location,l=[i.lat(),i.lng()];g.showMarker(e,l,l)}else{alert("Map address returns error: "+j)}})},redraw:function(){var f=this.getMap(),e=this.getKmlLayer();google.maps.event.trigger(f,"resize");if(e){f.fitBounds(e.getDefaultViewport())}else{f.setCenter(this.getCenter());f.setZoom(this.zoom)}},startDirService:function(e){if(!this.dirService){this.dirService=new google.maps.DirectionsService()}if(!this.dirPanel){this.dirPanel=new google.maps.DirectionsRenderer({map:e,panel:document.getElementById(this.markerDirections)})}},showDirections:function(i,e,k){var f=document.getElementById(this.markerDirections),h=document.createElement("form"),n=this,j=this.region||"",l,g,m;while(!!(g=f.lastChild)){f.removeChild(g)}g=document.createElement("p");g.appendChild(document.createTextNode(this.gettext("From")+": "));m=document.createElement("input");m.type="text";m.name="from";m.value=this.markerDirectionsDefault;g.appendChild(m);l=document.createElement("input");l.type="submit";l.value=this.gettext("Get directions");g.appendChild(l);h.appendChild(g);f.appendChild(h);if(typeof h.elements.from=="undefined"){h.elements.from=m}d(h,"submit",function(q){c(q);var r=this.elements.from.value;if(/\S/.test(r)){var o=(n.markerAddress==="")?new google.maps.LatLng(i,e):n.markerAddress,p={origin:r,region:j,destination:o,travelMode:google.maps.DirectionsTravelMode.DRIVING};n.dirService.route(p,function(u,s){var t=google.maps.DirectionsStatus;switch(s){case t.OK:n.dirPanel.setDirections(u);break;case t.ZERO_RESULTS:alert("No route could be found between the origin and destination.");break;case t.OVER_QUERY_LIMIT:alert("The webpage has gone over the requests limit in too short a period of time.");break;case t.REQUEST_DENIED:alert("The webpage is not allowed to use the directions service.");break;case t.INVALID_REQUEST:alert("Invalid directions request.");break;case t.NOT_FOUND:alert("Origin or destination was not found.");break;default:alert("A directions request could not be processed due to a server error. The request may succeed if you try again.");break}})}});if(m.value){b(h,"submit")}}}})();
|
flexible-map.php
CHANGED
@@ -3,13 +3,13 @@
|
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: http://snippets.webaware.com.au/wordpress-plugins/wp-flexible-map/
|
5 |
Description: Embed Google Maps in pages and posts, either by centre coodinates or street address, or by URL to a Google Earth KML file.
|
6 |
-
Version: 1.6.
|
7 |
Author: WebAware
|
8 |
Author URI: http://www.webaware.com.au/
|
9 |
*/
|
10 |
|
11 |
/*
|
12 |
-
copyright (c) 2011-
|
13 |
|
14 |
This program is free software; you can redistribute it and/or modify
|
15 |
it under the terms of the GNU General Public License, version 2, as
|
@@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
28 |
if (!defined('FLXMAP_PLUGIN_ROOT')) {
|
29 |
define('FLXMAP_PLUGIN_ROOT', dirname(__FILE__) . '/');
|
30 |
define('FLXMAP_PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));
|
31 |
-
define('FLXMAP_PLUGIN_VERSION', '1.6.
|
32 |
|
33 |
// shortcode tags
|
34 |
define('FLXMAP_PLUGIN_TAG_MAP', 'flexiblemap');
|
@@ -58,11 +58,19 @@ $FlxMapPlugin = FlxMapPlugin::getInstance();
|
|
58 |
|
59 |
/**
|
60 |
* utility function so themes can easily display the map
|
|
|
61 |
* @param array $attrs
|
|
|
62 |
*/
|
63 |
function flexmap_show_map($attrs) {
|
64 |
$plugin = FlxMapPlugin::getInstance();
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
}
|
67 |
|
68 |
/**
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: http://snippets.webaware.com.au/wordpress-plugins/wp-flexible-map/
|
5 |
Description: Embed Google Maps in pages and posts, either by centre coodinates or street address, or by URL to a Google Earth KML file.
|
6 |
+
Version: 1.6.1
|
7 |
Author: WebAware
|
8 |
Author URI: http://www.webaware.com.au/
|
9 |
*/
|
10 |
|
11 |
/*
|
12 |
+
copyright (c) 2011-2013 WebAware Pty Ltd (email : rmckay@webaware.com.au)
|
13 |
|
14 |
This program is free software; you can redistribute it and/or modify
|
15 |
it under the terms of the GNU General Public License, version 2, as
|
28 |
if (!defined('FLXMAP_PLUGIN_ROOT')) {
|
29 |
define('FLXMAP_PLUGIN_ROOT', dirname(__FILE__) . '/');
|
30 |
define('FLXMAP_PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));
|
31 |
+
define('FLXMAP_PLUGIN_VERSION', '1.6.1');
|
32 |
|
33 |
// shortcode tags
|
34 |
define('FLXMAP_PLUGIN_TAG_MAP', 'flexiblemap');
|
58 |
|
59 |
/**
|
60 |
* utility function so themes can easily display the map
|
61 |
+
* to return as a string without output to screen, add 'echo'=>'false' to array of attributes
|
62 |
* @param array $attrs
|
63 |
+
* @return string
|
64 |
*/
|
65 |
function flexmap_show_map($attrs) {
|
66 |
$plugin = FlxMapPlugin::getInstance();
|
67 |
+
$map = $plugin->getMap($attrs);
|
68 |
+
|
69 |
+
if (!isset($attrs['echo']) || FlxMapPlugin::isYes($attrs['echo'])) {
|
70 |
+
echo $map;
|
71 |
+
}
|
72 |
+
|
73 |
+
return $map;
|
74 |
}
|
75 |
|
76 |
/**
|
readme.txt
CHANGED
@@ -6,8 +6,8 @@ Author URI: http://www.webaware.com.au/
|
|
6 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZCY9PST8E4GQ
|
7 |
Tags: google, maps, google maps, shortcode, kml
|
8 |
Requires at least: 3.2.1
|
9 |
-
Tested up to: 3.5.
|
10 |
-
Stable tag: 1.6.
|
11 |
License: GPLv2 or later
|
12 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
|
@@ -103,7 +103,7 @@ Either the center or the address paramater is required. If you provide both, the
|
|
103 |
|
104 |
= Calling from templates or plugins =
|
105 |
|
106 |
-
There is a PHP function `flexmap_show_map()` for theme and plugin developers. All of the same parameters for the shortcode can be passed to the function in an associative array.
|
107 |
|
108 |
*Sample*:
|
109 |
`flexmap_show_map(array(
|
@@ -121,10 +121,11 @@ There is a PHP function `flexmap_show_map()` for theme and plugin developers. Al
|
|
121 |
|
122 |
There are also some filter hooks that allow you to change the behaviour of the plugin.
|
123 |
|
124 |
-
* **
|
125 |
-
* **
|
126 |
-
* **
|
127 |
-
* **
|
|
|
128 |
|
129 |
For more information and examples, see [the website](http://snippets.webaware.com.au/wordpress-plugins/wp-flexible-map/).
|
130 |
|
@@ -175,6 +176,8 @@ $('div.ui-tabs').bind('tabsshow', function(event, ui) {
|
|
175 |
});
|
176 |
</script>`
|
177 |
|
|
|
|
|
178 |
= How can I get access to the map object? =
|
179 |
|
180 |
If you want to add your own scripting for the map, you can get the map object by identifying the FlexibleMap global variable for your map, and asking it to getMap(). By default, each FlexibleMap is given a randomly generated ID and the global variable name is derived from that. The map's containing div has a data property with this global variable name. Here's some sample jQuery code that gets the map object for the (first) map:
|
@@ -226,6 +229,13 @@ NB: currently, only AJAX methods that parse script tags will work correctly; thi
|
|
226 |
|
227 |
== Changelog ==
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
= 1.6.0 [2012-12-30] =
|
230 |
* added: themes can call function flexmap_load_scripts() to force load of scripts, e.g. on single-page AJAX websites
|
231 |
* added: can add HTML block to infowindow, e.g. images
|
6 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6ZCY9PST8E4GQ
|
7 |
Tags: google, maps, google maps, shortcode, kml
|
8 |
Requires at least: 3.2.1
|
9 |
+
Tested up to: 3.5.1
|
10 |
+
Stable tag: 1.6.1
|
11 |
License: GPLv2 or later
|
12 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
|
103 |
|
104 |
= Calling from templates or plugins =
|
105 |
|
106 |
+
There is a PHP function `flexmap_show_map()` for theme and plugin developers. All of the same parameters for the shortcode can be passed to the function in an associative array. If you want it to return the map as a string without output to screen, add "echo"=>"false" to array of attributes.
|
107 |
|
108 |
*Sample*:
|
109 |
`flexmap_show_map(array(
|
121 |
|
122 |
There are also some filter hooks that allow you to change the behaviour of the plugin.
|
123 |
|
124 |
+
* **flexmap_google_maps_api_args**: filter the array of arguments that will be passed to the Google Maps API, e.g. 'v'=>'3.11', 'sensor'=>'false'
|
125 |
+
* **flexmap_google_maps_api_url**: filter the Google Maps API URL, as a string
|
126 |
+
* **flexmap_shortcode_attrs**: filter the array of shortcode attributes, e.g. change the width and height
|
127 |
+
* **flexmap_shortcode_styles**: filter the array of inline styles applied to the div wrapping the map, e.g. remove width and height so that it can be specified in the theme's stylesheets
|
128 |
+
* **flexmap_shortcode_html**: filter the generated html, e.g. wrap another div around it, add a link to Google Maps, add some additonal script, etc.
|
129 |
|
130 |
For more information and examples, see [the website](http://snippets.webaware.com.au/wordpress-plugins/wp-flexible-map/).
|
131 |
|
176 |
});
|
177 |
</script>`
|
178 |
|
179 |
+
For tabs in jQuery Tools, see [this support topic](http://wordpress.org/support/topic/tabs-map#post-3784706).
|
180 |
+
|
181 |
= How can I get access to the map object? =
|
182 |
|
183 |
If you want to add your own scripting for the map, you can get the map object by identifying the FlexibleMap global variable for your map, and asking it to getMap(). By default, each FlexibleMap is given a randomly generated ID and the global variable name is derived from that. The map's containing div has a data property with this global variable name. Here's some sample jQuery code that gets the map object for the (first) map:
|
229 |
|
230 |
== Changelog ==
|
231 |
|
232 |
+
= 1.6.1 [2013-01-29] =
|
233 |
+
* fixed: infowindow auto-pans on load, to prevent the top of the bubble being cropped
|
234 |
+
* added: WordPress filter 'flexmap_google_maps_api_args' for filtering array of arguments before building Google Maps API URL
|
235 |
+
* added: function flexmap_show_map() accepts an attribute "echo", and returns a string without output to screen when "echo"=>"false"
|
236 |
+
* changed: all scripts now loaded through wp_enqueue_scripts, including language scripts (thanks to a [tip from toscho](http://wordpress.stackexchange.com/a/38335/24260))
|
237 |
+
* changed: bump version of Google Maps API to 3.11
|
238 |
+
|
239 |
= 1.6.0 [2012-12-30] =
|
240 |
* added: themes can call function flexmap_load_scripts() to force load of scripts, e.g. on single-page AJAX websites
|
241 |
* added: can add HTML block to infowindow, e.g. images
|