Usage ------ At a minimum, you must use "(:gmap:)," but to set the latitude and longitude, you will have to use a free geocoder (e.g. http://geocoder.us/). The examples below show how you can add text to a bubble over the marker and destination address that allows the site visitor to find directions to the location. Examples: ~~~~~~~~~ (:gmap lat=38.897639 lon=-77.036583:) "Minimum for pointing to a location." (:gmap lat=38.897639 lon=-77.036583 daddr="1600 Pennsylvania, 22303" msg="Joe's Bar and Grill 1600 Ranch Drive Washington, DC 22223":) "Full example with the destination address and message." (:gmapoint lat=39.01 lon=-77.1:) Variables --------- These are the variables that influence the behavior of the markup. The defaults are recommended for use in the configuration file for your PmWiki Installation. The markup options may be added by the author. Defaults ~~~~~~~~ * $EnableGmapOverviewControl = enables the Google API overview control * $EnableGmapTypeControl = enables the Google API type control * $GmapCtrl = default control size (small|large) defaults to large * $GmapLon = default longitude * $GmapLat = default latitude * $GmapZom = default zoom * $GmapJS (leave blank) * $GmapType = default map type (normal, satellite, hybrid). Markup Options ~~~~~~~~~~~~~~ * ctrl = designates the size of the arrow button control (small|large) * daddr = destination address (which allows directions to the address) * lat = lattitude * lon = longitude * oview = toggles from site default, accepts 'y' or 'n' accordingly. * msg = what text is displayed in the window over the marker. You will have to provide the HTML. * mtype = toggles from site default, accepts 'y' or 'n' accordingly. * type = the map type ('nor'mal, 'hyb'rid, 'sat'ellite) * zom = the zoom level. Release Notes ------------- * v1.0 - May 17, 2006: Initial Public Release by Ben Wilson. * v1.0.1 - May 22, 2006: Release by Ben Wilson. * Incorporated Google Map API v2.0+ compliance corrections by Des. * Replace $GmapCert with $HTMLHeaderFmt call. * Fixed problem with CSS via $HTMLStylesFmt. * Added support for dynamic scaling of controller. * Added the overview map. * Added support for map type (satellite, normal or hybrid). * Only add the directions block when directions are offered. Before, directions were only offered when a message was given. * Only add the message block when the message is offered. * v1.0.2 - May 22, 2005 (pm): Des Corrections * Added map type control buttons * Fixed default operation of map control sizing * Fixed spelling error that prevented the parser selecting the desired map control size. * v1.0.3 - May 23, 2005: Ben Wilson * Added options for height-width of map. * v1.1.0 - May 24, 2005: Ben Wilson * Added multiple point capability. * Added ability to toggle map overview. * Added ability to toggle map type control. */ $MapHtml = "
"; SDV($EnableGmapTypeControl, 1); SDV($EnableGmapOverviewControl, 1); SDV($GmapCtrl, 'large'); SDV($GmapHeight, '400px'); SDV($GmapLon, '-122.141944'); SDV($GmapLat, '37.441944'); SDV($GmapType, 'nor'); SDV($GmapWidth, '100%'); SDV($GmapZom, 8); #-------------------------------- # Internal Variables. Do not monkey with. $CLat = NULL; $CLon = NULL; $GmapE = NULL; $GmapJS = ' '; $GmaMarkers = array(); $GmapN = NULL; $GmaPoints = array(); $GmapS = NULL; $GmapW = NULL; Markup('gmap', 'block', '/\(:gmap(.*?):\)/e', 'Gmap("$1");'); Markup('gmapoint','_begin','/\(:gmapoint(.*?):\)/e','GmaPoint("$1");'); function GmaPoint($i) { global $GmaMarkers, $GmaPoints; $opts = ParseArgs($i); GmapCenterPoint($opts['lat'], $opts['lon']); $c = count($GmaPoints); $p = " var point$c = new GLatLng($opts[lat],$opts[lon]);\n"; $m = " var marker$c = new GMarker(point$c);\n"; $o = " map.addOverlay(marker$c);\n"; list($oput, $w) = GmaDirections($opts, $c); array_push($GmaPoints, array($p, $m, $o, $oput, $w)); return ''; } function GmaDirections($o, $i) { $output = ''; $window = ''; $message = ''; $directions = ''; #-------------------------------- # Check if author wants directions - if so, add the form. $dad = ($o['daddr']) ? $o['daddr'] : $GmapDaddr; if ($dad != '') { $directions =<<',$o['msg']); $o['msg'] = preg_replace('/</','<',$o['msg']); $message = "html$i +='$o[msg]';"; } if ($message != '' or $directions != '') { $output = "var html$i = '';$message$directions"; $window = " marker$i.openInfoWindowHtml(html$i);"; } # - End Handling Message. return array($window, $output); } function Gmap($input='') { global $EnableGmapTypeControl, $EnableGmapOverviewControl; global $GmapLon, $GmapLat, $GmapZom, $GmapJS; global $GmapCtrl, $GmapKey, $GmaPoints, $GmapType; global $GmapHeight, $GmapWidth; global $HTMLHeaderFmt, $HTMLStylesFmt; global $MapHtml, $ScriptHtml; global $GmapN, $GmapS, $GmapE, $GmapW, $CLat, $CLon; $opt = ParseArgs($input); $zom = ($opt['zom']) ? $opt['zom'] : $GmapZom; $lat = ($opt['lat']) ? $opt['lat'] : $GmapLat; $lon = ($opt['lon']) ? $opt['lon'] : $GmapLon; #-------------------------------- # Overview - We add if it's in the default or author requests. $overview = GmapToggle($EnableGmapOverviewControl, $opt['oview'], 'map.addControl(new GOverviewMapControl());'); #-------------------------------- # Control - We add if it's in the default or author requests. $mt_ctrl = GmapToggle($EnableGmapTypeControl, $opt['mtype'], 'map.addControl(new GMapTypeControl());'); #-------------------------------- # Get the Controller Size. v1.0.1 (v.1.0.2 bugfixes by Des $cki = ($opt['ctrl']) ? $opt['ctrl'] : $GmapCtrl; $map_controller_size = (strtolower($cki) == 'large') ? "map.addControl(new GLargeMapControl());" : "map.addControl(new GSmallMapControl());"; #-------------------------------- # Get the Map type. v1.0.1 (inserted in Gmap2.setCenter()) $map_type = array( 'hyb' => 'G_HYBRID_MAP', 'nor' => 'G_NORMAL_MAP', 'sat' => 'G_SATELLITE_MAP', ); $map_type_key = ($opt['type']) ? $opt['type'] : $GmapType; $map_type = $map_type[strtolower(substr($map_type_key,0,3))]; #-------------------------------- # Let's the author change the default size of the map. $height = ($opt['height']) ? $opt['height'] : $GmapHeight; $width = ($opt['width']) ? $opt['width'] : $GmapWidth; if ($lat != '' and $lon != '') GmaPoint("lat='$lat' lon='$lon'"); #-------------------------------- # Build the various points. $c = 0; $markers = ''; $points = ''; $overlays = ''; $windows = ''; $outputs = ''; foreach ($GmaPoints as $p) { list($p, $m, $o, $w, $oput) = $p; $points .= $p; $markers .= $m; $overlays .= $o; $windows .= $w; $outputs .= $oput; } #-------------------------------- # Set the HTML $HTMLStylesFmt['gmap_api'] = "div#map{ height: $height; width:$width;}"; $HTMLHeaderFmt[] = ''; $center = "var center = new GLatLng($CLat,$CLon);\n"; $GmapJS =<< // GMAPJS; return "$MapHtml"; } function GmapToggle($d, $o, $t) { #- $o = y or n, overrides site default if ($o == 'n') return ''; if ($o == 'y') return $t; return ($d) ? $t : ''; } function GmapCenterPoint($lat, $lon) { global $GmapN, $GmapS, $GmapE, $GmapW; global $CLat, $CLon; if ($lat > $GmapN or is_null($GmapN)) $GmapN = $lat; if ($lat < $GmapS or is_null($GmapS)) $GmapS = $lat; if ($lon > $GmapE or is_null($GmapE)) $GmapE = $lon; if ($lon < $GmapW or is_null($GmapW)) $GmapW = $lon; $CLon = ($GmapE + $GmapW)/2; $CLat = ($GmapN + $GmapS)/2; }