Version Description
[2012-02-04] = * added: address parameter as alternative to center coordinates * added: use address parameter for directions, if given (so that directions match address) * changed: readme improved a little * changed: refactored code for DRY (don't repeat yourself)
Download this release
Release Info
Developer | webaware |
Plugin | Flexible Map |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- class.FlxMapAdmin.php +5 -2
- class.FlxMapPlugin.php +91 -35
- flexible-map.js +35 -7
- flexible-map.min.js +1 -1
- flexible-map.php +7 -9
- instructions.html +19 -0
- readme.txt +66 -46
class.FlxMapAdmin.php
CHANGED
@@ -15,7 +15,7 @@ class FlxMapAdmin {
|
|
15 |
public function __construct($plugin) {
|
16 |
$this->plugin = $plugin;
|
17 |
|
18 |
-
// add
|
19 |
add_action('admin_menu', array($this, 'addAdminMenu'));
|
20 |
|
21 |
// add action hook for adding plugin meta links
|
@@ -32,8 +32,8 @@ class FlxMapAdmin {
|
|
32 |
$hookname = get_plugin_page_hookname(self::MENU_PAGE . '-instructions', '');
|
33 |
if (!empty($hookname)) {
|
34 |
add_action($hookname, array($this, 'instructions'));
|
|
|
35 |
}
|
36 |
-
$_registered_pages[$hookname] = true;
|
37 |
}
|
38 |
|
39 |
/**
|
@@ -47,6 +47,9 @@ class FlxMapAdmin {
|
|
47 |
return $links;
|
48 |
}
|
49 |
|
|
|
|
|
|
|
50 |
public function instructions() {
|
51 |
echo "<div class='wrap'>\n";
|
52 |
screen_icon('plugins');
|
15 |
public function __construct($plugin) {
|
16 |
$this->plugin = $plugin;
|
17 |
|
18 |
+
// add admin menu items
|
19 |
add_action('admin_menu', array($this, 'addAdminMenu'));
|
20 |
|
21 |
// add action hook for adding plugin meta links
|
32 |
$hookname = get_plugin_page_hookname(self::MENU_PAGE . '-instructions', '');
|
33 |
if (!empty($hookname)) {
|
34 |
add_action($hookname, array($this, 'instructions'));
|
35 |
+
$_registered_pages[$hookname] = true;
|
36 |
}
|
|
|
37 |
}
|
38 |
|
39 |
/**
|
47 |
return $links;
|
48 |
}
|
49 |
|
50 |
+
/**
|
51 |
+
* show instructions page
|
52 |
+
*/
|
53 |
public function instructions() {
|
54 |
echo "<div class='wrap'>\n";
|
55 |
screen_icon('plugins');
|
class.FlxMapPlugin.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
|
4 |
-
|
5 |
class FlxMapPlugin {
|
6 |
public $urlBase; // string: base URL path to files in plugin
|
7 |
|
@@ -9,10 +9,10 @@ class FlxMapPlugin {
|
|
9 |
private $loadScripts = FALSE; // true when scripts should be loaded
|
10 |
|
11 |
/**
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
public static function getInstance() {
|
17 |
static $instance = NULL;
|
18 |
|
@@ -25,8 +25,8 @@ class FlxMapPlugin {
|
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
-
|
29 |
-
|
30 |
private function __construct() {
|
31 |
// record plugin URL base
|
32 |
$this->urlBase = WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__));
|
@@ -48,15 +48,15 @@ class FlxMapPlugin {
|
|
48 |
}
|
49 |
|
50 |
/**
|
51 |
-
|
52 |
-
|
53 |
public function activate() {
|
54 |
// NOP
|
55 |
}
|
56 |
|
57 |
/**
|
58 |
-
|
59 |
-
|
60 |
public function deactivate() {
|
61 |
// remove deprecated custom capabilities for administrator (from previous versions)
|
62 |
$role = get_role('administrator');
|
@@ -73,7 +73,7 @@ class FlxMapPlugin {
|
|
73 |
public function actionFooter() {
|
74 |
if ($this->loadScripts) {
|
75 |
// load required scripts
|
76 |
-
$url = parse_url("{$this->urlBase}/flexible-map.min.js", PHP_URL_PATH) . '?v=
|
77 |
|
78 |
echo <<<HTML
|
79 |
<script src="$url"></script>
|
@@ -84,15 +84,15 @@ HTML;
|
|
84 |
}
|
85 |
|
86 |
/**
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
public function shortcodeMap($attrs) {
|
93 |
$html = '';
|
94 |
|
95 |
-
if (!empty($attrs['src']) || !empty($attrs['center'])) {
|
96 |
$this->loadScripts = TRUE;
|
97 |
$divID = uniqid('flxmap-');
|
98 |
$width = isset($attrs['width']) ? preg_replace('/\D/', '', $attrs['width']) : 400;
|
@@ -100,9 +100,9 @@ HTML;
|
|
100 |
|
101 |
$directions = FALSE;
|
102 |
$divDirections = '';
|
103 |
-
if (isset($attrs['directions'])) {
|
104 |
$directions = TRUE;
|
105 |
-
if (
|
106 |
$divDirectionsID = "$divID-dir";
|
107 |
$divDirections = "\n<div id='$divDirectionsID' class='flxmap-directions'></div>";
|
108 |
}
|
@@ -123,7 +123,7 @@ HTML;
|
|
123 |
|
124 |
HTML;
|
125 |
|
126 |
-
if (!(isset($attrs['hideMapType']) &&
|
127 |
$html .= " f.mapTypeControl = true;\n";
|
128 |
}
|
129 |
|
@@ -131,7 +131,7 @@ HTML;
|
|
131 |
$html .= " f.markerDirections = \"$divDirectionsID\";\n";
|
132 |
}
|
133 |
|
134 |
-
if (isset($attrs['showinfo']) &&
|
135 |
$html .= " f.markerShowInfo = false;\n";
|
136 |
}
|
137 |
|
@@ -144,9 +144,9 @@ HTML;
|
|
144 |
}
|
145 |
|
146 |
// add map based on coordinates, with optional marker coordinates
|
147 |
-
if (isset($attrs['center']) &&
|
148 |
$marker = $attrs['center'];
|
149 |
-
if (isset($attrs['marker']) &&
|
150 |
$marker = $attrs['marker'];
|
151 |
|
152 |
if (isset($attrs['zoom']))
|
@@ -158,15 +158,39 @@ HTML;
|
|
158 |
if (!empty($attrs['description']))
|
159 |
$html .= " f.markerDescription = \"{$this->unhtml($attrs['description'])}\";\n";
|
160 |
|
161 |
-
if (!empty($attrs['
|
162 |
-
$html .= " f.
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
$html .= " f.showMarker(\"$divID\", [{$attrs['center']}], [{$marker}]);\n";
|
165 |
}
|
166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
// add map based on KML file
|
168 |
else if (isset($attrs['src'])) {
|
169 |
-
$kmlfile = $attrs['src'];
|
170 |
$html .= " f.showKML(\"$divID\", \"$kmlfile\"";
|
171 |
|
172 |
if (isset($attrs['zoom']))
|
@@ -181,16 +205,48 @@ HTML;
|
|
181 |
return $html;
|
182 |
}
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
private static function unhtml($text) {
|
185 |
-
return
|
186 |
}
|
187 |
|
188 |
/**
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
}
|
196 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* class for managing the plugin
|
4 |
+
*/
|
5 |
class FlxMapPlugin {
|
6 |
public $urlBase; // string: base URL path to files in plugin
|
7 |
|
9 |
private $loadScripts = FALSE; // true when scripts should be loaded
|
10 |
|
11 |
/**
|
12 |
+
* static method for getting the instance of this singleton object
|
13 |
+
*
|
14 |
+
* @return FlxMapPlugin
|
15 |
+
*/
|
16 |
public static function getInstance() {
|
17 |
static $instance = NULL;
|
18 |
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
+
* hook the plug-in's initialise event to handle all post-activation initialisation
|
29 |
+
*/
|
30 |
private function __construct() {
|
31 |
// record plugin URL base
|
32 |
$this->urlBase = WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__));
|
48 |
}
|
49 |
|
50 |
/**
|
51 |
+
* activate the plug-in (called by activate event): add custom capabilities, etc.
|
52 |
+
*/
|
53 |
public function activate() {
|
54 |
// NOP
|
55 |
}
|
56 |
|
57 |
/**
|
58 |
+
* deactivate the plug-in (called by deactivate event): remove custom capabilities, etc.
|
59 |
+
*/
|
60 |
public function deactivate() {
|
61 |
// remove deprecated custom capabilities for administrator (from previous versions)
|
62 |
$role = get_role('administrator');
|
73 |
public function actionFooter() {
|
74 |
if ($this->loadScripts) {
|
75 |
// load required scripts
|
76 |
+
$url = parse_url("{$this->urlBase}/flexible-map.min.js", PHP_URL_PATH) . '?v=3';
|
77 |
|
78 |
echo <<<HTML
|
79 |
<script src="$url"></script>
|
84 |
}
|
85 |
|
86 |
/**
|
87 |
+
* handle shortcode for map display
|
88 |
+
*
|
89 |
+
* @param array shortcode attributes as supplied by the WP shortcode API
|
90 |
+
* @return string output to substitute for the shortcode
|
91 |
+
*/
|
92 |
public function shortcodeMap($attrs) {
|
93 |
$html = '';
|
94 |
|
95 |
+
if (!empty($attrs['src']) || !empty($attrs['center']) || !empty($attrs['address'])) {
|
96 |
$this->loadScripts = TRUE;
|
97 |
$divID = uniqid('flxmap-');
|
98 |
$width = isset($attrs['width']) ? preg_replace('/\D/', '', $attrs['width']) : 400;
|
100 |
|
101 |
$directions = FALSE;
|
102 |
$divDirections = '';
|
103 |
+
if (isset($attrs['directions']) && !self::isNo($attrs['directions'])) {
|
104 |
$directions = TRUE;
|
105 |
+
if (self::isYes($attrs['directions'])) {
|
106 |
$divDirectionsID = "$divID-dir";
|
107 |
$divDirections = "\n<div id='$divDirectionsID' class='flxmap-directions'></div>";
|
108 |
}
|
123 |
|
124 |
HTML;
|
125 |
|
126 |
+
if (!(isset($attrs['hideMapType']) && self::isYes($attrs['hideMapType']))) {
|
127 |
$html .= " f.mapTypeControl = true;\n";
|
128 |
}
|
129 |
|
131 |
$html .= " f.markerDirections = \"$divDirectionsID\";\n";
|
132 |
}
|
133 |
|
134 |
+
if (isset($attrs['showinfo']) && self::isNo($attrs['showinfo'])) {
|
135 |
$html .= " f.markerShowInfo = false;\n";
|
136 |
}
|
137 |
|
144 |
}
|
145 |
|
146 |
// add map based on coordinates, with optional marker coordinates
|
147 |
+
if (isset($attrs['center']) && self::isCoordinates($attrs['center'])) {
|
148 |
$marker = $attrs['center'];
|
149 |
+
if (isset($attrs['marker']) && self::isCoordinates($attrs['marker']))
|
150 |
$marker = $attrs['marker'];
|
151 |
|
152 |
if (isset($attrs['zoom']))
|
158 |
if (!empty($attrs['description']))
|
159 |
$html .= " f.markerDescription = \"{$this->unhtml($attrs['description'])}\";\n";
|
160 |
|
161 |
+
if (!empty($attrs['address']))
|
162 |
+
$html .= " f.markerAddress = \"{$this->unhtml($attrs['address'])}\";\n";
|
163 |
+
|
164 |
+
if (!empty($attrs['link'])) {
|
165 |
+
$link = self::str2js($attrs['link']);
|
166 |
+
$html .= " f.markerLink = \"$link\";\n";
|
167 |
+
}
|
168 |
|
169 |
$html .= " f.showMarker(\"$divID\", [{$attrs['center']}], [{$marker}]);\n";
|
170 |
}
|
171 |
|
172 |
+
// add map based on address query
|
173 |
+
else if (isset($attrs['address'])) {
|
174 |
+
if (isset($attrs['zoom']))
|
175 |
+
$html .= " f.zoom = " . preg_replace('/\D/', '', $attrs['zoom']) . ";\n";
|
176 |
+
|
177 |
+
if (!empty($attrs['title']))
|
178 |
+
$html .= " f.markerTitle = \"{$this->unhtml($attrs['title'])}\";\n";
|
179 |
+
|
180 |
+
if (!empty($attrs['description']))
|
181 |
+
$html .= " f.markerDescription = \"{$this->unhtml($attrs['description'])}\";\n";
|
182 |
+
|
183 |
+
if (!empty($attrs['link'])) {
|
184 |
+
$link = self::str2js($attrs['link']);
|
185 |
+
$html .= " f.markerLink = \"$link\";\n";
|
186 |
+
}
|
187 |
+
|
188 |
+
$html .= " f.showAddress(\"$divID\", \"{$this->unhtml($attrs['address'])}\");\n";
|
189 |
+
}
|
190 |
+
|
191 |
// add map based on KML file
|
192 |
else if (isset($attrs['src'])) {
|
193 |
+
$kmlfile = self::str2js($attrs['src']);
|
194 |
$html .= " f.showKML(\"$divID\", \"$kmlfile\"";
|
195 |
|
196 |
if (isset($attrs['zoom']))
|
205 |
return $html;
|
206 |
}
|
207 |
|
208 |
+
/**
|
209 |
+
* test string to see if contents equate to yes/true
|
210 |
+
* @param string $text
|
211 |
+
* @return boolean
|
212 |
+
*/
|
213 |
+
private static function isYes($text) {
|
214 |
+
return preg_match('/^(?:y|yes|true|1)$/i', $text);
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* test string to see if contents equate to no/false
|
219 |
+
* @param string $text
|
220 |
+
* @return boolean
|
221 |
+
*/
|
222 |
+
private static function isNo($text) {
|
223 |
+
return preg_match('/^(?:n|no|false|0)$/i', $text);
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* test string to see if contents are map coordinates (latitude,longitude)
|
228 |
+
* @param string $text
|
229 |
+
* @return boolean
|
230 |
+
*/
|
231 |
+
private static function isCoordinates($text) {
|
232 |
+
return preg_match('/^-?\\d+(?:\\.\\d+),-?\\d+(?:\\.\\d+)$/', $text);
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* decode HTML-encoded text and encode for JavaScript string
|
237 |
+
* @param string $text
|
238 |
+
* @return string
|
239 |
+
*/
|
240 |
private static function unhtml($text) {
|
241 |
+
return self::str2js(html_entity_decode($text));
|
242 |
}
|
243 |
|
244 |
/**
|
245 |
+
* encode for JavaScript string
|
246 |
+
* @param string $text
|
247 |
+
* @return string
|
248 |
+
*/
|
249 |
+
private static function str2js($text) {
|
250 |
+
return addcslashes($text, "\\/\'\"&\n\r<>");
|
251 |
}
|
252 |
}
|
flexible-map.js
CHANGED
@@ -16,6 +16,7 @@ function FlexibleMap() {
|
|
16 |
this.markerLink = ''; // link for marker title
|
17 |
this.markerShowInfo = true; // if have infowin for marker, show it immediately
|
18 |
this.markerDirections = false; // show directions link in info window
|
|
|
19 |
this.navigationControlOptions = { style: google.maps.NavigationControlStyle.SMALL };
|
20 |
this.dirService = false;
|
21 |
this.dirPanel = false;
|
@@ -71,7 +72,6 @@ FlexibleMap.prototype = (function() {
|
|
71 |
* @param {String} divID the ID of the div that will contain the map
|
72 |
* @param {Array} centre an array of two integers: [ latitude, longitude ]
|
73 |
* @param {Array} marker an array of two integers: [ latitude, longitude ]
|
74 |
-
* @param {String} title the title for the marker
|
75 |
*/
|
76 |
showMarker: function(divID, centre, marker) {
|
77 |
var map = this.showMap(divID, centre),
|
@@ -155,6 +155,32 @@ FlexibleMap.prototype = (function() {
|
|
155 |
}
|
156 |
},
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
/**
|
159 |
* show a map at specified centre latitude / longitude
|
160 |
* @param {String} divID the ID of the div that will contain the map
|
@@ -220,12 +246,14 @@ FlexibleMap.prototype = (function() {
|
|
220 |
|
221 |
// only process if something was entered to search on
|
222 |
if (/\S/.test(from)) {
|
223 |
-
var
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
229 |
self.dirService.route(request, function(response, status) {
|
230 |
var DirectionsStatus = google.maps.DirectionsStatus;
|
231 |
|
16 |
this.markerLink = ''; // link for marker title
|
17 |
this.markerShowInfo = true; // if have infowin for marker, show it immediately
|
18 |
this.markerDirections = false; // show directions link in info window
|
19 |
+
this.markerAddress = ''; // address of marker, if given
|
20 |
this.navigationControlOptions = { style: google.maps.NavigationControlStyle.SMALL };
|
21 |
this.dirService = false;
|
22 |
this.dirPanel = false;
|
72 |
* @param {String} divID the ID of the div that will contain the map
|
73 |
* @param {Array} centre an array of two integers: [ latitude, longitude ]
|
74 |
* @param {Array} marker an array of two integers: [ latitude, longitude ]
|
|
|
75 |
*/
|
76 |
showMarker: function(divID, centre, marker) {
|
77 |
var map = this.showMap(divID, centre),
|
155 |
}
|
156 |
},
|
157 |
|
158 |
+
/**
|
159 |
+
* show a map centred at address
|
160 |
+
* @param {String} divID the ID of the div that will contain the map
|
161 |
+
* @param {String} address the address (should return a unique location in Google Maps!)
|
162 |
+
*/
|
163 |
+
showAddress: function(divID, address) {
|
164 |
+
var self = this,
|
165 |
+
geocoder = new google.maps.Geocoder();
|
166 |
+
|
167 |
+
this.markerAddress = address;
|
168 |
+
|
169 |
+
if (this.markerTitle == "")
|
170 |
+
this.markerTitle = address;
|
171 |
+
|
172 |
+
geocoder.geocode({address: address}, function(results, status) {
|
173 |
+
if (status == google.maps.GeocoderStatus.OK) {
|
174 |
+
var location = results[0].geometry.location,
|
175 |
+
centre = [ location.Oa, location.Pa ];
|
176 |
+
self.showMarker(divID, centre, centre);
|
177 |
+
}
|
178 |
+
else {
|
179 |
+
alert("Map address returns error: " + status);
|
180 |
+
}
|
181 |
+
});
|
182 |
+
},
|
183 |
+
|
184 |
/**
|
185 |
* show a map at specified centre latitude / longitude
|
186 |
* @param {String} divID the ID of the div that will contain the map
|
246 |
|
247 |
// only process if something was entered to search on
|
248 |
if (/\S/.test(from)) {
|
249 |
+
var dest = (self.markerAddress == "") ? new google.maps.LatLng(latitude, longitude) : self.markerAddress,
|
250 |
+
request = {
|
251 |
+
origin: from,
|
252 |
+
region: region,
|
253 |
+
destination: dest,
|
254 |
+
travelMode: google.maps.DirectionsTravelMode.DRIVING
|
255 |
+
};
|
256 |
+
|
257 |
self.dirService.route(request, function(response, status) {
|
258 |
var DirectionsStatus = google.maps.DirectionsStatus;
|
259 |
|
flexible-map.min.js
CHANGED
@@ -2,4 +2,4 @@
|
|
2 |
JavaScript for the WordPress plugin wp-flexible-map
|
3 |
copyright (c) 2011-2012 WebAware Pty Ltd, released under LGPL v2.1
|
4 |
*/
|
5 |
-
function FlexibleMap(){this.mapTypeId=google.maps.MapTypeId.ROADMAP;this.mapTypeControl=false;this.scaleControl=false;this.streetViewControl=false;this.scrollwheel=false;this.zoom=16;this.markerTitle="";this.markerDescription="";this.markerLink="";this.markerShowInfo=true;this.markerDirections=false;this.navigationControlOptions={style:google.maps.NavigationControlStyle.SMALL};this.dirService=false;this.dirPanel=false;this.region=false}FlexibleMap.prototype=(function(){var b,a;if(document.addEventListener){b=function(d,c,e){d.addEventListener(c,e,false)};a=function(c){c.stopPropagation();c.preventDefault()}}else{if(document.attachEvent){b=function(c,d,e){c.attachEvent("on"+d,function(){e.call(c,window.event)})};a=function(c){c.cancelBubble=true;c.returnValue=0}}}return{constructor:FlexibleMap,showKML:function(c,g,d){var f=this.showMap(c,[0,0]),e=new google.maps.KmlLayer(g);e.setMap(f);if(typeof d!="undefined"){google.maps.event.addListenerOnce(f,"tilesloaded",function(){f.setZoom(d)})}google.maps.event.addListener(e,"click",function(h){h.featureData.description=h.featureData.description.replace(/ target="_blank"/ig,"")})},showMarker:function(f,e,k){var d=this.showMap(f,e),n=new google.maps.Marker({map:d,position:new google.maps.LatLng(k[0],k[1])});if(this.markerTitle){var j,l,p,g,h,m,o=this,c=document.createElement("DIV");c.style.fontFamily="Arial,Helvetica,sans-serif";h=document.createElement("DIV");h.style.fontWeight="bold";h.style.fontSize="medium";h.appendChild(document.createTextNode(this.markerTitle));c.appendChild(h);if(this.markerDescription||this.markerLink){h=document.createElement("DIV");h.style.fontSize="small";if(this.markerDescription){p=this.markerDescription.split("\n");for(j=0,l=p.length;j<l;j++){if(j>0){h.appendChild(document.createElement("BR"))}h.appendChild(document.createTextNode(p[j]))}if(this.markerLink){h.appendChild(document.createElement("BR"))}}if(this.markerLink){m=document.createElement("A");m.href=this.markerLink;m.appendChild(document.createTextNode("Click for details"));h.appendChild(m)}c.appendChild(h)}if(this.markerDirections){h=document.createElement("DIV");h.style.fontSize="small";m=document.createElement("A");m.href="#";m.dataLatitude=k[0];m.dataLongitude=k[1];m.dataTitle=this.markerTitle;b(m,"click",function(i){a(i);o.showDirections(this.dataLatitude,this.dataLongitude,this.dataTitle)});m.appendChild(document.createTextNode("Directions"));h.appendChild(m);c.appendChild(h);if(!this.dirService){this.dirService=new google.maps.DirectionsService()}if(!this.dirPanel){this.dirPanel=new google.maps.DirectionsRenderer({map:d,panel:document.getElementById(this.markerDirections)})}}g=new google.maps.InfoWindow({content:c});if(this.markerShowInfo){g.open(d,n)}google.maps.event.addListener(n,"click",function(){g.open(d,n)})}},showMap:function(c,d){return new google.maps.Map(document.getElementById(c),{mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,scrollwheel:this.scrollwheel,streetViewControl:this.streetViewControl,navigationControlOptions:this.navigationControlOptions,center:new google.maps.LatLng(d[0],d[1]),zoom:this.zoom})},showDirections:function(g,c,i){var d=document.getElementById(this.markerDirections),f=document.createElement("form"),l=this,h=this.region||"",j,e,k;while(!!(e=d.lastChild)){d.removeChild(e)}e=document.createElement("p");e.appendChild(document.createTextNode("From: "));k=document.createElement("input");k.type="text";k.name="from";e.appendChild(k);j=document.createElement("input");j.type="submit";j.value="Get directions";e.appendChild(j);f.appendChild(e);d.appendChild(f);k.focus();if(typeof f.elements.from=="undefined"){f.elements.from=k}b(f,"submit",function(
|
2 |
JavaScript for the WordPress plugin wp-flexible-map
|
3 |
copyright (c) 2011-2012 WebAware Pty Ltd, released under LGPL v2.1
|
4 |
*/
|
5 |
+
function FlexibleMap(){this.mapTypeId=google.maps.MapTypeId.ROADMAP;this.mapTypeControl=false;this.scaleControl=false;this.streetViewControl=false;this.scrollwheel=false;this.zoom=16;this.markerTitle="";this.markerDescription="";this.markerLink="";this.markerShowInfo=true;this.markerDirections=false;this.markerAddress="";this.navigationControlOptions={style:google.maps.NavigationControlStyle.SMALL};this.dirService=false;this.dirPanel=false;this.region=false}FlexibleMap.prototype=(function(){var b,a;if(document.addEventListener){b=function(d,c,e){d.addEventListener(c,e,false)};a=function(c){c.stopPropagation();c.preventDefault()}}else{if(document.attachEvent){b=function(c,d,e){c.attachEvent("on"+d,function(){e.call(c,window.event)})};a=function(c){c.cancelBubble=true;c.returnValue=0}}}return{constructor:FlexibleMap,showKML:function(c,g,d){var f=this.showMap(c,[0,0]),e=new google.maps.KmlLayer(g);e.setMap(f);if(typeof d!="undefined"){google.maps.event.addListenerOnce(f,"tilesloaded",function(){f.setZoom(d)})}google.maps.event.addListener(e,"click",function(h){h.featureData.description=h.featureData.description.replace(/ target="_blank"/ig,"")})},showMarker:function(f,e,k){var d=this.showMap(f,e),n=new google.maps.Marker({map:d,position:new google.maps.LatLng(k[0],k[1])});if(this.markerTitle){var j,l,p,g,h,m,o=this,c=document.createElement("DIV");c.style.fontFamily="Arial,Helvetica,sans-serif";h=document.createElement("DIV");h.style.fontWeight="bold";h.style.fontSize="medium";h.appendChild(document.createTextNode(this.markerTitle));c.appendChild(h);if(this.markerDescription||this.markerLink){h=document.createElement("DIV");h.style.fontSize="small";if(this.markerDescription){p=this.markerDescription.split("\n");for(j=0,l=p.length;j<l;j++){if(j>0){h.appendChild(document.createElement("BR"))}h.appendChild(document.createTextNode(p[j]))}if(this.markerLink){h.appendChild(document.createElement("BR"))}}if(this.markerLink){m=document.createElement("A");m.href=this.markerLink;m.appendChild(document.createTextNode("Click for details"));h.appendChild(m)}c.appendChild(h)}if(this.markerDirections){h=document.createElement("DIV");h.style.fontSize="small";m=document.createElement("A");m.href="#";m.dataLatitude=k[0];m.dataLongitude=k[1];m.dataTitle=this.markerTitle;b(m,"click",function(i){a(i);o.showDirections(this.dataLatitude,this.dataLongitude,this.dataTitle)});m.appendChild(document.createTextNode("Directions"));h.appendChild(m);c.appendChild(h);if(!this.dirService){this.dirService=new google.maps.DirectionsService()}if(!this.dirPanel){this.dirPanel=new google.maps.DirectionsRenderer({map:d,panel:document.getElementById(this.markerDirections)})}}g=new google.maps.InfoWindow({content:c});if(this.markerShowInfo){g.open(d,n)}google.maps.event.addListener(n,"click",function(){g.open(d,n)})}},showAddress:function(c,d){var e=this,f=new google.maps.Geocoder();this.markerAddress=d;if(this.markerTitle==""){this.markerTitle=d}f.geocode({address:d},function(i,h){if(h==google.maps.GeocoderStatus.OK){var g=i[0].geometry.location,j=[g.Oa,g.Pa];e.showMarker(c,j,j)}else{alert("Map address returns error: "+h)}})},showMap:function(c,d){return new google.maps.Map(document.getElementById(c),{mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,scrollwheel:this.scrollwheel,streetViewControl:this.streetViewControl,navigationControlOptions:this.navigationControlOptions,center:new google.maps.LatLng(d[0],d[1]),zoom:this.zoom})},showDirections:function(g,c,i){var d=document.getElementById(this.markerDirections),f=document.createElement("form"),l=this,h=this.region||"",j,e,k;while(!!(e=d.lastChild)){d.removeChild(e)}e=document.createElement("p");e.appendChild(document.createTextNode("From: "));k=document.createElement("input");k.type="text";k.name="from";e.appendChild(k);j=document.createElement("input");j.type="submit";j.value="Get directions";e.appendChild(j);f.appendChild(e);d.appendChild(f);k.focus();if(typeof f.elements.from=="undefined"){f.elements.from=k}b(f,"submit",function(o){a(o);var p=this.elements.from.value;if(/\S/.test(p)){var m=(l.markerAddress=="")?new google.maps.LatLng(g,c):l.markerAddress,n={origin:p,region:h,destination:m,travelMode:google.maps.DirectionsTravelMode.DRIVING};l.dirService.route(n,function(s,q){var r=google.maps.DirectionsStatus;switch(q){case r.OK:l.dirPanel.setDirections(s);break;case r.ZERO_RESULTS:alert("No route could be found between the origin and destination.");break;case r.OVER_QUERY_LIMIT:alert("The webpage has gone over the requests limit in too short a period of time.");break;case r.REQUEST_DENIED:alert("The webpage is not allowed to use the directions service.");break;case r.INVALID_REQUEST:alert("Invalid directions request.");break;case r.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}})}})}}})();
|
flexible-map.php
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
/*
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: http://snippets.webaware.com.au/wordpress-plugins/wp-flexible-map/
|
5 |
-
Description:
|
6 |
-
Version: 1.0.
|
7 |
-
Author: WebAware
|
8 |
Author URI: http://www.webaware.com.au/
|
9 |
*/
|
10 |
|
@@ -34,12 +34,10 @@ if (!defined('FLXMAP_PLUGIN_ROOT')) {
|
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
* @param string $class_name name of class to attempt to load
|
42 |
-
*/
|
43 |
function flxmap_autoload($class_name) {
|
44 |
static $classMap = array (
|
45 |
'FlxMapAdmin' => 'class.FlxMapAdmin.php',
|
2 |
/*
|
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.0.2
|
7 |
+
Author: WebAware
|
8 |
Author URI: http://www.webaware.com.au/
|
9 |
*/
|
10 |
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
+
* autoload classes as/when needed
|
38 |
+
*
|
39 |
+
* @param string $class_name name of class to attempt to load
|
40 |
+
*/
|
|
|
|
|
41 |
function flxmap_autoload($class_name) {
|
42 |
static $classMap = array (
|
43 |
'FlxMapAdmin' => 'class.FlxMapAdmin.php',
|
instructions.html
CHANGED
@@ -63,3 +63,22 @@
|
|
63 |
<dt>Sample:</dt>
|
64 |
<dd><code>[flexiblemap src="http://code.google.com/apis/kml/documentation/KML_Samples.kml" width="500" height="400"]</code></dd>
|
65 |
</dl>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
<dt>Sample:</dt>
|
64 |
<dd><code>[flexiblemap src="http://code.google.com/apis/kml/documentation/KML_Samples.kml" width="500" height="400"]</code></dd>
|
65 |
</dl>
|
66 |
+
|
67 |
+
<hr />
|
68 |
+
|
69 |
+
<h3>Calling from templates or plugins</h3>
|
70 |
+
|
71 |
+
<p>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.</p>
|
72 |
+
|
73 |
+
<dl class="flxmap-instructions-parameters">
|
74 |
+
<dt>Sample:</dt>
|
75 |
+
<dd><pre><code>flexmap_show_map(array(
|
76 |
+
'center' => '-34.916721,138.828878',
|
77 |
+
'width' => 500,
|
78 |
+
'height' => 400,
|
79 |
+
'zoom' => 12,
|
80 |
+
'title' => 'Adelaide Hills',
|
81 |
+
'description' => 'The Adelaide Hills are repleat with wineries.',
|
82 |
+
'directions' => 'my-dir-div',
|
83 |
+
));</code></pre></dd>
|
84 |
+
</dl>
|
readme.txt
CHANGED
@@ -6,9 +6,9 @@ Author URI: http://www.webaware.com.au/
|
|
6 |
Tags: google, maps, shortcode, kml
|
7 |
Requires at least: 3.0.1
|
8 |
Tested up to: 3.3.1
|
9 |
-
Stable tag: 1.0.
|
10 |
|
11 |
-
|
12 |
|
13 |
== Description ==
|
14 |
|
@@ -16,8 +16,10 @@ Flexible Map allows you to add Google Maps to your WordPress website.
|
|
16 |
|
17 |
**Features:**
|
18 |
|
19 |
-
*
|
20 |
-
*
|
|
|
|
|
21 |
* no special Google Maps key is required -- uses the latest stable Google Maps API
|
22 |
* simple shortcode for adding maps to pages/posts
|
23 |
* PHP function `flexmap_show_map()` for theme and plugin developers
|
@@ -27,59 +29,57 @@ Flexible Map allows you to add Google Maps to your WordPress website.
|
|
27 |
* optional directions link for info window
|
28 |
* directions can be dropped into any div element with an ID
|
29 |
|
|
|
|
|
30 |
== Installation ==
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
*
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
* *
|
49 |
-
|
50 |
-
* *
|
51 |
-
|
52 |
-
* *
|
53 |
-
|
54 |
-
* *
|
55 |
-
|
56 |
-
* *
|
57 |
-
|
|
|
58 |
|
59 |
*Samples*:
|
60 |
`[flexiblemap center="-34.916721,138.828878" width="500" height="400" zoom="9" title="Adelaide Hills" description="The Adelaide Hills are repleat with wineries."]
|
|
|
61 |
[flexiblemap center="-34.916721,138.828878" width="500" height="400" title="Adelaide Hills" directions="true"]
|
62 |
[flexiblemap center="-34.916721,138.828878" width="500" height="400" title="Adelaide Hills" directions="my-dir-div"]`
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
* *width*
|
67 |
-
|
68 |
-
* *
|
69 |
-
|
70 |
-
* *
|
71 |
-
|
72 |
-
* *zoom*
|
73 |
-
* zoom level as an integer, larger is closer, e.g. *zoom="16"*
|
74 |
-
* *maptype*
|
75 |
-
* type of map to show, from [roadmap, satellite], e.g. *maptype="roadmap"*
|
76 |
-
* *hideMapType*
|
77 |
-
* hide the map type controls, from [true, false], e.g. *hideMapType="true"*
|
78 |
|
79 |
*Sample*:
|
80 |
`[flexiblemap src="http://code.google.com/apis/kml/documentation/KML_Samples.kml" width="500" height="400"]`
|
81 |
|
82 |
-
|
83 |
|
84 |
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.
|
85 |
|
@@ -94,10 +94,30 @@ There is a PHP function `flexmap_show_map()` for theme and plugin developers. Al
|
|
94 |
'directions' => 'my-dir-div',
|
95 |
));`
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
== Changelog ==
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
= 1.0.1 [2012-01-26] =
|
100 |
-
*
|
101 |
|
102 |
= 1.0.0 [2012-01-08] =
|
103 |
* final cleanup for public release
|
6 |
Tags: google, maps, shortcode, kml
|
7 |
Requires at least: 3.0.1
|
8 |
Tested up to: 3.3.1
|
9 |
+
Stable tag: 1.0.2
|
10 |
|
11 |
+
Embed Google Maps in pages and posts, either by centre coodinates or street address, or by URL to a Google Earth KML file.
|
12 |
|
13 |
== Description ==
|
14 |
|
16 |
|
17 |
**Features:**
|
18 |
|
19 |
+
* three ways to load a map:
|
20 |
+
* by centre coordinates
|
21 |
+
* by street address
|
22 |
+
* by URL to a Google Earth KML file
|
23 |
* no special Google Maps key is required -- uses the latest stable Google Maps API
|
24 |
* simple shortcode for adding maps to pages/posts
|
25 |
* PHP function `flexmap_show_map()` for theme and plugin developers
|
29 |
* optional directions link for info window
|
30 |
* directions can be dropped into any div element with an ID
|
31 |
|
32 |
+
Click to see [WP Flexible Map in action](http://snippets.webaware.com.au/wordpress-plugins/wp-flexible-map/).
|
33 |
+
|
34 |
== Installation ==
|
35 |
|
36 |
+
1. Upload this plugin to your /wp-content/plugins/ directory.
|
37 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
38 |
+
3. Add the shortcode [flexiblemap] to your pages / posts to embed maps
|
39 |
+
|
40 |
+
There are two ways to load maps with this plugin:
|
41 |
+
|
42 |
+
* specify the map's coordinates or street address
|
43 |
+
* specify the URL to a KML file (e.g. from Google Earth)
|
44 |
+
|
45 |
+
To add a Flexible Map to a post or a page, add a shortcode [flexiblemap] and give it some useful parameters. A map can either be specified using centre coordinates or street address, or by loading a KML file.
|
46 |
+
|
47 |
+
= Parameters for centre coordinates or street address map =
|
48 |
+
|
49 |
+
Either the center or the address paramater is required. If you provide both, the centre coordinates will be used for the map centre, but directions will use the street address. (This will prevent directions from telling people how to get to the destination opposite yours!)
|
50 |
+
|
51 |
+
* **width**: width in pixels, e.g. *width="500"*
|
52 |
+
* **height**: height in pixels, e.g. *height="400"*
|
53 |
+
* **center**: coordinates of centre in latitude,longitude, e.g. *center="-34.916721,138.828878"*
|
54 |
+
* **address**: street address of map centre, e.g. *address="116 Beaumont Street Hamilton NSW Australia"*
|
55 |
+
* **marker**: coordinates of the marker if different from the centre, in latitude,longitude, e.g. *marker="-34.916721,138.828878"*
|
56 |
+
* **title**: title of the marker, displayed in a text bubble, e.g. *title="Adelaide Hills"*
|
57 |
+
* **link**: URL to link from the marker title, e.g. *link="http://example.com/"*
|
58 |
+
* **description**: a description of the marker location (can have HTML links), e.g. *description="Lorem ipsum dolor sit amet"*
|
59 |
+
* **directions**: show directions link in text bubble; by default, directions will be displayed underneath map, but you can specify the element ID for directions here.
|
60 |
+
* **zoom**: zoom level as an integer, larger is closer, e.g. *zoom="16"*
|
61 |
+
* **maptype**: type of map to show, from [roadmap, satellite], e.g. *maptype="roadmap"*
|
62 |
+
* **hideMapType**: hide the map type controls, from [true, false], e.g. *hideMapType="true"*
|
63 |
|
64 |
*Samples*:
|
65 |
`[flexiblemap center="-34.916721,138.828878" width="500" height="400" zoom="9" title="Adelaide Hills" description="The Adelaide Hills are repleat with wineries."]
|
66 |
+
[flexiblemap address="116 Beaumont Street Hamilton NSW Australia" width="500" height="400" directions="true"]
|
67 |
[flexiblemap center="-34.916721,138.828878" width="500" height="400" title="Adelaide Hills" directions="true"]
|
68 |
[flexiblemap center="-34.916721,138.828878" width="500" height="400" title="Adelaide Hills" directions="my-dir-div"]`
|
69 |
|
70 |
+
= Parameters for KML map =
|
71 |
+
|
72 |
+
* **width**: width in pixels, e.g. *width="500"*
|
73 |
+
* **height**: height in pixels, e.g. *height="400"*
|
74 |
+
* **src**: the URL for a KML file to load map details from, e.g. *src="http://example.com/map.kml"*
|
75 |
+
* **zoom**: zoom level as an integer, larger is closer, e.g. *zoom="16"*
|
76 |
+
* **maptype**: type of map to show, from [roadmap, satellite], e.g. *maptype="roadmap"*
|
77 |
+
* **hideMapType**: hide the map type controls, from [true, false], e.g. *hideMapType="true"*
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
*Sample*:
|
80 |
`[flexiblemap src="http://code.google.com/apis/kml/documentation/KML_Samples.kml" width="500" height="400"]`
|
81 |
|
82 |
+
= Calling from templates or plugins =
|
83 |
|
84 |
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.
|
85 |
|
94 |
'directions' => 'my-dir-div',
|
95 |
));`
|
96 |
|
97 |
+
== Frequently Asked Questions ==
|
98 |
+
|
99 |
+
= Can I add multiple markers to a map? =
|
100 |
+
|
101 |
+
Using a KML file, you can have as many markers on a map as you like, with as much detail in the info windows. With KML you can also change marker icons and add other nice features. You can create your KML file in an application like Google Earth, or you can create it yourself (in a text editor or with your own programming). [Learn more about KML](http://code.google.com/apis/kml/).
|
102 |
+
|
103 |
+
= Why won't the map show my place when I use the address parameter? =
|
104 |
+
|
105 |
+
When you use a street address instead of centre coordinates, you are effectively searching Google Maps for your location. Try being very specific about your address, including your town / city, state / province, and country to make sure Google can find where you mean. If the marker is still in the wrong place, you might need to specify the location using centre coordinates instead.
|
106 |
+
|
107 |
+
= How can I use centre coordinates for the map and have directions to my address? =
|
108 |
+
|
109 |
+
When you use just centre coordinates for your map, the directions may send people to the location *opposite* your location! Yes, I know... anyway, if you specify both the centre coordinates and the street address, the map will be centred correctly and the directions will be to your address.
|
110 |
+
|
111 |
== Changelog ==
|
112 |
|
113 |
+
= 1.0.2 [2012-02-04] =
|
114 |
+
* added: address parameter as alternative to center coordinates
|
115 |
+
* added: use address parameter for directions, if given (so that directions match address)
|
116 |
+
* changed: readme improved a little
|
117 |
+
* changed: refactored code for DRY (don't repeat yourself)
|
118 |
+
|
119 |
= 1.0.1 [2012-01-26] =
|
120 |
+
* fixed: directions bugs in JavaScript for Opera, IE
|
121 |
|
122 |
= 1.0.0 [2012-01-08] =
|
123 |
* final cleanup for public release
|