r53817 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53816‎ | r53817 | r53818 >
Date:17:55, 27 July 2009
Author:avar
Status:deferred
Tags:
Comment:
A bit of an unclean hack (can be set in the config file) for either using the OSM tileservers or Cassini
Modified paths:
  • /trunk/extensions/SlippyMap/SlippyMap.hook.php (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.js (deleted) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.php (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMapExportCgiBin.class.php (modified) (history)
  • /trunk/extensions/SlippyMap/js (added) (history)
  • /trunk/extensions/SlippyMap/js/SlippyMap.js (added) (history)

Diff [purge]

Index: trunk/extensions/SlippyMap/SlippyMap.js
@@ -1,211 +0,0 @@
2 -/*
3 - * @file
4 - *
5 - * @description
6 - *
7 - * OpenStreetMap SlippyMap - MediaWiki extension
8 - *
9 - * This defines what happens when <slippymap> tag is placed in the wikitext
10 - *
11 - * We show a map based on the lat/lon/zoom data passed in. This extension brings in
12 - * the OpenLayers javascript, to show a slippy map.
13 - *
14 - * Usage example:
15 - * <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender></slippymap>
16 - *
17 - * Tile images are not cached local to the wiki.
18 - * To acheive this (remove the OSM dependency) you might set up a squid proxy,
19 - * and modify the requests URLs here accordingly.
20 - *
21 - * This file should be placed in the mediawiki 'extensions' directory
22 - * ...and then it needs to be 'included' within LocalSettings.php
23 - *
24 - * @license
25 - *
26 - * Copyright 2008 Harry Wood, Jens Frank, Grant Slater, Raymond Spekking and others
27 - *
28 - * This program is free software; you can redistribute it and/or modify
29 - * it under the terms of the GNU General Public License as published by
30 - * the Free Software Foundation; either version 2 of the License, or
31 - * (at your option) any later version.
32 - *
33 - * This program is distributed in the hope that it will be useful,
34 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 - * GNU General Public License for more details.
37 - *
38 - * You should have received a copy of the GNU General Public License
39 - * along with this program; if not, write to the Free Software
40 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41 - *
42 - */
43 -
44 -OpenLayers.Lang.setCode(wgSlippyMapLanguageCode);
45 -
46 -var slippymaps = new Array();
47 -var mapId = 0;
48 -var layer = null;
49 -
50 -if (wgSlippyMapSlippyByDefault) {
51 - addOnloadHook(slippymap_init);
52 -}
53 -
54 -function slippymap_init() {
55 - for (i=0; i < slippymaps.length; i++) {
56 - slippymaps[i].init();
57 - }
58 -}
59 -
60 -function slippymap_map(mapId, mapParams) {
61 - var self = this;
62 - this.mapId = mapId;
63 -
64 - for (key in mapParams)
65 - this[key] = mapParams[key];
66 -
67 - var buttonsPanel = new OpenLayers.Control.Panel( { displayClass: "buttonsPanel" } );
68 - buttonsPanel.addControls([ new OpenLayers.Control.Button({
69 - title: wgSlippyMapButtonCode,
70 - displayClass: "getWikiCodeButton",
71 - trigger: function() { self.getWikicode(); }
72 - }),
73 - new OpenLayers.Control.Button({
74 - title: wgSlippyMapResetview,
75 - displayClass: "resetButton",
76 - trigger: function() { self.resetPosition(); }
77 - })
78 - ]);
79 -
80 - this.mapOptions = { controls: [ new OpenLayers.Control.Navigation(),
81 - new OpenLayers.Control.ArgParser(),
82 - new OpenLayers.Control.Attribution(),
83 - new OpenLayers.Control.LayerSwitcher(),
84 - buttonsPanel ]
85 - };
86 -
87 - /* Add the zoom bar control, except if the map is only little */
88 - if (this.height > 320)
89 - this.mapOptions.controls.push(new OpenLayers.Control.PanZoomBar());
90 - else if (this.height > 140)
91 - this.mapOptions.controls.push(new OpenLayers.Control.PanZoom());
92 -}
93 -
94 -slippymap_map.prototype.init = function() {
95 - /* Swap out against the preview image */
96 - var previewImage = document.getElementById('mapPreview' + this.mapId);
97 - if (previewImage)
98 - previewImage.style.display = 'none';
99 -
100 - switch(this.mode) {
101 - case "satellite":
102 - /* Nasa WorldWind */
103 - this.map = this.ww_create(this.mapId, this.lon, this.lat, this.zoom, this.layer);
104 - break;
105 - case "wms":
106 - /* wms map */
107 - this.map = this.wms_create(this.mapId, this.lon, this.lat, this.zoom, this.layer);
108 - break;
109 - default:
110 - /* OpenStreetMap */
111 - this.map = this.osm_create(this.mapId, this.lon, this.lat, this.zoom);
112 - }
113 -
114 - if (this.marker) {
115 - var markers = new OpenLayers.Layer.Markers( "Markers" );
116 - this.map.addLayer(markers);
117 - var icon = OpenLayers.Marker.defaultIcon();
118 - markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(this.lon, this.lat).transform(new OpenLayers.Projection('EPSG:4326'), this.map.getProjectionObject()), icon));
119 - }
120 -}
121 -
122 -slippymap_map.prototype.osm_create = function(mapId, lon, lat, zoom) {
123 - var map;
124 - var osmLayer;
125 - map = new OpenLayers.Map('map' + mapId, this.mapOptions /* all provided for by OSM.js */);
126 -
127 - if (this.layer == 'mapnik' ) {
128 - osmLayer = new OpenLayers.Layer.OSM();
129 - } else if (this.layer == 'osmarender' ) {
130 - osmLayer = new OpenLayers.Layer.OSM("t@h",
131 - [ "http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
132 - "http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
133 - "http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"]);
134 - } else if (this.layer == 'maplint' ) {
135 - osmLayer = new OpenLayers.Layer.OSM("maplint",
136 - [ "http://a.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
137 - "http://b.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
138 - "http://c.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png"]);
139 - } else if (this.layer == 'cycle' ) {
140 - osmLayer = new OpenLayers.Layer.OSM("cycle",
141 - [ "http://a.thunderflames.org/tiles/cycle/${z}/${x}/${y}.png",
142 - "http://b.thunderflames.org/tiles/cycle/${z}/${x}/${y}.png",
143 - "http://c.thunderflames.org/tiles/cycle/${z}/${x}/${y}.png"]);
144 - }
145 -
146 - map.addLayers([osmLayer]);
147 - map.setCenter(new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection('EPSG:4326'), map.getProjectionObject()), zoom);
148 - return map;
149 -}
150 -
151 -/* Nasa WorldWind
152 - * TODO make configurable
153 - */
154 -slippymap_map.prototype.ww_create = function(mapId, lon, lat, zoom, layer) {
155 - var map;
156 - var wwLayer;
157 - this.mapOptions.maxResolution = 1.6;
158 - this.mapOptions.numZoomLevels = 21;
159 -
160 - map = new OpenLayers.Map('map' + mapId, this.mapOptions);
161 -
162 - if (this.layer == 'urban' ) {
163 - wwLayer = new OpenLayers.Layer.WorldWind( 'urban',
164 - "http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9,
165 - {T:"104"}, { tileSize: new OpenLayers.Size(512,512) });
166 - // TODO
167 - } else if (this.layer == 'landsat') {
168 - // TODO
169 - } else if (this.layer == 'bluemarble') {
170 -
171 - }
172 -
173 - map.addLayers([wwLayer]);
174 - map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
175 - return map;
176 -}
177 -
178 -/* WMS custom map
179 - * TODO make configurable
180 - */
181 -slippymap_map.prototype.wms_create = function(mapId, lon, lat, zoom) {
182 - /* ? */
183 - var map;
184 - this.mapOptions.maxResolution = 360/512/16;
185 - this.mapOptions.numZoomLevels = 15;
186 - map = new OpenLayers.Map('map' + mapId, this.mapOptions);
187 - wmsLayer = new OpenLayers.Layer.WMS(
188 - "Fire detects", "http://map.ngdc.noaa.gov/wmsconnector/com.esri.wms.Esrimap/firedetects",
189 - {
190 - layers: 'firedetects',
191 - format: 'image/png'
192 - });
193 - map.addLayers([wmsLayer]);
194 - map.setCenter(new OpenLayers.LonLat( lon, lat ), zoom);
195 - return map;
196 -}
197 -
198 -slippymap_map.prototype.resetPosition = function() {
199 - this.map.setCenter(new OpenLayers.LonLat(this.lon, this.lat).transform(new OpenLayers.Projection('EPSG:4326'), this.map.getProjectionObject()), this.zoom);
200 -}
201 -
202 -slippymap_map.prototype.getWikicode = function() {
203 - LL = this.map.getCenter().transform(this.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
204 - Z = this.map.getZoom();
205 - size = this.map.getSize();
206 -
207 - prompt(
208 - wgSlippyMapCode,
209 - "<slippymap lat=" + LL.lat + " lon=" + LL.lon + " zoom=" + Z + " width=" + size.w + " height=" + size.h + " mode=" + this.mode + " layer=" + this.layer + (this.marker == 0 ? "" : " marker=" + this.marker) + " />"
210 - );
211 -}
212 -
Index: trunk/extensions/SlippyMap/SlippyMap.hook.php
@@ -26,6 +26,7 @@
2727
2828 public function __construct() {
2929 global $wgParser, $wgHooks, $wgOut, $wgScriptPath, $wgStyleVersion;
 30+ global $wgSlippyMapJs;
3031
3132 // Load i18n
3233 self::loadMessages();
@@ -38,7 +39,7 @@
3940
4041 // Add JavaScript files to <head>
4142 $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/OpenLayers/public/OpenLayers.js?' . $wgStyleVersion );
42 - $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/SlippyMap.js?' . $wgStyleVersion );
 43+ $wgOut->addScriptFile( $wgScriptPath . '/extensions/SlippyMap/js/' . $wgSlippyMapJs . '?' . $wgStyleVersion );
4344
4445 // Add our CSS to <head>
4546 $wgOut->addExtensionStyle( $wgScriptPath . '/extensions/SlippyMap/SlippyMap.css?' . $wgStyleVersion );
Index: trunk/extensions/SlippyMap/SlippyMap.php
@@ -65,12 +65,46 @@
6666 */
6767
6868 /**
 69+ * This is a HACK. This JS should be automatically generated by a
 70+ * script or configured dynamically with generated JS variables.
 71+ */
 72+//$wgSlippyMapJs = 'SlippyMap.js';
 73+$wgSlippyMapJs = 'SlippyMapCassini.js';
 74+
 75+/**
6976 * $wgSlippyMapModes
7077 *
7178 * The keys in the array are allowed "mode=" values as passed to the
7279 * <slippymap> tag, and the values are the configuration for the mode.
7380 */
7481 $wgSlippyMapModes = array(
 82+ 'osm-wm' => array(
 83+ // First layer = default
 84+ 'layers' => array( 'osm-like' ),
 85+
 86+ // Default "zoom=" argument
 87+ 'defaultZoomLevel' => 14,
 88+
 89+ 'static_rendering' => array(
 90+ 'type' => 'SlippyMapExportCgiBin',
 91+ 'options' => array(
 92+ 'base_url' => 'http://localhost/cgi-bin/export',
 93+
 94+ 'format' => 'png',
 95+ 'numZoomLevels' => 19,
 96+ 'maxResolution' => 156543.0339,
 97+ 'unit' => 'm',
 98+ 'sphericalMercator' => true,
 99+
 100+ // More GET arguments
 101+ 'get_args' => array(
 102+ // Will use $wgContLang->getCode()
 103+ 'locale' => true,
 104+ 'maptype' => 'osm-like'
 105+ ),
 106+ ),
 107+ ),
 108+ ),
75109 'osm' => array(
76110 // First layer = default
77111 'layers' => array( 'mapnik', 'osmarender', 'maplint', 'cycle' ),
Index: trunk/extensions/SlippyMap/SlippyMapExportCgiBin.class.php
@@ -35,12 +35,23 @@
3636 }
3737
3838 public function getUrl() {
39 - return
 39+ global $wgContLang;
 40+
 41+ $args =
4042 $this->options['base_url']
4143 . '?'
4244 . 'bbox=' . implode( ',', $this->bounds )
4345 . '&amp;scale=' . $this->scale
4446 . '&amp;format=' . $this->options['format'];
 47+
 48+ // Hack to support my custom cgi-bin/export script
 49+ if ( isset( $this->options['get_args'] ) ) {
 50+ $args .=
 51+ '&amp;maptype=' . $this->options['get_args']['maptype']
 52+ . '&amp;locale=' . $wgContLang->getCode();
 53+ }
 54+
 55+ return $args;
4556 }
4657
4758 /**
Index: trunk/extensions/SlippyMap/js/SlippyMap.js
@@ -0,0 +1,211 @@
 2+/*
 3+ * @file
 4+ *
 5+ * @description
 6+ *
 7+ * OpenStreetMap SlippyMap - MediaWiki extension
 8+ *
 9+ * This defines what happens when <slippymap> tag is placed in the wikitext
 10+ *
 11+ * We show a map based on the lat/lon/zoom data passed in. This extension brings in
 12+ * the OpenLayers javascript, to show a slippy map.
 13+ *
 14+ * Usage example:
 15+ * <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender></slippymap>
 16+ *
 17+ * Tile images are not cached local to the wiki.
 18+ * To acheive this (remove the OSM dependency) you might set up a squid proxy,
 19+ * and modify the requests URLs here accordingly.
 20+ *
 21+ * This file should be placed in the mediawiki 'extensions' directory
 22+ * ...and then it needs to be 'included' within LocalSettings.php
 23+ *
 24+ * @license
 25+ *
 26+ * Copyright 2008 Harry Wood, Jens Frank, Grant Slater, Raymond Spekking and others
 27+ *
 28+ * This program is free software; you can redistribute it and/or modify
 29+ * it under the terms of the GNU General Public License as published by
 30+ * the Free Software Foundation; either version 2 of the License, or
 31+ * (at your option) any later version.
 32+ *
 33+ * This program is distributed in the hope that it will be useful,
 34+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 35+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 36+ * GNU General Public License for more details.
 37+ *
 38+ * You should have received a copy of the GNU General Public License
 39+ * along with this program; if not, write to the Free Software
 40+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 41+ *
 42+ */
 43+
 44+OpenLayers.Lang.setCode(wgSlippyMapLanguageCode);
 45+
 46+var slippymaps = new Array();
 47+var mapId = 0;
 48+var layer = null;
 49+
 50+if (wgSlippyMapSlippyByDefault) {
 51+ addOnloadHook(slippymap_init);
 52+}
 53+
 54+function slippymap_init() {
 55+ for (i=0; i < slippymaps.length; i++) {
 56+ slippymaps[i].init();
 57+ }
 58+}
 59+
 60+function slippymap_map(mapId, mapParams) {
 61+ var self = this;
 62+ this.mapId = mapId;
 63+
 64+ for (key in mapParams)
 65+ this[key] = mapParams[key];
 66+
 67+ var buttonsPanel = new OpenLayers.Control.Panel( { displayClass: "buttonsPanel" } );
 68+ buttonsPanel.addControls([ new OpenLayers.Control.Button({
 69+ title: wgSlippyMapButtonCode,
 70+ displayClass: "getWikiCodeButton",
 71+ trigger: function() { self.getWikicode(); }
 72+ }),
 73+ new OpenLayers.Control.Button({
 74+ title: wgSlippyMapResetview,
 75+ displayClass: "resetButton",
 76+ trigger: function() { self.resetPosition(); }
 77+ })
 78+ ]);
 79+
 80+ this.mapOptions = { controls: [ new OpenLayers.Control.Navigation(),
 81+ new OpenLayers.Control.ArgParser(),
 82+ new OpenLayers.Control.Attribution(),
 83+ new OpenLayers.Control.LayerSwitcher(),
 84+ buttonsPanel ]
 85+ };
 86+
 87+ /* Add the zoom bar control, except if the map is only little */
 88+ if (this.height > 320)
 89+ this.mapOptions.controls.push(new OpenLayers.Control.PanZoomBar());
 90+ else if (this.height > 140)
 91+ this.mapOptions.controls.push(new OpenLayers.Control.PanZoom());
 92+}
 93+
 94+slippymap_map.prototype.init = function() {
 95+ /* Swap out against the preview image */
 96+ var previewImage = document.getElementById('mapPreview' + this.mapId);
 97+ if (previewImage)
 98+ previewImage.style.display = 'none';
 99+
 100+ switch(this.mode) {
 101+ case "satellite":
 102+ /* Nasa WorldWind */
 103+ this.map = this.ww_create(this.mapId, this.lon, this.lat, this.zoom, this.layer);
 104+ break;
 105+ case "wms":
 106+ /* wms map */
 107+ this.map = this.wms_create(this.mapId, this.lon, this.lat, this.zoom, this.layer);
 108+ break;
 109+ default:
 110+ /* OpenStreetMap */
 111+ this.map = this.osm_create(this.mapId, this.lon, this.lat, this.zoom);
 112+ }
 113+
 114+ if (this.marker) {
 115+ var markers = new OpenLayers.Layer.Markers( "Markers" );
 116+ this.map.addLayer(markers);
 117+ var icon = OpenLayers.Marker.defaultIcon();
 118+ markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(this.lon, this.lat).transform(new OpenLayers.Projection('EPSG:4326'), this.map.getProjectionObject()), icon));
 119+ }
 120+}
 121+
 122+slippymap_map.prototype.osm_create = function(mapId, lon, lat, zoom) {
 123+ var map;
 124+ var osmLayer;
 125+ map = new OpenLayers.Map('map' + mapId, this.mapOptions /* all provided for by OSM.js */);
 126+
 127+ if (this.layer == 'mapnik' ) {
 128+ osmLayer = new OpenLayers.Layer.OSM();
 129+ } else if (this.layer == 'osmarender' ) {
 130+ osmLayer = new OpenLayers.Layer.OSM("t@h",
 131+ [ "http://a.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
 132+ "http://b.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png",
 133+ "http://c.tah.openstreetmap.org/Tiles/tile/${z}/${x}/${y}.png"]);
 134+ } else if (this.layer == 'maplint' ) {
 135+ osmLayer = new OpenLayers.Layer.OSM("maplint",
 136+ [ "http://a.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
 137+ "http://b.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png",
 138+ "http://c.tah.openstreetmap.org/Tiles/maplint/${z}/${x}/${y}.png"]);
 139+ } else if (this.layer == 'cycle' ) {
 140+ osmLayer = new OpenLayers.Layer.OSM("cycle",
 141+ [ "http://a.thunderflames.org/tiles/cycle/${z}/${x}/${y}.png",
 142+ "http://b.thunderflames.org/tiles/cycle/${z}/${x}/${y}.png",
 143+ "http://c.thunderflames.org/tiles/cycle/${z}/${x}/${y}.png"]);
 144+ }
 145+
 146+ map.addLayers([osmLayer]);
 147+ map.setCenter(new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection('EPSG:4326'), map.getProjectionObject()), zoom);
 148+ return map;
 149+}
 150+
 151+/* Nasa WorldWind
 152+ * TODO make configurable
 153+ */
 154+slippymap_map.prototype.ww_create = function(mapId, lon, lat, zoom, layer) {
 155+ var map;
 156+ var wwLayer;
 157+ this.mapOptions.maxResolution = 1.6;
 158+ this.mapOptions.numZoomLevels = 21;
 159+
 160+ map = new OpenLayers.Map('map' + mapId, this.mapOptions);
 161+
 162+ if (this.layer == 'urban' ) {
 163+ wwLayer = new OpenLayers.Layer.WorldWind( 'urban',
 164+ "http://worldwind25.arc.nasa.gov/tile/tile.aspx?", .8, 9,
 165+ {T:"104"}, { tileSize: new OpenLayers.Size(512,512) });
 166+ // TODO
 167+ } else if (this.layer == 'landsat') {
 168+ // TODO
 169+ } else if (this.layer == 'bluemarble') {
 170+
 171+ }
 172+
 173+ map.addLayers([wwLayer]);
 174+ map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
 175+ return map;
 176+}
 177+
 178+/* WMS custom map
 179+ * TODO make configurable
 180+ */
 181+slippymap_map.prototype.wms_create = function(mapId, lon, lat, zoom) {
 182+ /* ? */
 183+ var map;
 184+ this.mapOptions.maxResolution = 360/512/16;
 185+ this.mapOptions.numZoomLevels = 15;
 186+ map = new OpenLayers.Map('map' + mapId, this.mapOptions);
 187+ wmsLayer = new OpenLayers.Layer.WMS(
 188+ "Fire detects", "http://map.ngdc.noaa.gov/wmsconnector/com.esri.wms.Esrimap/firedetects",
 189+ {
 190+ layers: 'firedetects',
 191+ format: 'image/png'
 192+ });
 193+ map.addLayers([wmsLayer]);
 194+ map.setCenter(new OpenLayers.LonLat( lon, lat ), zoom);
 195+ return map;
 196+}
 197+
 198+slippymap_map.prototype.resetPosition = function() {
 199+ this.map.setCenter(new OpenLayers.LonLat(this.lon, this.lat).transform(new OpenLayers.Projection('EPSG:4326'), this.map.getProjectionObject()), this.zoom);
 200+}
 201+
 202+slippymap_map.prototype.getWikicode = function() {
 203+ LL = this.map.getCenter().transform(this.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
 204+ Z = this.map.getZoom();
 205+ size = this.map.getSize();
 206+
 207+ prompt(
 208+ wgSlippyMapCode,
 209+ "<slippymap lat=" + LL.lat + " lon=" + LL.lon + " zoom=" + Z + " width=" + size.w + " height=" + size.h + " mode=" + this.mode + " layer=" + this.layer + (this.marker == 0 ? "" : " marker=" + this.marker) + " />"
 210+ );
 211+}
 212+
Property changes on: trunk/extensions/SlippyMap/js/SlippyMap.js
___________________________________________________________________
Name: svn:mergeinfo
1213 +
Name: svn:eol-style
2214 + native

Status & tagging log