Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Semantic Maps

, 1 Aug 2009
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
<?php

/**
 * Initialization file for the Maps extension.
 * Extension documentation: http://www.mediawiki.org/wiki/Extension:Maps
 *
 * @file Maps.php
 * @ingroup Maps
 *
 * @author Jeroen De Dauw
 */

if( !defined( 'MEDIAWIKI' ) ) {
	die( 'Not an entry point.' );
}

define('Maps_VERSION', '0.2');

$egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
$egMapsIP = $IP . '/extensions/Maps';
$egMapsIncludePath = 'http://' . $_SERVER["HTTP_HOST"] . $egMapsScriptPath;

// Include the settings file
require_once($egMapsIP . '/Maps_Settings.php');

$wgExtensionFunctions[] = 'efMapsSetup';

$wgExtensionMessagesFiles['Maps'] = $egMapsIP . '/Maps.i18n.php';

$wgHooks['LanguageGetMagic'][] = 'efMapsFunctionMagic';
$wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';

// Autoload the general classes
$wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/Maps_BaseMap.php';
$wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
$wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
$wgAutoloadClasses['MapsGeocoder'] = $egMapsIP . '/Maps_Geocoder.php';
$wgAutoloadClasses['MapsBaseGeocoder'] = $egMapsIP . '/Maps_BaseGeocoder.php';

// Array containing all map services made available by Maps.
// This does not reflect the enabled mapping services, see $egMapsAvailableServices in Maps_Settings.php for this.
// Each array item represents a service: the key is the main service name (used in switch statements),
// and the array values are the aliases for the main name (so can also be used as service=alias).
$egMapsServices = array('googlemaps' => array('google', 'googlemap', 'gmap', 'gmaps'), 
						'openlayers' => array('layers', 'openlayer', 'ol'),
						'yahoomaps'	 => array('yahoo', 'yahoomap', 'ymap', 'ymaps')
						);

/**
 * Initialization function for the Maps extension
 */
function efMapsSetup() {
	global $wgExtensionCredits, $wgExtensionCredits, $wgOut;	
	global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsMainServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices;

	efMapsValidateGoogleMapsKey();
	
	// Make sure the default service is one of the enabled ones
	$egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0];
	$egMapsDefaultGeoService = in_array($egMapsDefaultGeoService, $egMapsAvailableGeoServices) ? $egMapsDefaultGeoService : $egMapsAvailableGeoServices[0];
	
	$egMapsMainServices = array_keys($egMapsServices);
	
	foreach($egMapsMainServices as $service) efMapsInitFormat($service);
	
	$services_list = implode(', ', $egMapsMainServices);

	wfLoadExtensionMessages( 'Maps' );
	
	$wgExtensionCredits['parserhook'][] = array(
		'name' => wfMsg('maps_name'),
		'version' => Maps_VERSION,
		'author' => array("[http://bn2vs.com Jeroen De Dauw]", "[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]", "Robert Buzink", "Matt Williamson", "[http://www.sergeychernyshev.com Sergey Chernyshev]"),
		'url' => 'http://www.mediawiki.org/wiki/Extension:Maps',
		'description' =>  wfMsg('maps_desc') . $services_list
	);

	efMapsAddParserHooks();
	
	$wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js');
}

/**
 * Adds the parser function hooks
 */
function efMapsAddParserHooks() {
	global $wgParser;
	
	// A hook to enable the '#display_point' parser function
	$wgParser->setFunctionHook( 'display_point', array('MapsMapper', 'displayPointRender' ));

	// A hook to enable the '#display_adress' parser function
	$wgParser->setFunctionHook( 'display_address', array('MapsMapper', 'displayAddressRender' ));

	// A hook to enable the geocoder parser functions
	$wgParser->setFunctionHook( 'geocode', array('MapsGeocoder', 'renderGeocoder' ));
	$wgParser->setFunctionHook( 'geocodelat' , array('MapsGeocoder', 'renderGeocoderLat' ));
	$wgParser->setFunctionHook( 'geocodelng' , array('MapsGeocoder', 'renderGeocoderLng' ));
}

/**
 * This function ensures backward compatibility with Semantic Google Maps and other extensions
 * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
 */
function efMapsValidateGoogleMapsKey() {
	global $egGoogleMapsKey, $wgGoogleMapsKey;
	
	if (strlen($egGoogleMapsKey) < 1 && isset($wgGoogleMapsKey)) $egGoogleMapsKey = $wgGoogleMapsKey;
}

/**
 * Initializes the result format depending on the map service
 */
function efMapsInitFormat( $format ) {
	global $wgAutoloadClasses, $egMapsIP;

	switch ($format) {
		case 'googlemaps':
			$class = 'MapsGoogleMaps';
			$file = $egMapsIP . '/GoogleMaps/Maps_GoogleMaps';
		break;
		case 'openlayers':
			$class = 'MapsOpenLayers';
			$file = $egMapsIP . '/OpenLayers/Maps_OpenLayers';
		break;
		case 'yahoomaps':
			$class = 'MapsYahooMaps';
			$file = $egMapsIP . '/YahooMaps/Maps_YahooMaps';
		break;
	}

	if (isset($class) && isset($file)) {
		$wgAutoloadClasses[$class] = $file . '.php';
	}

}

/**
 * Adds the magic words for the parser functions
 */
function efMapsFunctionMagic( &$magicWords, $langCode ) {
	$magicWords['display_point'] = array( 0, 'display_point' );
	$magicWords['display_address'] = array( 0, 'display_address' );

	$magicWords['geocode'] = array( 0, 'geocode' );
	$magicWords['geocodelat']	= array ( 0, 'geocodelat' );
	$magicWords['geocodelng']	= array ( 0, 'geocodelng' );
	
	return true; // Unless we return true, other parser functions won't get loaded
}

/**
 * Adds a link to Admin Links page
 */
function efMapsAddToAdminLinks(&$admin_links_tree) {
	// TODO: move the documentation link to another section - and make it non dependant on SMW?
    $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata'));
    // Escape if SMW hasn't added links
    if (is_null($displaying_data_section))
        return true;
    $smw_docu_row = $displaying_data_section->getRow('smw');
    wfLoadExtensionMessages('Maps');
    $maps_docu_label = wfMsg('adminlinks_documentation', wfMsg('maps_name'));
    $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Maps", $maps_docu_label));
    return true;
}


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)

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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 1 Aug 2009
Article Copyright 2009 by Jeroen De Dauw
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid