Index: branches/Maps0.8/includes/services/OpenLayers/OpenLayers.php |
— | — | @@ -26,14 +26,13 @@ |
27 | 27 | 'group' => 'ext.maps', |
28 | 28 | 'scripts' => array( |
29 | 29 | 'OpenLayers/OpenLayers.js', |
| 30 | + 'OSM/OpenStreetMap.js', |
| 31 | + 'jquery.openlayers.js', |
30 | 32 | 'ext.maps.openlayers.js' |
31 | 33 | ), |
32 | 34 | 'styles' => array( |
33 | 35 | 'OpenLayers/theme/default/style.css' |
34 | 36 | ), |
35 | | - 'messages' => array( |
36 | | - 'maps-markers' |
37 | | - ) |
38 | 37 | ); |
39 | 38 | |
40 | 39 | $wgAutoloadClasses['CriterionOLLayer'] = dirname( __FILE__ ) . '/CriterionOLLayer.php'; |
Index: branches/Maps0.8/includes/services/OpenLayers/ext.maps.openlayers.js |
— | — | @@ -3,183 +3,32 @@ |
4 | 4 | * @see http://www.mediawiki.org/wiki/Extension:Maps |
5 | 5 | * |
6 | 6 | * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
7 | | - * |
8 | | - * TODO: document |
9 | 7 | */ |
10 | 8 | |
11 | | -$( document ).ready( function() { |
12 | | - |
13 | | - OpenLayers.ImgPath = '../extensions/Maps/includes/services/OpenLayers/OpenLayers/img/'; |
14 | | - OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; |
15 | | - OpenLayers.Util.onImageLoadErrorColor = 'transparent'; |
16 | | - OpenLayers.Feature.prototype.popupClass = OpenLayers.Class( |
17 | | - OpenLayers.Popup.FramedCloud, |
18 | | - { |
19 | | - 'autoSize': true, |
20 | | - 'minSize': new OpenLayers.Size( 200, 100 ) |
21 | | - } |
22 | | - ); |
23 | | - |
24 | | - for ( i = 0, n = window.maps['openlayers'].length; i < n; i++ ) { |
25 | | - initiateMap( window.maps['openlayers'][i] ); |
26 | | - } |
27 | | - |
28 | | - function initiateMap( params ) { |
29 | | - OpenLayers.Lang.setCode( params.langCode ); |
30 | | - |
31 | | - var hasImageLayer = false; |
32 | | - for ( i = 0, n = params.layers.length; i < n; i++ ) { |
33 | | - // Idieally this would check if the objecct is of type OpenLayers.layer.image |
34 | | - if ( params.layers[i].options && params.layers[i].options.isImage === true ) { |
35 | | - hasImageLayer = true; |
36 | | - break; |
| 9 | +jQuery(document).ready(function() { |
| 10 | + if ( true ) { |
| 11 | + OpenLayers.ImgPath = '../extensions/Maps/includes/services/OpenLayers/OpenLayers/img/'; |
| 12 | + OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; |
| 13 | + OpenLayers.Util.onImageLoadErrorColor = 'transparent'; |
| 14 | + OpenLayers.Feature.prototype.popupClass = OpenLayers.Class( |
| 15 | + OpenLayers.Popup.FramedCloud, |
| 16 | + { |
| 17 | + 'autoSize': true, |
| 18 | + 'minSize': new OpenLayers.Size( 200, 100 ) |
37 | 19 | } |
38 | | - } |
| 20 | + ); |
39 | 21 | |
40 | | - // Create a new OpenLayers map with without any controls on it. |
41 | | - var mapOptions = { |
42 | | - controls: [], |
43 | | - projection: new OpenLayers.Projection("EPSG:900913"), |
44 | | - units: "m", |
45 | | - maxResolution: 156543.0339, |
46 | | - maxExtent: new OpenLayers.Bounds( |
47 | | - -20037508, -20037508, 20037508, 20037508.34 |
48 | | - ) |
49 | | - }; |
50 | | - |
51 | | - var mapElement = document.getElementById( params.mapId ); |
| 22 | + // OpenLayers.Lang.setCode( params.langCode ); |
52 | 23 | |
53 | | - // Remove the loading map message. |
54 | | - mapElement.innerHTML = ''; |
55 | | - |
56 | | - var map = new OpenLayers.Map( params.mapId, mapOptions ); |
57 | | - |
58 | | - addControls( map, params.controls, mapElement ); |
59 | | - |
60 | | - // Add the base layers. |
61 | | - for ( i = 0, n = params.layers.length; i < n; i++ ) { |
62 | | - map.addLayer( eval( params.layers[i] ) ); |
| 24 | + for ( i in window.maps.openlayers ) { |
| 25 | + jQuery( '#' + i ).openlayers( i, window.maps.openlayers[i] ); |
63 | 26 | } |
64 | | - |
65 | | - var centerIsSet = params.centre.lon != null && params.centre.lat != null; |
66 | | - |
67 | | - addMarkers( map, params, centerIsSet ); |
68 | | - |
69 | | - if ( centerIsSet ) { // When the center is provided, set it. |
70 | | - var centre = new OpenLayers.LonLat( params.centre.lon, params.centre.lat ); |
71 | | - |
72 | | - map.setCenter( centre ); |
73 | | - } |
74 | | - |
75 | | - if (params.zoom != null) map.zoomTo(params.zoom); // When the zoom is provided, set it. |
76 | 27 | } |
77 | | - |
78 | | - function addControls( map, controls, mapElement ) { |
79 | | - // Add the controls. |
80 | | - for ( var i = controls.length - 1; i >= 0; i-- ) { |
81 | | - // If a string is provided, find the correct name for the control, and use eval to create the object itself. |
82 | | - if ( typeof controls[i] == 'string' ) { |
83 | | - if ( controls[i].toLowerCase() == 'autopanzoom' ) { |
84 | | - if ( mapElement.offsetHeight > 140 ) controls[i] = mapElement.offsetHeight > 320 ? 'panzoombar' : 'panzoom'; |
85 | | - } |
86 | | - |
87 | | - control = getValidControlName( controls[i] ); |
88 | | - |
89 | | - if ( control ) { |
90 | | - eval(' map.addControl( new OpenLayers.Control.' + control + '() ); '); |
91 | | - } |
92 | | - } |
93 | | - else { |
94 | | - map.addControl(controls[i]); // If a control is provided, instead a string, just add it. |
95 | | - controls[i].activate(); // And activate it. |
96 | | - } |
97 | | - |
98 | | - } |
99 | | - } |
100 | | - |
101 | | - function addMarkers( map, params, centerIsSet ) { |
102 | | - if ( typeof params.markers == 'undefined' ) { |
103 | | - return; |
104 | | - } |
105 | | - |
106 | | - var bounds = null; |
| 28 | + else { |
| 29 | + alert( mediaWiki.msg( 'maps-openlayers-incompatbrowser' ) ); |
107 | 30 | |
108 | | - // Layer to hold the markers. |
109 | | - var markerLayer = new OpenLayers.Layer.Markers( mediaWiki.msg( 'maps-markers' ) ); |
110 | | - markerLayer.id= 'markerLayer'; |
111 | | - map.addLayer( markerLayer ); |
112 | | - |
113 | | - if ( params.markers.length > 1 && ( !centerIsSet || params.zoom == null ) ) { |
114 | | - bounds = new OpenLayers.Bounds(); |
| 31 | + for ( i in window.maps.googlemaps3 ) { |
| 32 | + jQuery( '#' + i ).text( mediaWiki.msg( 'maps-load-failed' ) ); |
115 | 33 | } |
116 | | - |
117 | | - for ( i = params.markers.length - 1; i >= 0; i-- ) { |
118 | | - params.markers[i].lonlat = new OpenLayers.LonLat( params.markers[i].lon, params.markers[i].lat ); |
119 | | - |
120 | | - if ( bounds != null ) bounds.extend( params.markers[i].lonlat ); // Extend the bounds when no center is set. |
121 | | - markerLayer.addMarker( getOLMarker( markerLayer, params.markers[i] ) ); // Create and add the marker. |
122 | | - } |
123 | | - |
124 | | - if ( bounds != null ) map.zoomToExtent( bounds ); // If a bounds object has been created, use it to set the zoom and center. |
125 | | - } |
126 | | - |
127 | | - /** |
128 | | - * Gets a valid control name (with excat lower and upper case letters), |
129 | | - * or returns false when the control is not allowed. |
130 | | - */ |
131 | | - function getValidControlName( control ) { |
132 | | - var OLControls = [ |
133 | | - 'ArgParser', 'Attribution', 'Button', 'DragFeature', 'DragPan', |
134 | | - 'DrawFeature', 'EditingToolbar', 'GetFeature', 'KeyboardDefaults', 'LayerSwitcher', |
135 | | - 'Measure', 'ModifyFeature', 'MouseDefaults', 'MousePosition', 'MouseToolbar', |
136 | | - 'Navigation', 'NavigationHistory', 'NavToolbar', 'OverviewMap', 'Pan', |
137 | | - 'Panel', 'PanPanel', 'PanZoom', 'PanZoomBar', 'Permalink', |
138 | | - 'Scale', 'ScaleLine', 'SelectFeature', 'Snapping', 'Split', |
139 | | - 'WMSGetFeatureInfo', 'ZoomBox', 'ZoomIn', 'ZoomOut', 'ZoomPanel', |
140 | | - 'ZoomToMaxExtent' |
141 | | - ]; |
142 | | - |
143 | | - for ( var i = OLControls.length - 1; i >= 0; i-- ) { |
144 | | - if ( control == OLControls[i].toLowerCase() ) { |
145 | | - return OLControls[i]; |
146 | | - } |
147 | | - } |
148 | | - |
149 | | - return false; |
150 | | - } |
151 | | - |
152 | | - function getOLMarker(markerLayer, markerData) { |
153 | | - var marker; |
154 | | - |
155 | | - if (markerData.icon != "") { |
156 | | - marker = new OpenLayers.Marker(markerData.lonlat, new OpenLayers.Icon(markerData.icon)); |
157 | | - } else { |
158 | | - marker = new OpenLayers.Marker(markerData.lonlat); |
159 | | - } |
160 | | - |
161 | | - if ( markerData.title.length + markerData.label.length > 0 ) { |
162 | | - |
163 | | - // This is the handler for the mousedown event on the marker, and displays the popup. |
164 | | - marker.events.register('mousedown', marker, |
165 | | - function(evt) { |
166 | | - var popup = new OpenLayers.Feature(markerLayer, markerData.lonlat).createPopup(true); |
167 | | - |
168 | | - if (markerData.title.length > 0 && markerData.label.length > 0) { // Add the title and label to the popup text. |
169 | | - popup.setContentHTML('<b>' + markerData.title + '</b><hr />' + markerData.label); |
170 | | - } |
171 | | - else { |
172 | | - popup.setContentHTML(markerData.title + markerData.label); |
173 | | - } |
174 | | - |
175 | | - popup.setOpacity(0.85); |
176 | | - markerLayer.map.addPopup(popup); |
177 | | - OpenLayers.Event.stop(evt); // Stop the event. |
178 | | - } |
179 | | - ); |
180 | | - |
181 | | - } |
182 | | - |
183 | | - return marker; |
184 | 34 | } |
185 | | - |
186 | | -} ); |
\ No newline at end of file |
| 35 | +}); |
Index: branches/Maps0.8/includes/services/OpenLayers/jquery.openlayers.js |
— | — | @@ -1,3 +1,154 @@ |
2 | 2 | /** |
| 3 | + * JavasSript for OpenLayers maps in the Maps extension. |
| 4 | + * @see http://www.mediawiki.org/wiki/Extension:Maps |
3 | 5 | * |
4 | | - */ |
\ No newline at end of file |
| 6 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 7 | + */ |
| 8 | + |
| 9 | +(function( $ ){ $.fn.openlayers = function( mapElementId, options ) { |
| 10 | + |
| 11 | + // Remove the loading map message. |
| 12 | + this.text( '' ); |
| 13 | + |
| 14 | + var mapOptions = { |
| 15 | + controls: [], |
| 16 | + projection: new OpenLayers.Projection("EPSG:900913"), |
| 17 | + units: "m", |
| 18 | + maxResolution: 156543.0339, |
| 19 | + maxExtent: new OpenLayers.Bounds( |
| 20 | + -20037508, -20037508, 20037508, 20037508.34 |
| 21 | + ) |
| 22 | + }; |
| 23 | + |
| 24 | + var map = new OpenLayers.Map( mapElementId, mapOptions ); |
| 25 | + |
| 26 | + addControls( map, options.controls, this.get( 0 ) ); |
| 27 | + |
| 28 | + // Add the base layers. |
| 29 | + for ( i = 0, n = options.layers.length; i < n; i++ ) { |
| 30 | + map.addLayer( eval( options.layers[i] ) ); |
| 31 | + } |
| 32 | + |
| 33 | + addMarkers( map, options ); |
| 34 | + |
| 35 | + if ( options.centre !== false ) { // When the center is provided, set it. |
| 36 | + map.setCenter( new OpenLayers.LonLat( options.centre.lon, options.centre.lat ) ); |
| 37 | + } |
| 38 | + |
| 39 | + if ( options.zoom !== false ) { |
| 40 | + map.zoomTo( options.zoom ); |
| 41 | + } |
| 42 | + |
| 43 | + function addControls( map, controls, mapElement ) { |
| 44 | + // Add the controls. |
| 45 | + for ( var i = controls.length - 1; i >= 0; i-- ) { |
| 46 | + // If a string is provided, find the correct name for the control, and use eval to create the object itself. |
| 47 | + if ( typeof controls[i] == 'string' ) { |
| 48 | + if ( controls[i].toLowerCase() == 'autopanzoom' ) { |
| 49 | + if ( mapElement.offsetHeight > 140 ) controls[i] = mapElement.offsetHeight > 320 ? 'panzoombar' : 'panzoom'; |
| 50 | + } |
| 51 | + |
| 52 | + control = getValidControlName( controls[i] ); |
| 53 | + |
| 54 | + if ( control ) { |
| 55 | + eval(' map.addControl( new OpenLayers.Control.' + control + '() ); '); |
| 56 | + } |
| 57 | + } |
| 58 | + else { |
| 59 | + map.addControl(controls[i]); // If a control is provided, instead a string, just add it. |
| 60 | + controls[i].activate(); // And activate it. |
| 61 | + } |
| 62 | + |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Gets a valid control name (with excat lower and upper case letters), |
| 68 | + * or returns false when the control is not allowed. |
| 69 | + */ |
| 70 | + function getValidControlName( control ) { |
| 71 | + var OLControls = [ |
| 72 | + 'ArgParser', 'Attribution', 'Button', 'DragFeature', 'DragPan', |
| 73 | + 'DrawFeature', 'EditingToolbar', 'GetFeature', 'KeyboardDefaults', 'LayerSwitcher', |
| 74 | + 'Measure', 'ModifyFeature', 'MouseDefaults', 'MousePosition', 'MouseToolbar', |
| 75 | + 'Navigation', 'NavigationHistory', 'NavToolbar', 'OverviewMap', 'Pan', |
| 76 | + 'Panel', 'PanPanel', 'PanZoom', 'PanZoomBar', 'Permalink', |
| 77 | + 'Scale', 'ScaleLine', 'SelectFeature', 'Snapping', 'Split', |
| 78 | + 'WMSGetFeatureInfo', 'ZoomBox', 'ZoomIn', 'ZoomOut', 'ZoomPanel', |
| 79 | + 'ZoomToMaxExtent' |
| 80 | + ]; |
| 81 | + |
| 82 | + for ( var i = OLControls.length - 1; i >= 0; i-- ) { |
| 83 | + if ( control == OLControls[i].toLowerCase() ) { |
| 84 | + return OLControls[i]; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + return false; |
| 89 | + } |
| 90 | + |
| 91 | + function addMarkers( map, params ) { |
| 92 | + if ( typeof params.markers == 'undefined' ) { |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + var bounds = null; |
| 97 | + |
| 98 | + // Layer to hold the markers. |
| 99 | + var markerLayer = new OpenLayers.Layer.Markers( mediaWiki.msg( 'maps-markers' ) ); |
| 100 | + markerLayer.id= 'markerLayer'; |
| 101 | + map.addLayer( markerLayer ); |
| 102 | + |
| 103 | + if ( params.markers.length > 1 && ( params.centre === false || params.zoom === false ) ) { |
| 104 | + bounds = new OpenLayers.Bounds(); |
| 105 | + } |
| 106 | + |
| 107 | + for ( i = params.markers.length - 1; i >= 0; i-- ) { |
| 108 | + params.markers[i].lonlat = new OpenLayers.LonLat( params.markers[i].lon, params.markers[i].lat ); |
| 109 | + |
| 110 | + if ( bounds != null ) bounds.extend( params.markers[i].lonlat ); // Extend the bounds when no center is set. |
| 111 | + markerLayer.addMarker( getOLMarker( markerLayer, params.markers[i] ) ); // Create and add the marker. |
| 112 | + } |
| 113 | + |
| 114 | + if ( bounds != null ) map.zoomToExtent( bounds ); // If a bounds object has been created, use it to set the zoom and center. |
| 115 | + } |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + function getOLMarker(markerLayer, markerData) { |
| 120 | + var marker; |
| 121 | + |
| 122 | + if (markerData.icon != "") { |
| 123 | + marker = new OpenLayers.Marker(markerData.lonlat, new OpenLayers.Icon(markerData.icon)); |
| 124 | + } else { |
| 125 | + marker = new OpenLayers.Marker(markerData.lonlat); |
| 126 | + } |
| 127 | + |
| 128 | + if ( markerData.title.length + markerData.label.length > 0 ) { |
| 129 | + |
| 130 | + // This is the handler for the mousedown event on the marker, and displays the popup. |
| 131 | + marker.events.register('mousedown', marker, |
| 132 | + function(evt) { |
| 133 | + var popup = new OpenLayers.Feature(markerLayer, markerData.lonlat).createPopup(true); |
| 134 | + |
| 135 | + if (markerData.title.length > 0 && markerData.label.length > 0) { // Add the title and label to the popup text. |
| 136 | + popup.setContentHTML('<b>' + markerData.title + '</b><hr />' + markerData.label); |
| 137 | + } |
| 138 | + else { |
| 139 | + popup.setContentHTML(markerData.title + markerData.label); |
| 140 | + } |
| 141 | + |
| 142 | + popup.setOpacity(0.85); |
| 143 | + markerLayer.map.addPopup(popup); |
| 144 | + OpenLayers.Event.stop(evt); // Stop the event. |
| 145 | + } |
| 146 | + ); |
| 147 | + |
| 148 | + } |
| 149 | + |
| 150 | + return marker; |
| 151 | + } |
| 152 | + |
| 153 | + return this; |
| 154 | + |
| 155 | +}; })( jQuery ); |