Index: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js |
— | — | @@ -87,7 +87,7 @@ |
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | | - * Remove all markers from an OL map (that's in window.OLMaps), and pplace a new one. |
| 91 | + * Remove all markers from an OL map (that's in window.OLMaps), and place a new one. |
92 | 92 | * |
93 | 93 | * @param mapName Name of the map as in OLMaps[mapName]. |
94 | 94 | * @param newLocation The location for the new marker. |
Index: trunk/extensions/SemanticMaps/SM_Settings.php |
— | — | @@ -53,3 +53,11 @@ |
54 | 54 | include_once $smgIP . '/OpenStreetMap/SM_OSM.php'; // OpenLayers optimized for OSM |
55 | 55 | |
56 | 56 | |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +# Array of String. The default mapping service for each feature, which will be used when no valid service is provided by the user. |
| 61 | +# Each service needs to be enabled, if not, the first one from the available services will be taken. |
| 62 | +# Note: The default service needs to be available for the feature you set it for, since it's used as a fallback mechanism. |
| 63 | +$egMapsDefaultServices['qp'] = 'googlemaps'; |
| 64 | +$egMapsDefaultServices['fi'] = 'googlemaps'; |
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php |
— | — | @@ -1,61 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * Factory method for form input handling classes |
6 | | - * |
7 | | - * @file SM_FormInputFactory.php |
8 | | - * @ingroup SemanticMaps |
9 | | - * |
10 | | - * @author Jeroen De Dauw |
11 | | - */ |
12 | | - |
13 | | -if( !defined( 'MEDIAWIKI' ) ) { |
14 | | - die( 'Not an entry point.' ); |
15 | | -} |
16 | | - |
17 | | -class SMFormInputFactory { |
18 | | - |
19 | | - public static function getFormInputHtml() { |
20 | | - global $egMapsServices; |
21 | | - |
22 | | - // If service_name is set, use this value, and ignore any given |
23 | | - // service parameters |
24 | | - // This will prevent ..input type=googlemaps|service=yahoo.. from |
25 | | - // showing up as a Yahoo! Maps map |
26 | | - if (array_key_exists('service_name', $field_args)) { |
27 | | - $service_name = $field_args['service_name']; |
28 | | - } |
29 | | - elseif (array_key_exists('service', $field_args)) { |
30 | | - $service_name = $field_args['service']; |
31 | | - } |
32 | | - else{ |
33 | | - $service_name = null; |
34 | | - } |
35 | | - |
36 | | - $service_name = MapsMapper::getValidService($service_name, 'fi'); |
37 | | - |
38 | | - $formInput = self::getFormInputInstance(); |
39 | | - |
40 | | - // Get and return the form input HTML from the hook corresponding with the provided service |
41 | | - return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args); |
42 | | - } |
43 | | - |
44 | | - private static function getFormInputInstance($serviceName) { |
45 | | - return new $egMapsServices[$service_name]['fi']['class'](); |
46 | | - } |
47 | | - |
48 | | -} |
49 | | - |
50 | | -/** |
51 | | - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service. |
52 | | - * |
53 | | - * @param unknown_type $coordinates |
54 | | - * @param unknown_type $input_name |
55 | | - * @param unknown_type $is_mandatory |
56 | | - * @param unknown_type $is_disabled |
57 | | - * @param array $field_args |
58 | | - * @return unknown |
59 | | - */ |
60 | | -function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) { |
61 | | - |
62 | | -} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | $hasFormInputs = true; |
41 | 41 | |
42 | 42 | // Add the result form input type for the service name. |
43 | | - self::initFormHook($serviceName, $serviceData['fi']); |
| 43 | + self::initFormHook($serviceName, $serviceData['fi'], $serviceName); |
44 | 44 | |
45 | 45 | // Loop through the service alliases, and add them as form input types. |
46 | 46 | foreach ($serviceData['aliases'] as $alias) self::initFormHook($alias, $serviceData['fi'], $serviceName); |
— | — | @@ -52,8 +52,8 @@ |
53 | 53 | } |
54 | 54 | |
55 | 55 | private static function initializeParams() { |
56 | | - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
57 | | - |
| 56 | + global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 57 | + |
58 | 58 | self::$parameters = array( |
59 | 59 | 'centre' => array( |
60 | 60 | 'aliases' => array('center'), |
— | — | @@ -65,7 +65,7 @@ |
66 | 66 | 'criteria' => array( |
67 | 67 | 'in_array' => $egMapsAvailableServices |
68 | 68 | ), |
69 | | - 'default' => $egMapsDefaultService |
| 69 | + 'default' => $egMapsDefaultServices['fi'] |
70 | 70 | ), |
71 | 71 | 'geoservice' => array( |
72 | 72 | 'aliases' => array(), |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | 'in_array' => array_keys($egMapsAvailableGeoServices) |
75 | 75 | ), |
76 | 76 | 'default' => $egMapsDefaultGeoService |
77 | | - ), |
| 77 | + ), |
78 | 78 | 'service_name' => array('default' => ''), |
79 | 79 | 'part_of_multiple' => array('default' => ''), |
80 | 80 | 'possible_values' => array('default' => ''), |
— | — | @@ -84,13 +84,13 @@ |
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | | - * Adds a mapping service's form hook |
| 88 | + * Adds a mapping service's form hook. |
89 | 89 | * |
90 | | - * @param string $service |
| 90 | + * @param string $inputName The name of the form input. |
91 | 91 | * @param array $fi |
92 | 92 | * @param strig $mainName |
93 | 93 | */ |
94 | | - private static function initFormHook($service, array $fi = null, $mainName = '') { |
| 94 | + private static function initFormHook($inputName, array $fi = null, $mainName = '') { |
95 | 95 | global $wgAutoloadClasses, $sfgFormPrinter, $smgIP; |
96 | 96 | |
97 | 97 | if (isset($fi)) { |
— | — | @@ -103,13 +103,13 @@ |
104 | 104 | // Add the form input hook for the service |
105 | 105 | $field_args = array(); |
106 | 106 | if (strlen($mainName) > 0) $field_args['service_name'] = $mainName; |
107 | | - $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args); |
| 107 | + $sfgFormPrinter->setInputTypeHook($inputName, 'smfSelectFormInputHTML', $field_args); |
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | | - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service. |
| 113 | + * Calls the relevant form input class depending on the provided service. |
114 | 114 | * |
115 | 115 | * @param unknown_type $coordinates |
116 | 116 | * @param unknown_type $input_name |
— | — | @@ -122,10 +122,8 @@ |
123 | 123 | function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) { |
124 | 124 | global $egMapsServices; |
125 | 125 | |
126 | | - // If service_name is set, use this value, and ignore any given |
127 | | - // service parameters |
128 | | - // This will prevent ..input type=googlemaps|service=yahoo.. from |
129 | | - // showing up as a Yahoo! Maps map |
| 126 | + // If service_name is set, use this value, and ignore any given service parameters. |
| 127 | + // This will prevent ..input type=googlemaps|service=yahoo.. from showing up as a Yahoo! Maps map. |
130 | 128 | if (array_key_exists('service_name', $field_args)) { |
131 | 129 | $service_name = $field_args['service_name']; |
132 | 130 | } |
— | — | @@ -137,7 +135,6 @@ |
138 | 136 | } |
139 | 137 | |
140 | 138 | $service_name = MapsMapper::getValidService($service_name, 'fi'); |
141 | | - |
142 | 139 | $formInput = new $egMapsServices[$service_name]['fi']['class'](); |
143 | 140 | |
144 | 141 | // Get and return the form input HTML from the hook corresponding with the provided service |
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js |
— | — | @@ -0,0 +1,118 @@ |
| 2 | + /** |
| 3 | + * Javascript functions for OpenStreetMap functionallity in Semantic Maps |
| 4 | + * |
| 5 | + * @file SM_OSMFunctions.js |
| 6 | + * @ingroup SMOSM |
| 7 | + * |
| 8 | + * @author Jeroen De Dauw |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * This function holds spesific functionallity for the OpenStreetMap form input of Semantic Maps |
| 13 | + * TODO: Refactor as much code as possible to non specific functions |
| 14 | + */ |
| 15 | +function makeOSMFormInput(mapName, locationFieldName, lat, lon, zoom, marker_lat, marker_lon, layers, controls, height) { |
| 16 | + var markers = Array(); |
| 17 | + |
| 18 | + // Show a starting marker only if marker coordinates are provided |
| 19 | + if (marker_lat != null && marker_lon != null) { |
| 20 | + markers.push(getOSMMarkerData(marker_lon, marker_lat, '', '')); |
| 21 | + } |
| 22 | + |
| 23 | + // Click event handler for updating the location of the marker |
| 24 | + // TODO / FIXME: This will probably cause problems when used for multiple maps on one page. |
| 25 | + OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { |
| 26 | + defaultHandlerOptions: { |
| 27 | + 'single': true, |
| 28 | + 'double': false, |
| 29 | + 'pixelTolerance': 0, |
| 30 | + 'stopSingle': false, |
| 31 | + 'stopDouble': false |
| 32 | + }, |
| 33 | + |
| 34 | + initialize: function(options) { |
| 35 | + this.handlerOptions = OpenLayers.Util.extend( |
| 36 | + {}, this.defaultHandlerOptions |
| 37 | + ); |
| 38 | + OpenLayers.Control.prototype.initialize.apply( |
| 39 | + this, arguments |
| 40 | + ); |
| 41 | + this.handler = new OpenLayers.Handler.Click( |
| 42 | + this, { |
| 43 | + 'click': this.trigger |
| 44 | + }, this.handlerOptions |
| 45 | + ); |
| 46 | + }, |
| 47 | + |
| 48 | + trigger: function(e) { |
| 49 | + replaceMarker(mapName, map.getLonLatFromViewPortPx(e.xy)); |
| 50 | + document.getElementById(locationFieldName).value = convertLatToDMS(map.getLonLatFromViewPortPx(e.xy).lat)+', '+convertLngToDMS(map.getLonLatFromViewPortPx(e.xy).lon); |
| 51 | + } |
| 52 | + |
| 53 | + }); |
| 54 | + |
| 55 | + var clickHanler = new OpenLayers.Control.Click(); |
| 56 | + controls.push(clickHanler); |
| 57 | + |
| 58 | + var map = initOpenLayer(mapName, lon, lat, zoom, layers, controls, markers, height); |
| 59 | + |
| 60 | + // Make the map variable available for other functions |
| 61 | + if (!window.OSMMaps) window.OSMMaps = new Object; |
| 62 | + eval("window.OSMMaps." + mapName + " = map;"); |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +/** |
| 67 | + * This function holds spesific functionallity for the OpenStreetMap form input of Semantic Maps |
| 68 | + * TODO: Refactor as much code as possible to non specific functions |
| 69 | + */ |
| 70 | +function showOSMAddress(address, mapName, outputElementName, notFoundFormat) { |
| 71 | + |
| 72 | + var map = OSMMaps[mapName]; |
| 73 | + var geocoder = new GClientGeocoder(); |
| 74 | + |
| 75 | + geocoder.getLatLng(address, |
| 76 | + function(point) { |
| 77 | + if (!point) { |
| 78 | + window.alert(address + ' ' + notFoundFormat); |
| 79 | + } else { |
| 80 | + var loc = new OpenLayers.LonLat(point.x, point.y); |
| 81 | + |
| 82 | + replaceMarker(mapName, loc); |
| 83 | + document.getElementById(outputElementName).value = convertLatToDMS(point.y) + ', ' + convertLngToDMS(point.x); |
| 84 | + } |
| 85 | + } |
| 86 | + ); |
| 87 | + |
| 88 | +} |
| 89 | + |
| 90 | +/** |
| 91 | + * Remove all markers from an OSM map (that's in window.OSMMaps), and place a new one. |
| 92 | + * |
| 93 | + * @param mapName Name of the map as in OSMMaps[mapName]. |
| 94 | + * @param newLocation The location for the new marker. |
| 95 | + * @return |
| 96 | + */ |
| 97 | +function replaceMarker(mapName, newLocation) { |
| 98 | + var map = OSMMaps[mapName]; |
| 99 | + var markerLayer = map.getLayer('markerLayer'); |
| 100 | + |
| 101 | + removeOSMMarkers(markerLayer); |
| 102 | + markerLayer.addMarker(getOSMMarker(markerLayer, getOSMMarkerData(newLocation.lon, newLocation.lat, '', ''), map.getProjectionObject())); |
| 103 | + |
| 104 | + map.panTo(newLocation); |
| 105 | +} |
| 106 | + |
| 107 | +/** |
| 108 | + * Removes all markers from a marker layer. |
| 109 | + * |
| 110 | + * @param markerLayer The layer to remove all markers from. |
| 111 | + * @return |
| 112 | + */ |
| 113 | +function removeOSMMarkers(markerLayer) { |
| 114 | + var markerCollection = markerLayer.markers; |
| 115 | + |
| 116 | + for (i in markerCollection) { |
| 117 | + markerLayer.removeMarker(markerCollection[i]); |
| 118 | + } |
| 119 | +} |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php |
— | — | @@ -3,15 +3,15 @@ |
4 | 4 | /** |
5 | 5 | * This groupe contains all OpenStreetMap related files of the Semantic Maps extension. |
6 | 6 | * |
7 | | - * @defgroup SMOpenStreetMap OpenStreetMap |
| 7 | + * @defgroup SMOSM OpenStreetMap |
8 | 8 | * @ingroup SemanticMaps |
9 | 9 | */ |
10 | 10 | |
11 | 11 | /** |
12 | 12 | * This file holds the general information for the OpenStreetMap service. |
13 | 13 | * |
14 | | - * @file SM_OpenStreetMap.php |
15 | | - * @ingroup SMOpenStreetMap |
| 14 | + * @file SM_OSM.php |
| 15 | + * @ingroup SMOSM |
16 | 16 | * |
17 | 17 | * @author Jeroen De Dauw |
18 | 18 | */ |
— | — | @@ -21,4 +21,4 @@ |
22 | 22 | } |
23 | 23 | |
24 | 24 | $egMapsServices['osm']['qp'] = array('class' => 'SMOSMQP', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMQP.php', 'local' => false); |
25 | | -// $egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false); |
\ No newline at end of file |
| 25 | +//$egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false); |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | global $wgJsMimeType; |
42 | 42 | global $smgScriptPath, $smgOSMFormsOnThisPage, $smgStyleVersion; |
43 | 43 | |
44 | | - MapsOSM::addOLDependencies($this->output); |
| 44 | + MapsOSM::addOSMDependencies($this->output); |
45 | 45 | |
46 | 46 | if (empty($smgOSMFormsOnThisPage)) { |
47 | 47 | $smgOSMFormsOnThisPage = 0; |
— | — | @@ -73,9 +73,9 @@ |
74 | 74 | $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
75 | 75 | |
76 | 76 | $this->output .= <<<EOT |
77 | | - addOnloadHook(makeOSMFormInput( |
| 77 | + <script type='$wgJsMimeType'> |
| 78 | + slippymaps['$this->mapName'] = new slippymap_map( |
78 | 79 | '$this->mapName', |
79 | | - '$this->coordsFieldName', |
80 | 80 | { |
81 | 81 | mode: 'osm-wm', |
82 | 82 | layer: 'osm-like', |
— | — | @@ -85,9 +85,11 @@ |
86 | 86 | zoom: $this->zoom, |
87 | 87 | width: $this->width, |
88 | 88 | height: $this->height, |
89 | | - controls: [$controlItems] |
| 89 | + controls: [$controlItems], |
| 90 | + coordField: '$this->coordsFieldName' |
90 | 91 | } |
91 | | - )); |
| 92 | + ); |
| 93 | + </script> |
92 | 94 | |
93 | 95 | <div id='$this->mapName' class='map' style='width:{$this->width}px; height:{$this->height}px;'> |
94 | 96 | <script type='$wgJsMimeType'>slippymaps['$this->mapName'].init();</script> |
Index: trunk/extensions/SemanticMaps/SemanticMaps.php |
— | — | @@ -23,26 +23,29 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -define('SM_VERSION', '0.5 a15'); |
28 | | - |
29 | | -$smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps'; |
30 | | -$smgIP = $IP . '/extensions/SemanticMaps'; |
31 | | - |
32 | | -$smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION; |
33 | | - |
34 | | -// Include the settings file. |
35 | | -require_once($smgIP . '/SM_Settings.php'); |
36 | | - |
37 | | -$wgExtensionFunctions[] = 'smfSetup'; |
38 | | - |
39 | | -$wgHooks['AdminLinks'][] = 'smfAddToAdminLinks'; |
40 | | - |
41 | | -$wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php'; |
42 | | - |
43 | | -// Registration of the Geographical Coordinate type. |
44 | | -$wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php'; |
45 | | -$wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType'; |
46 | | - |
| 27 | +// Only initialize the extension when all dependencies are present. |
| 28 | +if (defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' )) { |
| 29 | + define('SM_VERSION', '0.5 a18'); |
| 30 | + |
| 31 | + $smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps'; |
| 32 | + $smgIP = $IP . '/extensions/SemanticMaps'; |
| 33 | + |
| 34 | + $smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION; |
| 35 | + |
| 36 | + // Include the settings file. |
| 37 | + require_once($smgIP . '/SM_Settings.php'); |
| 38 | + |
| 39 | + $wgExtensionFunctions[] = 'smfSetup'; |
| 40 | + |
| 41 | + $wgHooks['AdminLinks'][] = 'smfAddToAdminLinks'; |
| 42 | + |
| 43 | + $wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php'; |
| 44 | + |
| 45 | + // Registration of the Geographical Coordinate type. |
| 46 | + $wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php'; |
| 47 | + $wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType'; |
| 48 | +} |
| 49 | + |
47 | 50 | /** |
48 | 51 | * 'Initialization' function for the Semantic Maps extension. |
49 | 52 | * The only work done here is creating the extension credits for |
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php |
— | — | @@ -48,13 +48,13 @@ |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function initializeParams() { |
52 | | - global $egMapsDefaultService, $egMapsDefaultCentre; |
| 52 | + global $egMapsDefaultServices, $egMapsDefaultCentre; |
53 | 53 | |
54 | 54 | self::$parameters = array( |
55 | 55 | 'format' => array( |
56 | 56 | 'aliases' => array(), |
57 | 57 | 'criteria' => array(), |
58 | | - 'default' => $egMapsDefaultService |
| 58 | + 'default' => $egMapsDefaultServices['qp'] |
59 | 59 | ), |
60 | 60 | 'centre' => array( |
61 | 61 | 'aliases' => array('center'), |