Index: trunk/extensions/SlippyMap/SlippyMap.i18n.php |
— | — | @@ -34,6 +34,8 @@ |
35 | 35 | 'slippymap_osmlink' => 'http://www.openstreetmap.org/?lat=%1&lon=%2&zoom=%3', # do not translate or duplicate this message to other languages |
36 | 36 | 'slippymap_osmtext' => 'See this map on OpenStreetMap.org', |
37 | 37 | 'slippymap_code' => 'Wikicode for this map view:', |
| 38 | + 'slippymap_button_code' => 'Get wikicode', |
| 39 | + 'slippymap_resetview' => 'Reset view', |
38 | 40 | 'slippymap_license' => 'OpenStreetMap - CC-BY-SA-2.0', # do not translate or duplicate this message to other languages |
39 | 41 | ); |
40 | 42 | |
— | — | @@ -60,12 +62,14 @@ |
61 | 63 | 'slippymap_lonbig' => "Die geografische Länge darf nicht größer als 180 sein", |
62 | 64 | 'slippymap_lonsmall' => "Die geografische Länge darf nicht kleiner als -180 sein", |
63 | 65 | 'slippymap_zoomsmall' => "Der Zoomwert darf nicht negativ sein", |
64 | | - 'slippymap_zoom18' => "Der Zoomwert (z) kann nicht größer als 17 sein. Beachte, dass diese MediaWiki-Erweiterung die OpenStreetMap 'Osmarender'-Karte einbindet, die nicht höher als Zoom 17 geht. Die Mapnik-Karte ist auf openstreetmap.org verfügbar und geht bis Zoom 18.", |
65 | | - 'slippymap_zoombig' => "Der Zoomwert (z) kann nicht größer als 17 sein.", |
| 66 | + 'slippymap_zoom18' => "Der Zoomwert (z) darf nicht größer als 17 sein. Beachte, dass diese MediaWiki-Erweiterung die OpenStreetMap 'Osmarender'-Karte einbindet, die nicht höher als Zoom 17 geht. Die Mapnik-Karte ist auf openstreetmap.org verfügbar und geht bis Zoom 18.", |
| 67 | + 'slippymap_zoombig' => "Der Zoomwert (z) darf nicht größer als 17 sein.", |
66 | 68 | 'slippymap_invalidlayer' => "Ungültiger 'layer'-Wert „%1“", |
67 | 69 | 'slippymap_code' => 'Wikitext für diese Kartenansicht:', |
68 | 70 | 'slippymap_maperror' => "Kartenfehler:", |
69 | 71 | 'slippymap_osmtext' => 'Diese Karte auf OpenStreetMap.org ansehen', |
| 72 | + 'slippymap_button_code' => 'Zeige Wikicode', |
| 73 | + 'slippymap_resetview' => 'Zurücksetzen', |
70 | 74 | ); |
71 | 75 | |
72 | 76 | /** French (Français) |
Index: trunk/extensions/SlippyMap/SlippyMap.php |
— | — | @@ -33,6 +33,8 @@ |
34 | 34 | $wgAutoloadClasses['SlippyMap'] = dirname( __FILE__ ) . '/SlippyMap.class.php'; |
35 | 35 | $wgExtensionMessagesFiles['SlippyMap'] = dirname( __FILE__ ) . "/SlippyMap.i18n.php"; |
36 | 36 | |
| 37 | + # Bump this when updating OpenStreetMap.js to help update caches |
| 38 | + $wgSlippyMapVersion = 1; |
37 | 39 | |
38 | 40 | function wfslippymap() { |
39 | 41 | global $wgParser, $wgMapOfServiceUrl; |
Index: trunk/extensions/SlippyMap/SlippyMap.class.php |
— | — | @@ -24,8 +24,8 @@ |
25 | 25 | |
26 | 26 | # The callback function for converting the input text to HTML output |
27 | 27 | function parse( $input ) { |
28 | | - global $wgMapOfServiceUrl; |
29 | | - |
| 28 | + global $wgMapOfServiceUrl, $wgSlippyMapVersion; |
| 29 | + |
30 | 30 | wfLoadExtensionMessages( 'SlippyMap' ); |
31 | 31 | |
32 | 32 | //Parse pipe separated name value pairs (e.g. 'aaa=bbb|ccc=ddd') |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | $params[substr($paramString,0,$eqPos)] = trim(htmlspecialchars(substr($paramString,$eqPos+1))); |
41 | 41 | } |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | $lat = $params['lat']; |
45 | 45 | $lon = $params['lon']; |
46 | 46 | $zoom = $params['z']; |
— | — | @@ -47,28 +47,28 @@ |
48 | 48 | $height = $params['h']; |
49 | 49 | $layer = $params['layer']; |
50 | 50 | $marker = $params['marker']; |
51 | | - |
| 51 | + |
52 | 52 | $error=""; |
53 | | - |
| 53 | + |
54 | 54 | //default values (meaning these parameters can be missed out) |
55 | 55 | if ($width=='') $width ='450'; |
56 | 56 | if ($height=='') $height='320'; |
57 | 57 | if ($layer=='') $layer='mapnik'; |
58 | | - |
| 58 | + |
59 | 59 | if ($zoom=='') $zoom = $params['zoom']; //see if they used 'zoom' rather than 'z' (and allow it) |
60 | 60 | |
61 | 61 | $marker = ( $marker != '' && $marker != '0' ); |
62 | | - |
| 62 | + |
63 | 63 | //trim off the 'px' on the end of pixel measurement numbers (ignore if present) |
64 | 64 | if (substr($width,-2)=='px') $width = substr($width,0,-2); |
65 | 65 | if (substr($height,-2)=='px') $height = substr($height,0,-2); |
66 | | - |
| 66 | + |
67 | 67 | //Check required parameters values are provided |
68 | 68 | if ($lat=='') $error .= wfMsg( 'slippymap_latmissing' ); |
69 | 69 | if ($lon=='') $error .= wfMsg( 'slippymap_lonmissing' ); |
70 | 70 | if ($zoom=='') $error .= wfMsg( 'slippymap_zoommissing' ); |
71 | | - if ($params['long']!='') $error .= wfMsg( 'slippymap_longdepreciated' ); |
72 | | - |
| 71 | + if ( isset( $params['long'] ) ) $error .= wfMsg( 'slippymap_longdepreciated' ); |
| 72 | + |
73 | 73 | if ($error=='') { |
74 | 74 | //no errors so far. Now check the values |
75 | 75 | if (!is_numeric($width)) { |
— | — | @@ -105,10 +105,10 @@ |
106 | 106 | $error = wfMsg( 'slippymap_zoombig' ); |
107 | 107 | } |
108 | 108 | } |
109 | | - |
| 109 | + |
110 | 110 | //Find the tile server URL to use. Note that we could allow the user to override that with |
111 | 111 | //*any* tile server URL for more flexibility, but that might be a security concern. |
112 | | - |
| 112 | + |
113 | 113 | $layer = strtolower($layer); |
114 | 114 | $layerObjectDef = ''; |
115 | 115 | if ($layer=='osmarender') { |
— | — | @@ -120,12 +120,11 @@ |
121 | 121 | } else { |
122 | 122 | $error = wfMsg( 'slippymap_invalidlayer', htmlspecialchars($layer) ); |
123 | 123 | } |
124 | | - |
125 | | - |
| 124 | + |
126 | 125 | if ($error!="") { |
127 | 126 | //Something was wrong. Spew the error message and input text. |
128 | 127 | $output = ''; |
129 | | - $output .= "<font color=\"red\"><b>". wfMsg( 'slippymap_maperror' ). "</b> " . $error . "</font><br>"; |
| 128 | + $output .= "<span class=\"error\">". wfMsg( 'slippymap_maperror' ) . ' ' . $error . "</span><br />"; |
130 | 129 | $output .= htmlspecialchars($input); |
131 | 130 | } else { |
132 | 131 | //HTML output for the slippy map. |
— | — | @@ -133,7 +132,7 @@ |
134 | 133 | //otherwise MediaWiki adds <BR> tags, which is bad in the middle of block of javascript. |
135 | 134 | //There are other ways of fixing this, but not for MediaWiki v4 |
136 | 135 | //(See http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F) |
137 | | - |
| 136 | + |
138 | 137 | $output = '<script type="text/javascript"> var osm_fully_loaded=false;'; |
139 | 138 | |
140 | 139 | // defer loading of the javascript. Since the script is quite bit, it would delay |
— | — | @@ -143,22 +142,19 @@ |
144 | 143 | ' sc.src = "http://openlayers.org/api/OpenLayers.js";' . |
145 | 144 | ' document.body.appendChild( sc );' . |
146 | 145 | ' var sc = document.createElement("script");' . |
147 | | - ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co";'. |
| 146 | + ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co&' . $wgSlippyMapVersion . '";'. |
148 | 147 | ' document.body.appendChild( sc );' . |
149 | 148 | '} );'; |
150 | 149 | |
151 | | - |
152 | | - |
153 | | - |
154 | 150 | $output .= "var lon= $lon; var lat= $lat; var zoom= $zoom; var lonLat;"; |
155 | | - |
| 151 | + |
156 | 152 | $output .= 'var map; '; |
157 | | - |
| 153 | + |
158 | 154 | $output .= 'function lonLatToMercator(ll) { '; |
159 | 155 | $output .= ' var lon = ll.lon * 20037508.34 / 180; '; |
160 | 156 | $output .= ' var lat = Math.log (Math.tan ((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180); '; |
161 | 157 | $output .= ' lat = lat * 20037508.34 / 180; '; |
162 | | - |
| 158 | + |
163 | 159 | $output .= ' return new OpenLayers.LonLat(lon, lat); '; |
164 | 160 | $output .= '} '; |
165 | 161 | |
— | — | @@ -170,32 +166,31 @@ |
171 | 167 | $output .= ' lat = lat * 180 / Math.PI;'; |
172 | 168 | $output .= ' return new OpenLayers.LonLat(lon, lat); '; |
173 | 169 | $output .= ' } '; |
174 | | - |
| 170 | + |
175 | 171 | $output .= 'addOnloadHook( slippymap_init ); '; |
176 | | - |
| 172 | + |
177 | 173 | $output .= 'function slippymap_init() { '; |
178 | 174 | $output .= ' if (!osm_fully_loaded) { window.setTimeout("slippymap_init()",500); return 0; } ' ; |
179 | | - |
| 175 | + |
180 | 176 | $output .= ' map = new OpenLayers.Map("map", { '; |
181 | 177 | $output .= ' controls:[ '; |
182 | 178 | $output .= ' new OpenLayers.Control.Navigation(), '; |
183 | | - |
| 179 | + |
184 | 180 | if ($height>320) { |
185 | 181 | //Add the zoom bar control, except if the map is only little |
186 | 182 | $output .= ' new OpenLayers.Control.PanZoomBar(),'; |
187 | 183 | } else if ( $height > 140 ) { |
188 | 184 | $output .= ' new OpenLayers.Control.PanZoom(),'; |
189 | 185 | } |
190 | | - |
| 186 | + |
191 | 187 | $output .= ' new OpenLayers.Control.Attribution()], '; |
192 | 188 | $output .= ' maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), '; |
193 | 189 | $output .= " maxResolution:156543.0399, units:'meters', projection: \"EPSG:900913\"} ); "; |
194 | | - |
195 | | - |
| 190 | + |
196 | 191 | $output .= " layer = new " . $layerObjectDef; |
197 | | - |
| 192 | + |
198 | 193 | $output .= " map.addLayer(layer); "; |
199 | | - |
| 194 | + |
200 | 195 | $output .= " lonLat = lonLatToMercator(new OpenLayers.LonLat(lon, lat)); "; |
201 | 196 | |
202 | 197 | if ( $marker ) { |
— | — | @@ -206,10 +201,10 @@ |
207 | 202 | " var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/YELLOW.png',size,offset);" . |
208 | 203 | ' markers.addMarker(new OpenLayers.Marker( lonLat,icon)); '; |
209 | 204 | } |
210 | | - |
| 205 | + |
211 | 206 | $output .= " map.setCenter (lonLat, zoom); "; |
212 | 207 | $output .= " postmap = document.getElementById('postmap'); "; |
213 | | - $output .= " postmap.innerHTML = '<input type=\"button\" value=\"Reset view\" onmousedown=\"map.setCenter(lonLat, zoom);\" /><input type=\"button\" value=\"Get wikicode\" onmousedown=\"slippymap_getWikicode();\" \>'; "; |
| 208 | + $output .= " postmap.innerHTML = '<input type=\"button\" value=\"" . wfMsg( 'slippymap_resetview' ) . "\" onmousedown=\"map.setCenter(lonLat, zoom);\" /><input type=\"button\" value=\"" . wfMsg( 'slippymap_button_code' ) . "\" onmousedown=\"slippymap_getWikicode();\" \>'; "; |
214 | 209 | $output .= "} "; |
215 | 210 | |
216 | 211 | $output .= 'function slippymap_getWikicode() {'; |
— | — | @@ -218,18 +213,15 @@ |
219 | 214 | |
220 | 215 | $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>" ); '; |
221 | 216 | $output .= '}'; |
222 | | - |
| 217 | + |
223 | 218 | $output .= "</script> "; |
224 | | - |
225 | | - |
| 219 | + |
226 | 220 | $output .= '<div class="map">'; |
227 | 221 | $output .= "<div style=\"width: {$width}px; height:{$height}px; border-style:solid; border-width:1px; border-color:lightgrey;\" id=\"map\">"; |
228 | 222 | $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\">"; |
229 | 223 | $output .= "<img src=\"".$wgMapOfServiceUrl."lat=$lat&long=$lon&z=$zoom&w=$width&h=$height&format=jpeg\" width=\"$width\" height=\"$height\" border=\"0\"><br/>"; |
230 | 224 | $output .= '<span style="font-size:60%; background-color:white; position:relative; top:-15px; ">OpenStreetMap - CC-BY-SA-2.0</span>'; |
231 | 225 | $output .= '</a></noscript></div><div id="postmap"></div></div>'; |
232 | | - |
233 | | - |
234 | 226 | } |
235 | 227 | return $output; |
236 | 228 | } |