r37976 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37975‎ | r37976 | r37977 >
Date:21:14, 23 July 2008
Author:jeluf
Status:old
Tags:
Comment:
Changes by Grant Slater:
- Updated Tiles@Home urls to current
- Removed lonLatToMercator/MercatorToLonLat dependancy, use OL instead
- Minor quoting tweaks
Modified paths:
  • /trunk/extensions/SlippyMap/OpenStreetMap.js (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SlippyMap/OpenStreetMap.js
@@ -143,9 +143,9 @@
144144 */
145145 initialize: function(name, options) {
146146 var url = [
147 - "http://a.tah.openstreetmap.org/Tiles/tile.php/",
148 - "http://b.tah.openstreetmap.org/Tiles/tile.php/",
149 - "http://c.tah.openstreetmap.org/Tiles/tile.php/"
 147+ "http://a.tah.openstreetmap.org/Tiles/tile/",
 148+ "http://b.tah.openstreetmap.org/Tiles/tile/",
 149+ "http://c.tah.openstreetmap.org/Tiles/tile/"
150150 ];
151151 options = OpenLayers.Util.extend({ numZoomLevels: 18 }, options);
152152 var newArguments = [name, url, options];
@@ -199,9 +199,9 @@
200200 */
201201 initialize: function(name, options) {
202202 var url = [
203 - "http://d.tah.openstreetmap.org/Tiles/maplint.php/",
204 - "http://e.tah.openstreetmap.org/Tiles/maplint.php/",
205 - "http://f.tah.openstreetmap.org/Tiles/maplint.php/"
 203+ "http://d.tah.openstreetmap.org/Tiles/maplint/",
 204+ "http://e.tah.openstreetmap.org/Tiles/maplint/",
 205+ "http://f.tah.openstreetmap.org/Tiles/maplint/"
206206 ];
207207 options = OpenLayers.Util.extend({ numZoomLevels: 18, isBaseLayer: false, visibility: false }, options);
208208 var newArguments = [name, url, options];
Index: trunk/extensions/SlippyMap/SlippyMap.class.php
@@ -63,7 +63,7 @@
6464 $marker = '';
6565 }
6666
67 - $error="";
 67+ $error='';
6868
6969 //default values (meaning these parameters can be missed out)
7070 if ($width=='') $width ='450';
@@ -77,8 +77,8 @@
7878 $marker = ( $marker != '' && $marker != '0' );
7979
8080 //trim off the 'px' on the end of pixel measurement numbers (ignore if present)
81 - if (substr($width,-2)=='px') $width = substr($width,0,-2);
82 - if (substr($height,-2)=='px') $height = substr($height,0,-2);
 81+ if (substr($width,-2)=='px') $width = (int) substr($width,0,-2);
 82+ if (substr($height,-2)=='px') $height = (int) substr($height,0,-2);
8383
8484 //Check required parameters values are provided
8585 if ( $lat=='' ) $error .= wfMsg( 'slippymap_latmissing' );
@@ -155,34 +155,17 @@
156156 // page loading and rendering dramatically
157157 $output .= 'addOnloadHook( function() { ' .
158158 ' var sc = document.createElement("script");' .
159 - ' sc.src = "http://openlayers.org/api/OpenLayers.js";' .
 159+ ' sc.src = "http://www.openlayers.org/api/OpenLayers.js";' .
160160 ' document.body.appendChild( sc );' .
161161 ' var sc = document.createElement("script");' .
162162 ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co&' . $wgSlippyMapVersion . '";'.
163163 ' document.body.appendChild( sc );' .
164164 '} );';
165165
166 - $output .= "var lon= $lon; var lat= $lat; var zoom= $zoom; var lonLat;";
 166+ $output .= "var lon= ${lon}; var lat= ${lat}; var zoom= ${zoom}; var lonLat;";
167167
168168 $output .= 'var map; ';
169169
170 - $output .= 'function lonLatToMercator(ll) { ';
171 - $output .= ' var lon = ll.lon * 20037508.34 / 180; ';
172 - $output .= ' var lat = Math.log (Math.tan ((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180); ';
173 - $output .= ' lat = lat * 20037508.34 / 180; ';
174 -
175 - $output .= ' return new OpenLayers.LonLat(lon, lat); ';
176 - $output .= '} ';
177 -
178 - $output .= 'function MercatorToLonLat(ll) { ';
179 - $output .= ' var lon = ll.lon / 20037508.34 * 180; ';
180 - $output .= ' var lat = ll.lat / 20037508.34 * 180 * ( Math.PI / 180 ); ';
181 - $output .= ' lat = ( Math.pow(Math.E, lat) - Math.pow(Math.E, -lat) ) / 2; ';
182 - $output .= ' lat = Math.atan( lat ); ';
183 - $output .= ' lat = lat * 180 / Math.PI;';
184 - $output .= ' return new OpenLayers.LonLat(lon, lat); ';
185 - $output .= ' } ';
186 -
187170 $output .= 'addOnloadHook( slippymap_init ); ';
188171
189172 $output .= 'function slippymap_init() { ';
@@ -201,13 +184,13 @@
202185
203186 $output .= ' new OpenLayers.Control.Attribution()], ';
204187 $output .= ' maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), ';
205 - $output .= " maxResolution:156543.0399, units:'meters', projection: \"EPSG:900913\"} ); ";
 188+ $output .= ' maxResolution:156543.0399, units:\'meters\', projection: "EPSG:900913"} ); ';
206189
207 - $output .= " layer = new " . $layerObjectDef;
 190+ $output .= ' layer = new ' . $layerObjectDef;
208191
209 - $output .= " map.addLayer(layer); ";
 192+ $output .= ' map.addLayer(layer); ';
210193
211 - $output .= " lonLat = lonLatToMercator(new OpenLayers.LonLat(lon, lat)); ";
 194+ $output .= ' lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); ';
212195
213196 if ( $marker ) {
214197 $output .= 'var markers = new OpenLayers.Layer.Markers( "Markers" ); ' .
@@ -218,11 +201,12 @@
219202 ' markers.addMarker(new OpenLayers.Marker( lonLat,icon)); ';
220203 }
221204
222 - $output .= " map.setCenter (lonLat, zoom); ";
223 - $output .= "} ";
 205+ $output .= ' map.setCenter (lonLat, zoom); ';
 206+ $output .= '} ';
224207
225208 $output .= 'function slippymap_getWikicode() {';
226 - $output .= ' LL = MercatorToLonLat(map.getCenter()); Z = map.getZoom();';
 209+ $output .= ' LL = map.getCenter().transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));';
 210+ $output .= ' Z = map.getZoom(); ';
227211 $output .= ' size = map.getSize();';
228212
229213 $output .= ' prompt( "' . wfMsg('slippymap_code') .'", "<slippymap h="+size.h+" w="+size.w+" z="+Z+" lat="+LL.lat+" lon="+LL.lon+" layer=mapnik marker=1></slippymap>" ); ';
@@ -233,9 +217,9 @@
234218 $output .= '<div class="map">';
235219 $output .= "<div style=\"width: {$width}px; height:{$height}px; border-style:solid; border-width:1px; border-color:lightgrey;\" id=\"map\">";
236220 $output .= "<noscript><a href=\"http://www.openstreetmap.org/?lat=$lat&lon=$lon&zoom=$zoom\" title=\"See this map on OpenStreetMap.org\" style=\"text-decoration:none\">";
237 - $output .= "<img src=\"".$wgMapOfServiceUrl."lat=$lat&long=$lon&z=$zoom&w=$width&h=$height&format=jpeg\" width=\"$width\" height=\"$height\" border=\"0\"><br/>";
238 - $output .= '<span style="font-size:60%; background-color:white; position:relative; top:-15px; ">OpenStreetMap - CC-BY-SA-2.0</span>';
239 - $output .= '</a></noscript></div><div id="postmap"><input type="button" value="' . wfMsg('slippymap_resetview') . '" onmousedown="map.setCenter(lonLat, zoom);" /><input type="button" value="' . wfMsg('slippymap_button_code') . '" onmousedown="slippymap_getWikicode();" /></div></div>';
 221+ $output .= "<img src=\"".$wgMapOfServiceUrl."lat=${lat}&long=${lon}&z=${zoom}&w=${width}&h=${height}&format=jpeg\" width=\"${width}\" height=\"${height}\" border=\"0\"><br/>";
 222+ $output .= '</a></noscript>';
 223+ $output .= '</div><div id="postmap"><input type="button" value="' . wfMsg('slippymap_resetview') . '" onmousedown="map.setCenter(lonLat, zoom);" /><input type="button" value="' . wfMsg('slippymap_button_code') . '" onmousedown="slippymap_getWikicode();" /></div></div>';
240224 }
241225 return $output;
242226 }

Status & tagging log