Extension:Semantic Google Maps/Semantic Maps

setFunctionHook( 'insert_map', 'wfInsert_MapFunction_Render' ); global $sfgFormPrinter; if ($sfgFormPrinter) { $sfgFormPrinter->setInputTypeHook('coordinatesmap', 'SF_coordinatesmap_html', array); } } 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; if (!$wgGoogleMapsOnThisPage) {$wgGoogleMapsOnThisPage = 0;} $wgGoogleMapsOnThisPage++;

$lat = sm_returnlatlon('lat',$coordinates); $lon = sm_returnlatlon('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_returnlatlon($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; }

// the function that outputs the custom form html function SF_coordinatesmap_html($cur_value, $input_name, $is_mandatory, $is_disabled, $field_args) {

global $gTabIndex, $gDisabledText, $wgJsMimeType, $wgGoogleMapsKey, $wgGoogleMapsOnThisPage;

if ($coordinates) { // can show up here either as an array or a string, depending on     // whether it came from user input or a wiki page if (is_array($coordinates)) { $flat = 666; // todo if relevant $flon = 666; } else { $flat = sm_returnlatlon('lat',$coordinates); $flon = sm_returnlatlon('lon',$coordinates); }   }		if (!$wgGoogleMapsOnThisPage) {$wgGoogleMapsOnThisPage = 0;} $wgGoogleMapsOnThisPage++; $width = '200'; $height = '200'; $class = 'sm_map'; $zoom = '16'; $type = 'G_HYBRID_MAP'; $controls = 'GSmallMapControl'; if ($flat == 0) { $lat = '50';} else {$lat = $flat;} if ($flon == 0) { $lon = '5';} else {$lon = $flon;}

// input field $text .= ' ' . "\n"; $info_id = "info_$gTabIndex"; $text .= "	 "; // map div $text .= ' ';

//geocoder html $text .= '  Lookup coordinates ';		// map javascript $text .= ' '; $text .= " function showAddress(address) {	makeMap{$wgGoogleMapsOnThisPage};	if (geocoder) {       geocoder.getLatLng(          address,          function(point) {            if (!point) {              alert(address + \" not found\");            } else {				map.clearOverlays				map.setCenter(point, 14);           	 	var marker = new GMarker(point);  		    	map.addOverlay(marker);				document.getElementById(\"input_" . $gTabIndex . "\").value = convertLatToDMS(point.y)+', '+convertLngToDMS(point.x);          }          }        );      }    }		function convertLatToDMS (val) {  if (val < 0) {    return Math.abs(val) + \"\u00B0 \" + \"S\";  } else {    return Math.abs(val) + \"\u00B0 \" + \"N\";  } }

function convertLngToDMS (val) { if (val < 0) { return Math.abs(val) + \"\u00B0 \" + \"W\"; } else { return Math.abs(val) + \"\u00B0 \" + \"E\"; } } function addLoadEvent(func) { var oldonload = window.onload;  if (typeof oldonload == 'function') {  window.onload = function {  oldonload;  func;  };  } else {  window.onload = func;  }  }  window.unload = GUnload; ";		$text .= " function makeMap{$wgGoogleMapsOnThisPage} { if (GBrowserIsCompatible) {window.map = new GMap2(document.getElementById(\"sm_map{$wgGoogleMapsOnThisPage}\")); geocoder = new GClientGeocoder; 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); GEvent.addListener(map, \"click\", function(overlay, point) {      place = null;      if (overlay) {	map.removeOverlay (overlay);      } else {        var marker = new GMarker (point);        map.clearOverlays;        document.getElementById(\"input_". $gTabIndex. "\").value = convertLatToDMS(point.y)+', '+convertLngToDMS(point.x);     map.addOverlay(marker);        map.panTo(point);      }    });  } else { document.write('should show map'); } } addLoadEvent(makeMap{$wgGoogleMapsOnThisPage}); ";    $output = array($text,'');	    return $output;

} // end function SF_coordinatesmap_html

?>