http://www.mediawiki.org/wiki/Special:Code/MediaWiki/59745
Revision: 59745 Author: jeroendedauw Date: 2009-12-04 21:01:11 +0000 (Fri, 04 Dec 2009) Log Message: ----------- Changes for 0.5. http://www.mediawiki.org/wiki/Extension:Semantic_Maps/Future#Semantic_Maps_0.5 Modified Paths: -------------- trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php trunk/extensions/SemanticMaps/SM_Settings.php trunk/extensions/SemanticMaps/SemanticMaps.php Removed Paths: ------------- trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php Deleted: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php =================================================================== --- trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -1,61 +0,0 @@ -<?php - -/** - * Factory method for form input handling classes - * - * @file SM_FormInputFactory.php - * @ingroup SemanticMaps - * - * @author Jeroen De Dauw - */ - -if( !defined( 'MEDIAWIKI' ) ) { - die( 'Not an entry point.' ); -} - -class SMFormInputFactory { - - public static function getFormInputHtml() { - global $egMapsServices; - - // If service_name is set, use this value, and ignore any given - // service parameters - // This will prevent ..input type=googlemaps|service=yahoo.. from - // showing up as a Yahoo! Maps map - if (array_key_exists('service_name', $field_args)) { - $service_name = $field_args['service_name']; - } - elseif (array_key_exists('service', $field_args)) { - $service_name = $field_args['service']; - } - else{ - $service_name = null; - } - - $service_name = MapsMapper::getValidService($service_name, 'fi'); - - $formInput = self::getFormInputInstance(); - - // Get and return the form input HTML from the hook corresponding with the provided service - return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args); - } - - private static function getFormInputInstance($serviceName) { - return new $egMapsServices[$service_name]['fi']['class'](); - } - -} - -/** - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service. - * - * @param unknown_type $coordinates - * @param unknown_type $input_name - * @param unknown_type $is_mandatory - * @param unknown_type $is_disabled - * @param array $field_args - * @return unknown - */ -function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) { - -} \ No newline at end of file Modified: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php =================================================================== --- trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -39,7 +39,7 @@ $hasFormInputs = true; // Add the result form input type for the service name. - self::initFormHook($serviceName, $serviceData['fi']); + self::initFormHook($serviceName, $serviceData['fi'], $serviceName); // Loop through the service alliases, and add them as form input types. foreach ($serviceData['aliases'] as $alias) self::initFormHook($alias, $serviceData['fi'], $serviceName); @@ -52,8 +52,8 @@ } private static function initializeParams() { - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; - + global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; + self::$parameters = array( 'centre' => array( 'aliases' => array('center'), @@ -65,7 +65,7 @@ 'criteria' => array( 'in_array' => $egMapsAvailableServices ), - 'default' => $egMapsDefaultService + 'default' => $egMapsDefaultServices['fi'] ), 'geoservice' => array( 'aliases' => array(), @@ -73,7 +73,7 @@ 'in_array' => array_keys($egMapsAvailableGeoServices) ), 'default' => $egMapsDefaultGeoService - ), + ), 'service_name' => array('default' => ''), 'part_of_multiple' => array('default' => ''), 'possible_values' => array('default' => ''), @@ -84,13 +84,13 @@ } /** - * Adds a mapping service's form hook + * Adds a mapping service's form hook. * - * @param string $service + * @param string $inputName The name of the form input. * @param array $fi * @param strig $mainName */ - private static function initFormHook($service, array $fi = null, $mainName = '') { + private static function initFormHook($inputName, array $fi = null, $mainName = '') { global $wgAutoloadClasses, $sfgFormPrinter, $smgIP; if (isset($fi)) { @@ -103,13 +103,13 @@ // Add the form input hook for the service $field_args = array(); if (strlen($mainName) > 0) $field_args['service_name'] = $mainName; - $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args); + $sfgFormPrinter->setInputTypeHook($inputName, 'smfSelectFormInputHTML', $field_args); } } /** - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service. + * Calls the relevant form input class depending on the provided service. * * @param unknown_type $coordinates * @param unknown_type $input_name @@ -122,10 +122,8 @@ function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) { global $egMapsServices; - // If service_name is set, use this value, and ignore any given - // service parameters - // This will prevent ..input type=googlemaps|service=yahoo.. from - // showing up as a Yahoo! Maps map + // If service_name is set, use this value, and ignore any given service parameters. + // This will prevent ..input type=googlemaps|service=yahoo.. from showing up as a Yahoo! Maps map. if (array_key_exists('service_name', $field_args)) { $service_name = $field_args['service_name']; } @@ -137,7 +135,6 @@ } $service_name = MapsMapper::getValidService($service_name, 'fi'); - $formInput = new $egMapsServices[$service_name]['fi']['class'](); // Get and return the form input HTML from the hook corresponding with the provided service Modified: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js =================================================================== --- trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js 2009-12-04 21:01:11 UTC (rev 59745) @@ -87,7 +87,7 @@ } /** - * Remove all markers from an OL map (that's in window.OLMaps), and pplace a new one. + * Remove all markers from an OL map (that's in window.OLMaps), and place a new one. * * @param mapName Name of the map as in OLMaps[mapName]. * @param newLocation The location for the new marker. Modified: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php =================================================================== --- trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -3,15 +3,15 @@ /** * This groupe contains all OpenStreetMap related files of the Semantic Maps extension. * - * @defgroup SMOpenStreetMap OpenStreetMap + * @defgroup SMOSM OpenStreetMap * @ingroup SemanticMaps */ /** * This file holds the general information for the OpenStreetMap service. * - * @file SM_OpenStreetMap.php - * @ingroup SMOpenStreetMap + * @file SM_OSM.php + * @ingroup SMOSM * * @author Jeroen De Dauw */ @@ -21,4 +21,4 @@ } $egMapsServices['osm']['qp'] = array('class' => 'SMOSMQP', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMQP.php', 'local' => false); -// $egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false); \ No newline at end of file +//$egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false); \ No newline at end of file Modified: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php =================================================================== --- trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -40,7 +40,7 @@ global $wgJsMimeType; global $smgScriptPath, $smgOSMFormsOnThisPage, $smgStyleVersion; - MapsOSM::addOLDependencies($this->output); + MapsOSM::addOSMDependencies($this->output); if (empty($smgOSMFormsOnThisPage)) { $smgOSMFormsOnThisPage = 0; @@ -73,9 +73,9 @@ $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); $this->output .= <<<EOT - addOnloadHook(makeOSMFormInput( + <script type='$wgJsMimeType'> + slippymaps['$this->mapName'] = new slippymap_map( '$this->mapName', - '$this->coordsFieldName', { mode: 'osm-wm', layer: 'osm-like', @@ -85,9 +85,11 @@ zoom: $this->zoom, width: $this->width, height: $this->height, - controls: [$controlItems] + controls: [$controlItems], + coordField: '$this->coordsFieldName' } - )); + ); + </script> <div id='$this->mapName' class='map' style='width:{$this->width}px; height:{$this->height}px;'> <script type='$wgJsMimeType'>slippymaps['$this->mapName'].init();</script> Modified: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js =================================================================== --- trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js 2009-12-04 21:01:11 UTC (rev 59745) @@ -0,0 +1,118 @@ + /** + * Javascript functions for OpenStreetMap functionallity in Semantic Maps + * + * @file SM_OSMFunctions.js + * @ingroup SMOSM + * + * @author Jeroen De Dauw + */ + +/** + * This function holds spesific functionallity for the OpenStreetMap form input of Semantic Maps + * TODO: Refactor as much code as possible to non specific functions + */ +function makeOSMFormInput(mapName, locationFieldName, lat, lon, zoom, marker_lat, marker_lon, layers, controls, height) { + var markers = Array(); + + // Show a starting marker only if marker coordinates are provided + if (marker_lat != null && marker_lon != null) { + markers.push(getOSMMarkerData(marker_lon, marker_lat, '', '')); + } + + // Click event handler for updating the location of the marker + // TODO / FIXME: This will probably cause problems when used for multiple maps on one page. + OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { + defaultHandlerOptions: { + 'single': true, + 'double': false, + 'pixelTolerance': 0, + 'stopSingle': false, + 'stopDouble': false + }, + + initialize: function(options) { + this.handlerOptions = OpenLayers.Util.extend( + {}, this.defaultHandlerOptions + ); + OpenLayers.Control.prototype.initialize.apply( + this, arguments + ); + this.handler = new OpenLayers.Handler.Click( + this, { + 'click': this.trigger + }, this.handlerOptions + ); + }, + + trigger: function(e) { + replaceMarker(mapName, map.getLonLatFromViewPortPx(e.xy)); + document.getElementById(locationFieldName).value = convertLatToDMS(map.getLonLatFromViewPortPx(e.xy).lat)+', '+convertLngToDMS(map.getLonLatFromViewPortPx(e.xy).lon); + } + + }); + + var clickHanler = new OpenLayers.Control.Click(); + controls.push(clickHanler); + + var map = initOpenLayer(mapName, lon, lat, zoom, layers, controls, markers, height); + + // Make the map variable available for other functions + if (!window.OSMMaps) window.OSMMaps = new Object; + eval("window.OSMMaps." + mapName + " = map;"); +} + + +/** + * This function holds spesific functionallity for the OpenStreetMap form input of Semantic Maps + * TODO: Refactor as much code as possible to non specific functions + */ +function showOSMAddress(address, mapName, outputElementName, notFoundFormat) { + + var map = OSMMaps[mapName]; + var geocoder = new GClientGeocoder(); + + geocoder.getLatLng(address, + function(point) { + if (!point) { + window.alert(address + ' ' + notFoundFormat); + } else { + var loc = new OpenLayers.LonLat(point.x, point.y); + + replaceMarker(mapName, loc); + document.getElementById(outputElementName).value = convertLatToDMS(point.y) + ', ' + convertLngToDMS(point.x); + } + } + ); + +} + +/** + * Remove all markers from an OSM map (that's in window.OSMMaps), and place a new one. + * + * @param mapName Name of the map as in OSMMaps[mapName]. + * @param newLocation The location for the new marker. + * @return + */ +function replaceMarker(mapName, newLocation) { + var map = OSMMaps[mapName]; + var markerLayer = map.getLayer('markerLayer'); + + removeOSMMarkers(markerLayer); + markerLayer.addMarker(getOSMMarker(markerLayer, getOSMMarkerData(newLocation.lon, newLocation.lat, '', ''), map.getProjectionObject())); + + map.panTo(newLocation); +} + +/** + * Removes all markers from a marker layer. + * + * @param markerLayer The layer to remove all markers from. + * @return + */ +function removeOSMMarkers(markerLayer) { + var markerCollection = markerLayer.markers; + + for (i in markerCollection) { + markerLayer.removeMarker(markerCollection[i]); + } +} \ No newline at end of file Modified: trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php =================================================================== --- trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -48,13 +48,13 @@ } private static function initializeParams() { - global $egMapsDefaultService, $egMapsDefaultCentre; + global $egMapsDefaultServices, $egMapsDefaultCentre; self::$parameters = array( 'format' => array( 'aliases' => array(), 'criteria' => array(), - 'default' => $egMapsDefaultService + 'default' => $egMapsDefaultServices['qp'] ), 'centre' => array( 'aliases' => array('center'), Modified: trunk/extensions/SemanticMaps/SM_Settings.php =================================================================== --- trunk/extensions/SemanticMaps/SM_Settings.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/SM_Settings.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -53,3 +53,11 @@ include_once $smgIP . '/OpenStreetMap/SM_OSM.php'; // OpenLayers optimized for OSM + + + +# Array of String. The default mapping service for each feature, which will be used when no valid service is provided by the user. +# Each service needs to be enabled, if not, the first one from the available services will be taken. +# Note: The default service needs to be available for the feature you set it for, since it's used as a fallback mechanism. +$egMapsDefaultServices['qp'] = 'googlemaps'; +$egMapsDefaultServices['fi'] = 'googlemaps'; Modified: trunk/extensions/SemanticMaps/SemanticMaps.php =================================================================== --- trunk/extensions/SemanticMaps/SemanticMaps.php 2009-12-04 21:00:48 UTC (rev 59744) +++ trunk/extensions/SemanticMaps/SemanticMaps.php 2009-12-04 21:01:11 UTC (rev 59745) @@ -23,26 +23,29 @@ die( 'Not an entry point.' ); } -define('SM_VERSION', '0.5 a15'); - -$smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps'; -$smgIP = $IP . '/extensions/SemanticMaps'; - -$smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION; - -// Include the settings file. -require_once($smgIP . '/SM_Settings.php'); - -$wgExtensionFunctions[] = 'smfSetup'; - -$wgHooks['AdminLinks'][] = 'smfAddToAdminLinks'; - -$wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php'; - -// Registration of the Geographical Coordinate type. -$wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php'; -$wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType'; - +// Only initialize the extension when all dependencies are present. +if (defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' )) { + define('SM_VERSION', '0.5 a18'); + + $smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps'; + $smgIP = $IP . '/extensions/SemanticMaps'; + + $smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION; + + // Include the settings file. + require_once($smgIP . '/SM_Settings.php'); + + $wgExtensionFunctions[] = 'smfSetup'; + + $wgHooks['AdminLinks'][] = 'smfAddToAdminLinks'; + + $wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php'; + + // Registration of the Geographical Coordinate type. + $wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php'; + $wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType'; +} + /** * 'Initialization' function for the Semantic Maps extension. * The only work done here is creating the extension credits for _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs