Click here to Skip to main content
11,431,483 members (65,216 online)
Click here to Skip to main content
Add your own
alternative version

Semantic Maps

, 1 Aug 2009 GPL3
A MediaWiki extension that allows you to insert, edit, view and aggregate coordinate data
MapsAndSemanticMaps0.2.zip
SemanticMaps
COPYING
GoogleMaps
INSTALL
OpenLayers
README
RELEASE-NOTES
YahooMaps
Maps
COPYING
Geocoders
GoogleMaps
INSTALL
OpenLayers
OpenLayers
img
blank.gif
cloud-popup-relative.png
drag-rectangle-off.png
drag-rectangle-on.png
east-mini.png
layer-switcher-maximize.png
layer-switcher-minimize.png
marker-blue.png
marker-gold.png
marker-green.png
marker.png
measuring-stick-off.png
measuring-stick-on.png
north-mini.png
panning-hand-off.png
panning-hand-on.png
slider.png
south-mini.png
west-mini.png
zoom-minus-mini.png
zoom-plus-mini.png
zoom-world-mini.png
zoombar.png
theme
default
img
add_point_off.png
add_point_on.png
blank.gif
close.gif
drag-rectangle-off.png
drag-rectangle-on.png
draw_line_off.png
draw_line_on.png
draw_point_off.png
draw_point_on.png
draw_polygon_off.png
draw_polygon_on.png
editing_tool_bar.png
move_feature_off.png
move_feature_on.png
navigation_history.png
overview_replacement.gif
pan-panel-NOALPHA.png
pan-panel.png
panning-hand-off.png
panning-hand-on.png
pan_off.png
pan_on.png
remove_point_off.png
remove_point_on.png
ruler.png
save_features_off.png
save_features_on.png
view_next_off.png
view_next_on.png
view_previous_off.png
view_previous_on.png
zoom-panel-NOALPHA.png
zoom-panel.png
OSM
README
RELEASE-NOTES
YahooMaps
 /**
  * Javascript functions for Google Maps functionallity in Maps and it's extensions
  *
  * @file GoogleMapFunctions.js
  * @ingroup Maps
  *
  * @author Robert Buzink
  * @author Yaron Koren   
  * @author Jeroen De Dauw
  */


/**
 * Returns GMarker object on the provided location.
 * It will show a popup baloon with title and label when clicked, if either of these is set.
 */
function createGMarker(point, title, label, icon) {
	var marker;
	
	if (icon != '') {
		var iconObj = new GIcon(G_DEFAULT_ICON);
		iconObj.image = icon;
		marker = new GMarker(point, {icon:iconObj});
	} else {
		marker = new GMarker(point);
	}
	
	if ((title + label).length > 0) {
		var bothTxtAreSet = title.length > 0 && label.length > 0;
		var popupText = bothTxtAreSet ? '<b>' + title + '</b><hr />' + label : title + label;	

		GEvent.addListener(marker, 'click',
			function() {
				marker.openInfoWindowHtml(popupText, {maxWidth:350});
			}
		);		
	}

	return marker;
}

/**
 * Returns GMap2 object with the provided properties and markers.
 */
function initializeGoogleMap(mapName, width, height, lat, lon, zoom, type, control, scrollWheelZoom, earthEnabled, markers) {
	var map;
	
	if (GBrowserIsCompatible()) {
		map = createGoogleMap(document.getElementById(mapName), new GSize(width, height), new GLatLng(lat, lon), zoom, type, control, scrollWheelZoom, earthEnabled);
	
		for (i in markers) {
			var marker = markers[i];
			map.addOverlay(createGMarker(marker.point, marker.title, marker.label, marker.icon));
		}
	}
	
	return map;
}

/**
 * Returns GMap2 object with the provided properties.
 */
function createGoogleMap(mapElement, size, center, zoom, type, control, scrollWheelZoom, earthEnabled) {
	var map = new GMap2(mapElement, {size: size});
	
	if (earthEnabled) map.addMapType(G_SATELLITE_3D_MAP);
	map.addMapType(type);
	
	map.setMapType(type);
	map.setCenter(center, zoom);
	map.addControl(new GMapTypeControl());
	
	if (typeof(control) != 'undefined') map.addControl(control);
	if (scrollWheelZoom) map.enableScrollWheelZoom();
	
	return map;
}

/**
 * This function holds spesific functionallity for the Google Maps form input of Semantic Maps
 * TODO: Refactor as much code as possible to non specific functions
 * TODO: Centralize geocoding functionallity, and use that code instead of local GG
 */
function makeFormInputGoogleMap(mapName, locationFieldName, width, height, lat, lon, zoom, marker_lat, marker_lon, type, control, scrollWheelZoom, earthEnabled) {
	if (GBrowserIsCompatible()) { // TODO: This function should probably be used after the loading of the G Maps API
		var map = createGoogleMap(document.getElementById(mapName), new GSize(width, height), new GLatLng(lat, lon), zoom, type, control, scrollWheelZoom, earthEnabled);

		// Show a starting marker only if marker coordinates are provided
		if (marker_lat != null && marker_lon != null) {
			map.addOverlay(new GMarker(new GLatLng(marker_lat, marker_lon)));
		}
		
		// Click event handler for updating the location of the marker
		GEvent.addListener(map, "click",
			function(overlay, point) {
				if (overlay) {
					map.removeOverlay (overlay);
				} else {
					map.clearOverlays();
					document.getElementById(locationFieldName).value = convertLatToDMS(point.y)+', '+convertLngToDMS(point.x);
					map.addOverlay(new GMarker(point));
					map.panTo(point);
				}
			}
		);
		
		// Make the map variable available for other functions
		if (!window.GMaps) window.GMaps = new Object;
		eval("window.GMaps." + mapName + " = map;"); 
	}
}

/**
 * This function holds spesific functionallity for the Google Maps form input of Semantic Maps
 * TODO: Refactor as much code as possible to non specific functions
 */
function showGAddress(address, mapName, outputElementName, notFoundFormat) {
	var map = GMaps[mapName];
	var geocoder = new GClientGeocoder();

	geocoder.getLatLng(address,
		function(point) {
			if (!point) {
				window.alert(address + ' ' + notFoundFormat);
			} else {
				map.clearOverlays();
				map.setCenter(point);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				document.getElementById(outputElementName).value = convertLatToDMS(point.y) + ', ' + convertLngToDMS(point.x);
			}
		}
	);

}
 
 function getGMarkerData(lat, lon, title, label, icon) {
		return {point: new GLatLng(lat, lon), title: title, label: label, icon: icon};
	}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Jeroen De Dauw
Software Developer
Belgium Belgium
I am a free and open source software enthusiast and freelance software developer with multiple years of experience in both web and desktop development. Currently my primarily focus is on MediaWiki and Semantic MediaWiki work. I'm in the all time top 10 MediaWiki comitters and am one of the WikiWorks consultants. You can contact me at jeroendedauw at gmail for development jobs and questions related to my work.

More info can be found on my website [0] and my blog [1]. You can also follow me on twitter [2] and identi.ca [3].

[0] http://www.jeroendedauw.com/
[1] http://blog.bn2vs.com/
[2] https://twitter.com/#!/JeroenDeDauw
[3] http://identi.ca/jeroendedauw
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 1 Aug 2009
Article Copyright 2009 by Jeroen De Dauw
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid