r54832 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54831‎ | r54832 | r54833 >
Date:00:24, 12 August 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.3
Modified paths:
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/OpenLayerFunctions.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/OpenLayers/OpenLayerFunctions.js
@@ -7,44 +7,26 @@
88 * @author Jeroen De Dauw
99 */
1010
11 -
1211 /**
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.
3713 * The resulting map is returned by the function but no further handling is required in most cases.
3814 */
3915 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),
4625 controls: []
4726 }
4827
 28+
 29+
 30+
4931 var map = new OpenLayers.Map(mapName, mapOptions);
5032
5133 // Add the controls
@@ -65,8 +47,63 @@
6648
6749 }
6850
 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) {
69105 // 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;
71108
72109 // Variables to prevent double adding of a base layer
73110 var usedNor = false; var usedSat = false; var usedHyb = false; var usedPhy = false; // Google types
@@ -91,7 +128,7 @@
92129 if (googleAPILoaded) {
93130 switch(mapTypes[i]) {
94131 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; }
96133 break;
97134 case 'google-satellite' :
98135 if (!usedSat){ newLayer = new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP /*, sphericalMercator:true */}); usedSat = true; }
@@ -103,7 +140,7 @@
104141 if (!usedPhy){ newLayer = new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP /*, sphericalMercator:true */}); usedPhy = true; }
105142 break;
106143 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; }
108145 if (!usedSat){ map.addLayer(new OpenLayers.Layer.Google( 'Google Satellite' , {type: G_SATELLITE_MAP /*, sphericalMercator:true */})); usedSat = true; }
109146 if (!usedHyb){ map.addLayer(new OpenLayers.Layer.Google( 'Google Hybrid' , {type: G_HYBRID_MAP /*, sphericalMercator:true */})); usedHyb = true; }
110147 if (!usedPhy){ map.addLayer(new OpenLayers.Layer.Google( 'Google Physical' , {type: G_PHYSICAL_MAP /*, sphericalMercator:true */})); usedPhy = true; }
@@ -115,29 +152,29 @@
116153 }
117154 break;
118155 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; }
122159 break;
123160 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; }
125162 case 'bing-satellite' :
126163 if (!usedBingSat){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Satellite' , {type: VEMapStyle.Aerial} ); usedBingSat = true; }
127164 case 'bing-hybrid' :
128165 if (!usedBingHyb){ newLayer = new OpenLayers.Layer.VirtualEarth( 'Bing Hybrid' , {type: VEMapStyle.Hybrid} ); usedBingHyb = true; }
129166 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; }
133170 break;
134171 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; }
136173 break;
137174 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; }
139176 break;
140177 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; }
142179 break;
143180 case 'openlayers' : case 'open-layers' :
144181 if (!usedOLWMS){ newLayer = new OpenLayers.Layer.WMS( 'OpenLayers WMS', 'http://labs.metacarta.com/wms/vmap0', {layers: 'basic'} ); usedOLWMS = true; }
@@ -146,9 +183,19 @@
147184 if (!usedNasa){ newLayer = new OpenLayers.Layer.WMS("NASA Global Mosaic", "http://t1.hypercube.telascience.org/cgi-bin/landsat7", {layers: "landsat7" /*, sphericalMercator:true */} ); usedNasa = true; }
148185 break;
149186 // FIXME: this will cause the OL API to mess itself up - other coordinate system?
150 - /*
 187+
151188 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; }
153200 break;
154201 case 'osm-nik' : case 'osm-mapnik' :
155202 if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.Mapnik("OSM Mapnik"); usedOSM = true; }
@@ -156,7 +203,7 @@
157204 case 'osm-cycle' : case 'osm-cyclemap' :
158205 if (!usedOSM){ newLayer = new OpenLayers.Layer.OSM.CycleMap("Cycle Map"); usedOSM = true; }
159206 break;
160 - */
 207+
161208 }
162209
163210 if (newLayer != null) {
@@ -171,37 +218,10 @@
172219 }
173220 */
174221 }
175 -
176 -
177222 }
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 -
201223 return map;
202224 }
203 -
204225
205 -
206226 function getOLMarker(markerLayer, markerData, projectionObject) {
207227 //markerData.lonlat.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
208228
@@ -243,7 +263,9 @@
244264 }
245265
246266
247 -function setOLPopupType(minWidth, minHeight) {
 267+function initOLSettings(minWidth, minHeight) {
 268+ OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
 269+ OpenLayers.Util.onImageLoadErrorColor = "transparent";
248270 OpenLayers.Feature.prototype.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {'autoSize': true, 'minSize': new OpenLayers.Size(minWidth, minHeight)});
249271 }
250272
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php
@@ -80,7 +80,7 @@
8181 $output .="<link rel='stylesheet' href='$egMapsIncludePath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
8282 <script type='$wgJsMimeType' src='$egMapsIncludePath/OpenLayers/OpenLayers/OpenLayers.js'></script>
8383 <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";
8585 }
8686 }
8787

Status & tagging log