Extension:Semantic Google Maps/InsertMap.php

This parser function includes a Google Map in a page. Can be used in templates. Accepts template-variables as input. setFunctionHook( 'insert_map', 'wfInsert_MapFunction_Render' ); } function wfInsert_MapFunction_Magic( &$magicWords, $langCode ) { # Add the magic word # The first array element is case sensitive, in this case it is not case sensitive # All remaining elements are synonyms for our parser function $magicWords['insert_map'] = array( 0, 'insert_map' ); # unless we return true, other parser functions extensions won't get loaded. return true; } function wfInsert_MapFunction_Render( &$parser, $coordinates = '1,1', $zoom = '2', $type = 'G_HYBRID_MAP', $controls = 'GSmallMapControl', $class = 'pmap', $width = , $height = , $style = '' ) { # The parser function itself # The input parameters are wikitext with templates expanded # The output is not parsed as wikitext global $wgJsMimeType, $wgGoogleMapsKey; $wgGoogleMapsOnThisPage = 99;
 * 1) Define a setup function
 * 1) Add a hook to initialise the magic word

$lat = sm_ConvertCoord('lat',$coordinates); $lon = sm_ConvertCoord('lon',$coordinates); $output .= ' '; $output .= " function createMarker(point, label) { var marker = new GMarker(point);  GEvent.addListener(marker, 'click', function { marker.openInfoWindowHtml(label); });  return marker;  }  function addLoadEvent(func) {  var oldonload = window.onload;  if (typeof oldonload == 'function') {  window.onload = function {  oldonload;  func;  };  } else {  window.onload = func;  }  }  window.unload = GUnload; "; $output .= ' '; $output .= " function makeMap{$wgGoogleMapsOnThisPage} { if (GBrowserIsCompatible) {var map = new GMap2(document.getElementById(\"map{$wgGoogleMapsOnThisPage}\")); map.addControl(new {$controls}); map.addControl(new GMapTypeControl); map.setCenter(new GLatLng({$lat}, {$lon}), {$zoom}, {$type}); var point = new GLatLng({$lat}, {$lon}); var marker = new GMarker(point); map.addOverlay(marker); } else { document.write('should show map'); } } addLoadEvent(makeMap{$wgGoogleMapsOnThisPage}); "; //$output .= "var map = new GMap2(document.getElementById(\"map{$wgGoogleMapsOnThisPage}\")); map.addControl(new {$controls}); map.addControl(new GMapTypeControl); map.setCenter(new GLatLng({$lat}, {$lon}), {$zoom}, {$type}); "; return array( $output, noparse => true, isHTML => true );

}

function sm_ConvertCoord($param1 = , $param2 =  ) { $coordinates = preg_split("/,/", $param2); switch ($param1) { case 'lat': return sm_convert_coord($coordinates[0]); case 'lon': return sm_convert_coord($coordinates[1]); }		}

function sm_degree2decimal($deg_coord="") { $dpos=strpos($deg_coord,'°'); $mpos=strpos($deg_coord,'‘'); $spos=strpos($deg_coord,'"');	$mlen=(($mpos-$dpos)-1);	$slen=(($spos-$mpos)-1);	$direction=substr(strrev($deg_coord),0,1);	$degrees=substr($deg_coord,0,$dpos);	$minutes=substr($deg_coord,$dpos+1,$mlen);	$seconds=substr($deg_coord,$mpos+1,$slen);	$seconds=($seconds/60);	$minutes=($minutes+$seconds);	$minutes=($minutes/60);	$decimal=($degrees+$minutes);	//South latitudes and West longitudes need to return a negative result	if (($direction=="S") or ($direction=="W")) {		$decimal=$decimal*(-1);	}	return $decimal; }

function sm_decdegree2decimal($deg_coord="") { $direction=substr(strrev($deg_coord),0,1); $decimal=floatval($deg_coord); if (($direction=="S") or ($direction=="W")) { $decimal=$decimal*(-1); }	return $decimal; }

function sm_convert_coord ($deg_coord="") { if (preg_match('/°/', $deg_coord)) { if (preg_match('/"/', $deg_coord)) {			$deg_coord = sm_degree2decimal($deg_coord);		} else { 			$deg_coord = sm_decdegree2decimal($deg_coord);		} 	}	return $deg_coord; }

?>