Index: trunk/extensions/Maps/OpenLayers/OpenLayerFunctions.js |
— | — | @@ -24,9 +24,6 @@ |
25 | 25 | controls: [] |
26 | 26 | } |
27 | 27 | |
28 | | - |
29 | | - |
30 | | - |
31 | 28 | var map = new OpenLayers.Map(mapName, mapOptions); |
32 | 29 | |
33 | 30 | // Add the controls |
— | — | @@ -63,12 +60,19 @@ |
64 | 61 | } |
65 | 62 | |
66 | 63 | for (i in marker_data) { |
| 64 | + marker_data[i].lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); |
67 | 65 | if (bounds != null) bounds.extend(marker_data[i].lonlat); // Extend the bounds when no center is set |
68 | 66 | markerLayer.addMarker(getOLMarker(markerLayer, marker_data[i], map.getProjectionObject())); // Create and add the marker |
69 | 67 | } |
70 | 68 | |
71 | 69 | 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 |
| 70 | + |
| 71 | + if (centerIsSet) { // When the center is provided, set it |
| 72 | + var centre = new OpenLayers.LonLat(lon, lat); |
| 73 | + centre.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); |
| 74 | + map.setCenter(centre); |
| 75 | + } |
| 76 | + |
73 | 77 | if (zoom != null) map.zoomTo(zoom); // When the zoom is provided, set it |
74 | 78 | |
75 | 79 | return map; |
— | — | @@ -109,7 +113,10 @@ |
110 | 114 | var usedNor = false; var usedSat = false; var usedHyb = false; var usedPhy = false; // Google types |
111 | 115 | var usedBingNor = false; var usedBingHyb = false; var usedBingSat = false; // Bing types |
112 | 116 | var usedYahooNor = false; var usedYahooHyb = false; var usedYahooSat = false; // Yahoo types |
113 | | - var usedOLWMS = false; var usedNasa = false; var usedOSM = false; |
| 117 | + var usedOLWMS = false; // OL types |
| 118 | + var usedOSMnik = false; var usedOSMcycle = false; var usedOSMarender = false; // OSM types |
| 119 | + var usedNasa = false; // Others |
| 120 | + |
114 | 121 | var isDefaultBaseLayer = false; |
115 | 122 | |
116 | 123 | // Add the base layers |
— | — | @@ -128,22 +135,22 @@ |
129 | 136 | if (googleAPILoaded) { |
130 | 137 | switch(mapTypes[i]) { |
131 | 138 | case 'google-normal' : |
132 | | - if (!usedNor){ newLayer = new OpenLayers.Layer.Google( 'Google Streets' /*, {sphericalMercator:true} */ ); usedNor = true; } |
| 139 | + if (!usedNor){ newLayer = new OpenLayers.Layer.Google( 'Google Streets', {'sphericalMercator':true} ); usedNor = true; } |
133 | 140 | break; |
134 | 141 | case 'google-satellite' : |
135 | | - if (!usedSat){ newLayer = new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP /*, sphericalMercator:true */}); usedSat = true; } |
| 142 | + if (!usedSat){ newLayer = new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP , 'sphericalMercator':true}); usedSat = true; } |
136 | 143 | break; |
137 | 144 | case 'google-hybrid' : |
138 | | - if (!usedHyb){ newLayer = new OpenLayers.Layer.Google( 'Google Hybrid' , {type: G_HYBRID_MAP /*, sphericalMercator:true */}); usedHyb = true; } |
| 145 | + if (!usedHyb){ newLayer = new OpenLayers.Layer.Google( 'Google Hybrid' , {type: G_HYBRID_MAP , 'sphericalMercator':true}); usedHyb = true; } |
139 | 146 | break; |
140 | 147 | case 'google-physical' : |
141 | | - if (!usedPhy){ newLayer = new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP /*, sphericalMercator:true */}); usedPhy = true; } |
| 148 | + if (!usedPhy){ newLayer = new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP , 'sphericalMercator':true}); usedPhy = true; } |
142 | 149 | break; |
143 | 150 | case 'google' : |
144 | | - if (!usedNor){ map.addLayer(new OpenLayers.Layer.Google( 'Google Streets' /*, {sphericalMercator:true} */)); usedNor = true; } |
145 | | - if (!usedSat){ map.addLayer(new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP /*, sphericalMercator:true */})); usedSat = true; } |
146 | | - if (!usedHyb){ map.addLayer(new OpenLayers.Layer.Google( 'Google Hybrid' , {type: G_HYBRID_MAP /*, sphericalMercator:true */})); usedHyb = true; } |
147 | | - if (!usedPhy){ map.addLayer(new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP /*, sphericalMercator:true */})); usedPhy = true; } |
| 151 | + if (!usedNor){ map.addLayer(new OpenLayers.Layer.Google( 'Google Streets' , {'sphericalMercator':true})); usedNor = true; } |
| 152 | + if (!usedSat){ map.addLayer(new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP , 'sphericalMercator':true})); usedSat = true; } |
| 153 | + if (!usedHyb){ map.addLayer(new OpenLayers.Layer.Google( 'Google Hybrid' , {type: G_HYBRID_MAP , 'sphericalMercator':true})); usedHyb = true; } |
| 154 | + if (!usedPhy){ map.addLayer(new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP , 'sphericalMercator':true})); usedPhy = true; } |
148 | 155 | break; |
149 | 156 | } |
150 | 157 | } |
— | — | @@ -152,58 +159,50 @@ |
153 | 160 | } |
154 | 161 | break; |
155 | 162 | case 'bing' : case 'virtual-earth' : |
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; } |
| 163 | + if (!usedBingNor){ map.addLayer(new OpenLayers.Layer.VirtualEarth( 'Bing Streets' , {type: VEMapStyle.Shaded, 'sphericalMercator':true} )); usedBingNor = true; } |
| 164 | + if (!usedBingSat){ map.addLayer(new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial, 'sphericalMercator':true} )); usedBingSat = true; } |
| 165 | + if (!usedBingHyb){ map.addLayer(new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid, 'sphericalMercator':true} )); usedBingHyb = true; } |
159 | 166 | break; |
160 | 167 | case 'bing-normal' : |
161 | | - if (!usedBingNor){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Streets' , {type: VEMapStyle.Shaded} ); usedBingNor = true; } |
| 168 | + if (!usedBingNor){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Streets' , {type: VEMapStyle.Shaded, 'sphericalMercator':true} ); usedBingNor = true; } |
162 | 169 | case 'bing-satellite' : |
163 | | - if (!usedBingSat){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial} ); usedBingSat = true; } |
| 170 | + if (!usedBingSat){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial, 'sphericalMercator':true} ); usedBingSat = true; } |
164 | 171 | case 'bing-hybrid' : |
165 | | - if (!usedBingHyb){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid} ); usedBingHyb = true; } |
| 172 | + if (!usedBingHyb){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid, 'sphericalMercator':true} ); usedBingHyb = true; } |
166 | 173 | case 'yahoo' : |
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; } |
| 174 | + if (!usedYahooNor){ map.addLayer(new OpenLayers.Layer.Yahoo( 'Yahoo Streets' ), {'sphericalMercator':true}); usedYahooNor = true; } |
| 175 | + if (!usedYahooSat){ map.addLayer(new OpenLayers.Layer.Yahoo( 'Yahoo Satellite', {'type': YAHOO_MAP_SAT, 'sphericalMercator':true} )); usedYahooSat = true; } |
| 176 | + if (!usedYahooHyb){ map.addLayer(new OpenLayers.Layer.Yahoo( 'Yahoo Hybrid', {'type': YAHOO_MAP_HYB, 'sphericalMercator':true} )); usedYahooHyb = true; } |
170 | 177 | break; |
171 | 178 | case 'yahoo-normal' : |
172 | | - if (!usedYahooNor){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Streets' ); usedYahooNor = true; } |
| 179 | + if (!usedYahooNor){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Streets', {'sphericalMercator':true} ); usedYahooNor = true; } |
173 | 180 | break; |
174 | 181 | case 'yahoo-satellite' : |
175 | | - if (!usedYahooSat){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Satellite', {'type': YAHOO_MAP_SAT} ); usedYahooSat = true; } |
| 182 | + if (!usedYahooSat){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Satellite', {'type': YAHOO_MAP_SAT, 'sphericalMercator':true} ); usedYahooSat = true; } |
176 | 183 | break; |
177 | 184 | case 'yahoo-hybrid' : |
178 | | - if (!usedYahooHyb){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Hybrid', {'type': YAHOO_MAP_HYB} ); usedYahooHyb = true; } |
| 185 | + if (!usedYahooHyb){ newLayer = new OpenLayers.Layer.Yahoo( 'Yahoo Hybrid', {'type': YAHOO_MAP_HYB, 'sphericalMercator':true} ); usedYahooHyb = true; } |
179 | 186 | break; |
180 | 187 | case 'openlayers' : case 'open-layers' : |
181 | | - if (!usedOLWMS){ newLayer = new OpenLayers.Layer.WMS( 'OpenLayers WMS', 'http://labs.metacarta.com/wms/vmap0', {layers: 'basic'} ); usedOLWMS = true; } |
| 188 | + if (!usedOLWMS){ newLayer = new OpenLayers.Layer.WMS( 'OpenLayers WMS', 'http://labs.metacarta.com/wms/vmap0', {layers: 'basic', 'sphericalMercator':true} ); usedOLWMS = true; } |
182 | 189 | break; |
183 | 190 | case 'nasa' : |
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; } |
| 191 | + if (!usedNasa){ newLayer = new OpenLayers.Layer.WMS("NASA Global Mosaic", "http://t1.hypercube.telascience.org/cgi-bin/landsat7", {layers: "landsat7", 'sphericalMercator':true} ); usedNasa = true; } |
185 | 192 | break; |
186 | | - // FIXME: this will cause the OL API to mess itself up - other coordinate system? |
187 | | - |
188 | 193 | case 'osm' : case 'openstreetmap' : |
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; } |
| 194 | + if (!usedOSMarender){ map.addLayer(new OpenLayers.Layer.OSM.Osmarender("OSM arender")); usedOSMarender = true; } |
| 195 | + if (!usedOSMnik){ map.addLayer(new OpenLayers.Layer.OSM.Mapnik("OSM Mapnik"), {'sphericalMercator':true}); usedOSMnik = true; } |
| 196 | + if (!usedOSMcycle){ map.addLayer(new OpenLayers.Layer.OSM.CycleMap("Cycle Map"), {'sphericalMercator':true}); usedOSMcycle = true; } |
200 | 197 | break; |
| 198 | + case 'osmarender' : |
| 199 | + if (!usedOSMarender){ newLayer = new OpenLayers.Layer.OSM.Osmarender("OSM arender"); usedOSMarender = true; } |
| 200 | + break; |
201 | 201 | case 'osm-nik' : case 'osm-mapnik' : |
202 | | - if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.Mapnik("OSM Mapnik"); usedOSM = true; } |
| 202 | + if (!usedOSMnik){ newLayer = new OpenLayers.Layer.OSM.Mapnik("OSM Mapnik"); usedOSMnik = true; } |
203 | 203 | break; |
204 | 204 | case 'osm-cycle' : case 'osm-cyclemap' : |
205 | | - if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.CycleMap("Cycle Map"); usedOSM = true; } |
| 205 | + if (!usedOSMcycle){ newLayer = new OpenLayers.Layer.OSM.CycleMap("Cycle Map"); usedOSMcycle = true; } |
206 | 206 | break; |
207 | | - |
208 | 207 | } |
209 | 208 | |
210 | 209 | if (newLayer != null) { |
— | — | @@ -255,7 +254,6 @@ |
256 | 255 | |
257 | 256 | function getOLMarkerData(lon, lat, title, label) { |
258 | 257 | lonLat = new OpenLayers.LonLat(lon, lat) |
259 | | - //lonLat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")); |
260 | 258 | return { |
261 | 259 | lonlat: lonLat, |
262 | 260 | title: title, |
— | — | @@ -282,7 +280,7 @@ |
283 | 281 | } |
284 | 282 | |
285 | 283 | // Click event handler for updating the location of the marker |
286 | | - // TODO/FIXME: This will probably cause problems when used for multiple maps on one page. |
| 284 | + // TODO / FIXME: This will probably cause problems when used for multiple maps on one page. |
287 | 285 | OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { |
288 | 286 | defaultHandlerOptions: { |
289 | 287 | 'single': true, |