Index: trunk/extensions/Maps/OpenLayers/OpenLayerFunctions.js |
— | — | @@ -7,44 +7,26 @@ |
8 | 8 | * @author Jeroen De Dauw |
9 | 9 | */ |
10 | 10 | |
11 | | - |
12 | 11 | /** |
13 | | - * Get a valid control name (with excat lower and upper case letters), |
14 | | - * or return false when the control is not allowed. |
15 | | - */ |
16 | | -function getValidControlName(control) { |
17 | | - var OLControls = ['ArgParser', 'Attribution', 'Button', 'DragFeature', 'DragPan', |
18 | | - 'DrawFeature', 'EditingToolbar', 'GetFeature', 'KeyboardDefaults', 'LayerSwitcher', |
19 | | - 'Measure', 'ModifyFeature', 'MouseDefaults', 'MousePosition', 'MouseToolbar', |
20 | | - 'Navigation', 'NavigationHistory', 'NavToolbar', 'OverviewMap', 'Pan', |
21 | | - 'Panel', 'PanPanel', 'PanZoom', 'PanZoomBar', 'Permalink', |
22 | | - 'Scale', 'ScaleLine', 'SelectFeature', 'Snapping', 'Split', |
23 | | - 'WMSGetFeatureInfo', 'ZoomBox', 'ZoomIn', 'ZoomOut', 'ZoomPanel', |
24 | | - 'ZoomToMaxExtent']; |
25 | | - |
26 | | - for (i in OLControls) { |
27 | | - if (control == OLControls[i].toLowerCase()) { |
28 | | - return OLControls[i]; |
29 | | - } |
30 | | - } |
31 | | - |
32 | | - return false; |
33 | | -} |
34 | | - |
35 | | -/** |
36 | | - * Create and initialize an OpenLayers map. |
| 12 | + * Creates and initializes an OpenLayers map. |
37 | 13 | * The resulting map is returned by the function but no further handling is required in most cases. |
38 | 14 | */ |
39 | 15 | function initOpenLayer(mapName, lon, lat, zoom, mapTypes, controls, marker_data){ |
40 | | - // Create a new OpenLayers map without any controls on it |
41 | | - var mapOptions = { /* |
42 | | - projection: new OpenLayers.Projection("EPSG:900913"), |
43 | | - displayProjection: new OpenLayers.Projection("EPSG:900913"), |
44 | | - units: "m", |
45 | | - */ |
| 16 | + |
| 17 | + // Create a new OpenLayers map with without any controls on it |
| 18 | + var mapOptions = { |
| 19 | + projection: new OpenLayers.Projection("EPSG:900913"), |
| 20 | + displayProjection: new OpenLayers.Projection("EPSG:4326"), |
| 21 | + units: "m", |
| 22 | + numZoomLevels: 18, |
| 23 | + maxResolution: 156543.0339, |
| 24 | + maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34), |
46 | 25 | controls: [] |
47 | 26 | } |
48 | 27 | |
| 28 | + |
| 29 | + |
| 30 | + |
49 | 31 | var map = new OpenLayers.Map(mapName, mapOptions); |
50 | 32 | |
51 | 33 | // Add the controls |
— | — | @@ -65,8 +47,63 @@ |
66 | 48 | |
67 | 49 | } |
68 | 50 | |
| 51 | + addMapBaseLayers(map, mapTypes); |
| 52 | + |
| 53 | + // Layer to hold the markers |
| 54 | + var markerLayer = new OpenLayers.Layer.Markers('Markers'); |
| 55 | + markerLayer.id= 'markerLayer'; |
| 56 | + map.addLayer(markerLayer); |
| 57 | + |
| 58 | + var centerIsSet = lon != null && lat != null; |
| 59 | + |
| 60 | + var bounds = null; |
| 61 | + |
| 62 | + if (marker_data.length > 1 && (!centerIsSet || zoom == null)) { |
| 63 | + bounds = new OpenLayers.Bounds(); |
| 64 | + } |
| 65 | + |
| 66 | + for (i in marker_data) { |
| 67 | + if (bounds != null) bounds.extend(marker_data[i].lonlat); // Extend the bounds when no center is set |
| 68 | + markerLayer.addMarker(getOLMarker(markerLayer, marker_data[i], map.getProjectionObject())); // Create and add the marker |
| 69 | + } |
| 70 | + |
| 71 | + if (bounds != null) map.zoomToExtent(bounds); // If a bounds object has been created, use it to set the zoom and center |
| 72 | + if (centerIsSet) map.setCenter(new OpenLayers.LonLat(lon, lat)); // When the center is provided, set it |
| 73 | + if (zoom != null) map.zoomTo(zoom); // When the zoom is provided, set it |
| 74 | + |
| 75 | + return map; |
| 76 | +} |
| 77 | + |
| 78 | +/** |
| 79 | + * Gets a valid control name (with excat lower and upper case letters), |
| 80 | + * or returns false when the control is not allowed. |
| 81 | + */ |
| 82 | +function getValidControlName(control) { |
| 83 | + var OLControls = ['ArgParser', 'Attribution', 'Button', 'DragFeature', 'DragPan', |
| 84 | + 'DrawFeature', 'EditingToolbar', 'GetFeature', 'KeyboardDefaults', 'LayerSwitcher', |
| 85 | + 'Measure', 'ModifyFeature', 'MouseDefaults', 'MousePosition', 'MouseToolbar', |
| 86 | + 'Navigation', 'NavigationHistory', 'NavToolbar', 'OverviewMap', 'Pan', |
| 87 | + 'Panel', 'PanPanel', 'PanZoom', 'PanZoomBar', 'Permalink', |
| 88 | + 'Scale', 'ScaleLine', 'SelectFeature', 'Snapping', 'Split', |
| 89 | + 'WMSGetFeatureInfo', 'ZoomBox', 'ZoomIn', 'ZoomOut', 'ZoomPanel', |
| 90 | + 'ZoomToMaxExtent']; |
| 91 | + |
| 92 | + for (i in OLControls) { |
| 93 | + if (control == OLControls[i].toLowerCase()) { |
| 94 | + return OLControls[i]; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + return false; |
| 99 | +} |
| 100 | + |
| 101 | +/** |
| 102 | + * Adds all map type base layers to a map, and returns it. |
| 103 | + */ |
| 104 | +function addMapBaseLayers(map, mapTypes) { |
69 | 105 | // Variables for whowing an error when the Google Maps API is not loaded |
70 | | - var googleAPILoaded = typeof(G_NORMAL_MAP) != 'undefined'; var shownApiError = false; |
| 106 | + var googleAPILoaded = typeof(G_NORMAL_MAP) != 'undefined'; |
| 107 | + var shownApiError = false; |
71 | 108 | |
72 | 109 | // Variables to prevent double adding of a base layer |
73 | 110 | var usedNor = false; var usedSat = false; var usedHyb = false; var usedPhy = false; // Google types |
— | — | @@ -91,7 +128,7 @@ |
92 | 129 | if (googleAPILoaded) { |
93 | 130 | switch(mapTypes[i]) { |
94 | 131 | case 'google-normal' : |
95 | | - if (!usedNor){ newLayer = new OpenLayers.Layer.Google( 'Google Maps' /*, {sphericalMercator:true} */ ); usedNor = true; } |
| 132 | + if (!usedNor){ newLayer = new OpenLayers.Layer.Google( 'Google Streets' /*, {sphericalMercator:true} */ ); usedNor = true; } |
96 | 133 | break; |
97 | 134 | case 'google-satellite' : |
98 | 135 | if (!usedSat){ newLayer = new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP /*, sphericalMercator:true */}); usedSat = true; } |
— | — | @@ -103,7 +140,7 @@ |
104 | 141 | if (!usedPhy){ newLayer = new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP /*, sphericalMercator:true */}); usedPhy = true; } |
105 | 142 | break; |
106 | 143 | case 'google' : |
107 | | - if (!usedNor){ map.addLayer(new OpenLayers.Layer.Google( 'Google Maps' /*, {sphericalMercator:true} */)); usedNor = true; } |
| 144 | + if (!usedNor){ map.addLayer(new OpenLayers.Layer.Google( 'Google Streets' /*, {sphericalMercator:true} */)); usedNor = true; } |
108 | 145 | if (!usedSat){ map.addLayer(new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP /*, sphericalMercator:true */})); usedSat = true; } |
109 | 146 | if (!usedHyb){ map.addLayer(new OpenLayers.Layer.Google( 'Google Hybrid' , {type: G_HYBRID_MAP /*, sphericalMercator:true */})); usedHyb = true; } |
110 | 147 | if (!usedPhy){ map.addLayer(new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP /*, sphericalMercator:true */})); usedPhy = true; } |
— | — | @@ -115,29 +152,29 @@ |
116 | 153 | } |
117 | 154 | break; |
118 | 155 | case 'bing' : case 'virtual-earth' : |
119 | | - if (!usedBingNor){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Maps' , {type: VEMapStyle.Shaded} ); usedBingNor = true; } |
120 | | - if (!usedBingSat){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial} ); usedBingSat = true; } |
121 | | - if (!usedBingHyb){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid} ); usedBingHyb = true; } |
| 156 | + if (!usedBingNor){ map.addLayer(new OpenLayers.Layer.VirtualEarth( 'Bing Streets' , {type: VEMapStyle.Shaded} )); usedBingNor = true; } |
| 157 | + if (!usedBingSat){ map.addLayer(new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial} )); usedBingSat = true; } |
| 158 | + if (!usedBingHyb){ map.addLayer(new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid} )); usedBingHyb = true; } |
122 | 159 | break; |
123 | 160 | case 'bing-normal' : |
124 | | - if (!usedBingNor){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Maps' , {type: VEMapStyle.Shaded} ); usedBingNor = true; } |
| 161 | + if (!usedBingNor){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Streets' , {type: VEMapStyle.Shaded} ); usedBingNor = true; } |
125 | 162 | case 'bing-satellite' : |
126 | 163 | if (!usedBingSat){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial} ); usedBingSat = true; } |
127 | 164 | case 'bing-hybrid' : |
128 | 165 | if (!usedBingHyb){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid} ); usedBingHyb = true; } |
129 | 166 | case 'yahoo' : |
130 | | - if (!usedYahooNor){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Maps' ); usedYahooNor = true; } |
131 | | - if (!usedYahooSat){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Maps', {'type': YAHOO_MAP_SAT} ); usedYahooSat = true; } |
132 | | - if (!usedYahooHyb){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Maps', {'type': YAHOO_MAP_HYB} ); usedYahooHyb = true; } |
| 167 | + if (!usedYahooNor){ map.addLayer(new OpenLayers.Layer.Yahoo( 'Yahoo Streets' )); usedYahooNor = true; } |
| 168 | + if (!usedYahooSat){ map.addLayer(new OpenLayers.Layer.Yahoo( 'Yahoo Satellite', {'type': YAHOO_MAP_SAT} )); usedYahooSat = true; } |
| 169 | + if (!usedYahooHyb){ map.addLayer(new OpenLayers.Layer.Yahoo( 'Yahoo Hybrid', {'type': YAHOO_MAP_HYB} )); usedYahooHyb = true; } |
133 | 170 | break; |
134 | 171 | case 'yahoo-normal' : |
135 | | - if (!usedYahooNor){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Maps' ); usedYahooNor = true; } |
| 172 | + if (!usedYahooNor){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Streets' ); usedYahooNor = true; } |
136 | 173 | break; |
137 | 174 | case 'yahoo-satellite' : |
138 | | - if (!usedYahooSat){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Maps', {'type': YAHOO_MAP_SAT} ); usedYahooSat = true; } |
| 175 | + if (!usedYahooSat){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Satellite', {'type': YAHOO_MAP_SAT} ); usedYahooSat = true; } |
139 | 176 | break; |
140 | 177 | case 'yahoo-hybrid' : |
141 | | - if (!usedYahooHyb){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Maps', {'type': YAHOO_MAP_HYB} ); usedYahooHyb = true; } |
| 178 | + if (!usedYahooHyb){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Hybrid', {'type': YAHOO_MAP_HYB} ); usedYahooHyb = true; } |
142 | 179 | break; |
143 | 180 | case 'openlayers' : case 'open-layers' : |
144 | 181 | if (!usedOLWMS){ newLayer = new OpenLayers.Layer.WMS( 'OpenLayers WMS', 'http://labs.metacarta.com/wms/vmap0', {layers: 'basic'} ); usedOLWMS = true; } |
— | — | @@ -146,9 +183,19 @@ |
147 | 184 | if (!usedNasa){ newLayer = new OpenLayers.Layer.WMS("NASA Global Mosaic", "http://t1.hypercube.telascience.org/cgi-bin/landsat7", {layers: "landsat7" /*, sphericalMercator:true */} ); usedNasa = true; } |
148 | 185 | break; |
149 | 186 | // FIXME: this will cause the OL API to mess itself up - other coordinate system? |
150 | | - /* |
| 187 | + |
151 | 188 | case 'osm' : case 'openstreetmap' : |
152 | | - if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.Osmarender("Open Street Map"); usedOSM = true; } |
| 189 | + window.alert('osm'); |
| 190 | + if (!usedOSM){ newLayer = new OpenLayers.Layer.TMS( |
| 191 | + "OpenStreetMap (Mapnik)", |
| 192 | + "http://tile.openstreetmap.org/", |
| 193 | + { |
| 194 | + type: 'png', getURL: osm_getTileURL, |
| 195 | + displayOutsideMaxExtent: true, |
| 196 | + attribution: '<a href="http://www.openstreetmap.org/">OpenStreetMap</a>' |
| 197 | + } |
| 198 | + ); |
| 199 | + usedOSM = true; } |
153 | 200 | break; |
154 | 201 | case 'osm-nik' : case 'osm-mapnik' : |
155 | 202 | if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.Mapnik("OSM Mapnik"); usedOSM = true; } |
— | — | @@ -156,7 +203,7 @@ |
157 | 204 | case 'osm-cycle' : case 'osm-cyclemap' : |
158 | 205 | if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.CycleMap("Cycle Map"); usedOSM = true; } |
159 | 206 | break; |
160 | | - */ |
| 207 | + |
161 | 208 | } |
162 | 209 | |
163 | 210 | if (newLayer != null) { |
— | — | @@ -171,37 +218,10 @@ |
172 | 219 | } |
173 | 220 | */ |
174 | 221 | } |
175 | | - |
176 | | - |
177 | 222 | } |
178 | | - |
179 | | - // Layer to hold the markers |
180 | | - var markerLayer = new OpenLayers.Layer.Markers('Markers'); |
181 | | - markerLayer.id= 'markerLayer'; |
182 | | - map.addLayer(markerLayer); |
183 | | - |
184 | | - var centerIsSet = lon != null && lat != null; |
185 | | - |
186 | | - var bounds = null; |
187 | | - |
188 | | - if (marker_data.length > 1 && (!centerIsSet || zoom == null)) { |
189 | | - bounds = new OpenLayers.Bounds(); |
190 | | - } |
191 | | - |
192 | | - for (i in marker_data) { |
193 | | - if (bounds != null) bounds.extend(marker_data[i].lonlat); // Extend the bounds when no center is set |
194 | | - markerLayer.addMarker(getOLMarker(markerLayer, marker_data[i], map.getProjectionObject())); // Create and add the marker |
195 | | - } |
196 | | - |
197 | | - if (bounds != null) map.zoomToExtent(bounds); // If a bounds object has been created, use it to set the zoom and center |
198 | | - if (centerIsSet) map.setCenter(new OpenLayers.LonLat(lon, lat)); // When the center is provided, set it |
199 | | - if (zoom != null) map.zoomTo(zoom); // When the zoom is provided, set it |
200 | | - |
201 | 223 | return map; |
202 | 224 | } |
203 | | - |
204 | 225 | |
205 | | - |
206 | 226 | function getOLMarker(markerLayer, markerData, projectionObject) { |
207 | 227 | //markerData.lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); |
208 | 228 | |
— | — | @@ -243,7 +263,9 @@ |
244 | 264 | } |
245 | 265 | |
246 | 266 | |
247 | | -function setOLPopupType(minWidth, minHeight) { |
| 267 | +function initOLSettings(minWidth, minHeight) { |
| 268 | + OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3; |
| 269 | + OpenLayers.Util.onImageLoadErrorColor = "transparent"; |
248 | 270 | OpenLayers.Feature.prototype.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {'autoSize': true, 'minSize': new OpenLayers.Size(minWidth, minHeight)}); |
249 | 271 | } |
250 | 272 | |
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php |
— | — | @@ -80,7 +80,7 @@ |
81 | 81 | $output .="<link rel='stylesheet' href='$egMapsIncludePath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
|
82 | 82 | <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayers/OpenLayers.js'></script>
|
83 | 83 | <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayerFunctions.js'></script>
|
84 | | - <script type='$wgJsMimeType'>setOLPopupType(200, 100);</script>\n";
|
| 84 | + <script type='$wgJsMimeType'>initOLSettings(200, 100);</script>\n";
|
85 | 85 | }
|
86 | 86 | }
|
87 | 87 |
|