r58223 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58222‎ | r58223 | r58224 >
Date:21:18, 27 October 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php (modified) (history)
  • /trunk/extensions/Maps/MapUtilityFunctions.js (modified) (history)
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_MapFeature.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Utils.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMaps (added) (history)
  • /trunk/extensions/Maps/OpenStreetMaps/Maps_OSM.php (added) (history)
  • /trunk/extensions/Maps/OpenStreetMaps/Maps_OSMDispMap.php (added) (history)
  • /trunk/extensions/Maps/OpenStreetMaps/Maps_OSMDispPoint.php (added) (history)
  • /trunk/extensions/Maps/OpenStreetMaps/Maps_OSMUtils.php (added) (history)
  • /trunk/extensions/Maps/OpenStreetMaps/OSMFunctions.js (added) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php
@@ -54,9 +54,6 @@
5555
5656 MapsMapper::enforceArrayValues($this->layers);
5757 $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
58 -
59 - MapsUtils::makePxValue($this->width);
60 - MapsUtils::makePxValue($this->height);
6158
6259 $markerItems = array();
6360
@@ -77,9 +74,9 @@
7875
7976 $markersString = implode(',', $markerItems);
8077
81 - $this->output .= "<div id='$this->mapName' style='width: $this->width; height: $this->height; background-color: #cccccc;'></div>
 78+ $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div>
8279 <script type='$wgJsMimeType'> /*<![CDATA[*/
83 - addLoadEvent(
 80+ addOnloadHook(
8481 initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString])
8582 );
8683 /*]]>*/ </script>";
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php
@@ -54,13 +54,10 @@
5555
5656 MapsMapper::enforceArrayValues($this->layers);
5757 $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
58 -
59 - MapsUtils::makePxValue($this->width);
60 - MapsUtils::makePxValue($this->height);
6158
62 - $this->output .= "<div id='$this->mapName' style='width: $this->width; height: $this->height; background-color: #cccccc;'></div>
 59+ $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div>
6360 <script type='$wgJsMimeType'> /*<![CDATA[*/
64 - addLoadEvent(
 61+ addOnloadHook(
6562 initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[])
6663 );
6764 /*]]>*/ </script>";
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php
@@ -29,7 +29,7 @@
3030 * @param string $layer The layer to check (and load the dependencies for
3131 */
3232 public static function loadDependencyWhenNeeded(&$output, $layer) {
33 - global $wgJsMimeType;
 33+ global $wgJsMimeType, $wgStyleVersion;
3434 global $egGoogleMapsOnThisPage, $egMapsScriptPath;
3535
3636 switch ($layer) {
@@ -49,7 +49,7 @@
5050 if (!self::$loadedOL) { $output .= "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>\n"; self::$loadedOL = true; }
5151 break;
5252 case 'osm' : case 'openstreetmap' :
53 - if (!self::$loadedOSM) { $output .= "<script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OSM/OpenStreetMap.js'></script>\n"; self::$loadedOSM = true; }
 53+ if (!self::$loadedOSM) { $output .= "<script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OSM/OpenStreetMap.js?$wgStyleVersion'></script>\n"; self::$loadedOSM = true; }
5454 break;
5555 }
5656 }
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -154,7 +154,7 @@
155155 $this->centre_lat = $egMapsMapLat;
156156 $this->centre_lon = $egMapsMapLon;
157157 }
158 -
 158+
159159 /**
160160 * Parse the wiki text in the title and label values.
161161 *
@@ -167,7 +167,6 @@
168168
169169 /**
170170 * Escape the title and label text
171 - *
172171 */
173172 private function doEscaping() {
174173 $this->title = str_replace("'", "\'", $this->title);
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php
@@ -109,13 +109,13 @@
110110
111111 /**
112112 *
113 - * @param $coordsOrAddress
114 - * @return unknown_type
 113+ *
 114+ * @param string $coordsOrAddress
115115 */
116116 private static function isCoordinate($coordsOrAddress) {
117117 $coordRegexes = array( // TODO: change . to �, this won't work for some reason
118118 '/^\d{1,3}(\.\d{1,7})?,(\s)?\d{1,3}(\.\d{1,7})?$/', // Floats
119 - '/^(\d{1,2}.)(\d{2}\')?((\d{2}")?|(\d{2}\.\d{2}")?)(N|S)(\s)?(\d{1,2}.)(\d{2}\')?((\d{2}")?|(\d{2}\.\d{2}")?)(E|W)$/', // DMS // TODO: compress logic
 119+ '/^(\d{1,2}.)(\d{2}\')?((\d{2}")?|(\d{2}\.\d{2}")?)(N|S)(\s)?(\d{1,2}.)(\d{2}\')?((\d{2}")?|(\d{2}\.\d{2}")?)(E|W)$/', // DMS
120120 '/^(-)?\d{1,3}(|\.\d{1,7}).,(\s)?(-)?(\s)?\d{1,3}(|\.\d{1,7}).$/', // DD
121121 '/(-)?\d{1,3}.\d{1,3}(\.\d{1,7}\')?,(\s)?(-)?\d{1,3}.\d{1,3}(\.\d{1,7}\')?$/', // DM
122122 );
Index: trunk/extensions/Maps/Maps.php
@@ -23,7 +23,7 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('Maps_VERSION', '0.4 a8');
 27+define('Maps_VERSION', '0.4 a9');
2828
2929 $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
3030 $egMapsIP = $IP . '/extensions/Maps';
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -64,7 +64,7 @@
6565
6666 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
6767 <script type="$wgJsMimeType"> /*<![CDATA[*/
68 -addLoadEvent(
 68+addOnloadHook(
6969 initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [])
7070 );
7171 /*]]>*/ </script>
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php
@@ -115,7 +115,7 @@
116116 * @param string $output
117117 */
118118 public static function addGMapDependencies(&$output) {
119 - global $wgJsMimeType, $wgLang, $wgOut;
 119+ global $wgJsMimeType, $wgLang, $wgStyleVersion;
120120 global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage;
121121
122122 if (empty($egGoogleMapsOnThisPage)) {
@@ -123,11 +123,9 @@
124124
125125 MapsGoogleMapsUtils::validateGoogleMapsKey();
126126
127 - $wgOut->addScriptFile($egMapsScriptPath . '/GoogleMaps/GoogleMapFunctions.js');
128 -
129127 // TODO: use strbuilder for performance gain?
130128 $output .= "<script src='http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl={$wgLang->getCode()}' type='$wgJsMimeType'></script>
131 - <script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions.js'></script>";
 129+ <script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions.js?$wgStyleVersion'></script>";
132130 }
133131 }
134132
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -85,7 +85,7 @@
8686
8787 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
8888 <script type="$wgJsMimeType"> /*<![CDATA[*/
89 -addLoadEvent(
 89+addOnloadHook(
9090 initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString])
9191 );
9292 /*]]>*/ </script>
Index: trunk/extensions/Maps/Maps_MapFeature.php
@@ -1,7 +1,7 @@
22 <?php
33
44 /**
5 - * MapsMapFeature bundles some base functionallity for all general mapping feature classes
 5+ * MapsMapFeature bundles some base functionallity for all general mapping feature classes.
66 *
77 * @file Maps_MapFeature.php
88 * @ingroup Maps
@@ -67,7 +67,10 @@
6868 }
6969 }
7070
 71+ // TODO: refactor down - not every mapping feature/service should support a controls parameter
7172 MapsMapper::enforceArrayValues($this->controls);
 73+
 74+ MapsUtils::makeMapSizeValid($this->width, $this->height);
7275 }
7376
7477 /**
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -53,9 +53,6 @@
5454 $this->type = MapsYahooMapsUtils::getYMapType($this->type, true);
5555
5656 $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
57 -
58 - MapsUtils::makePxValue($this->width);
59 - MapsUtils::makePxValue($this->height);
6057
6158 $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
6259
@@ -83,10 +80,10 @@
8481 $typesString = MapsYahooMapsUtils::createTypesString($this->types);
8582
8683 $this->output .= <<<END
87 - <div id="$this->mapName" style="width: $this->width; height: $this->height;"></div>
 84+ <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div>
8885
8986 <script type="$wgJsMimeType">/*<![CDATA[*/
90 - addLoadEvent(
 87+ addOnloadHook(
9188 initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString])
9289 );
9390 /*]]>*/</script>
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php
@@ -53,9 +53,6 @@
5454 $this->type = MapsYahooMapsUtils::getYMapType($this->type, true);
5555
5656 $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
57 -
58 - MapsUtils::makePxValue($this->width);
59 - MapsUtils::makePxValue($this->height);
6057
6158 $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
6259
@@ -64,10 +61,10 @@
6562 $typesString = MapsYahooMapsUtils::createTypesString($this->types);
6663
6764 $this->output .= <<<END
68 - <div id="$this->mapName" style="width: $this->width; height: $this->height;"></div>
 65+ <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div>
6966
7067 <script type="$wgJsMimeType">/*<![CDATA[*/
71 - addLoadEvent(
 68+ addOnloadHook(
7269 initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [])
7370 );
7471 /*]]>*/</script>
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php
@@ -80,13 +80,13 @@
8181 * @param string $output
8282 */
8383 public static function addYMapDependencies(&$output) {
84 - global $wgJsMimeType;
 84+ global $wgJsMimeType, $wgStyleVersion;
8585 global $egYahooMapsKey, $egMapsScriptPath, $egYahooMapsOnThisPage;
8686
8787 if (empty($egYahooMapsOnThisPage)) {
8888 $egYahooMapsOnThisPage = 0;
8989 $output .= "<script type='$wgJsMimeType' src='http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=$egYahooMapsKey'></script>
90 - <script type='$wgJsMimeType' src='$egMapsScriptPath/YahooMaps/YahooMapFunctions.js'></script>";
 90+ <script type='$wgJsMimeType' src='$egMapsScriptPath/YahooMaps/YahooMapFunctions.js?$wgStyleVersion'></script>";
9191 }
9292 }
9393
Index: trunk/extensions/Maps/Maps.i18n.php
@@ -30,6 +30,7 @@
3131 'maps_googlemaps' => 'Google Maps',
3232 'maps_yahoomaps' => 'Yahoo! Maps',
3333 'maps_openlayers' => 'OpenLayers',
 34+ 'maps_osm' => 'OpenStreetMaps',
3435 );
3536
3637 /** Message documentation (Message documentation)
Index: trunk/extensions/Maps/MapUtilityFunctions.js
@@ -9,6 +9,7 @@
1010 * @author Jeroen De Dauw
1111 */
1212
 13+/*
1314 function addLoadEvent(func) {
1415 var oldonload = window.onload;
1516 if (typeof oldonload == 'function') {
@@ -21,6 +22,7 @@
2223 window.onload = func;
2324 }
2425 }
 26+*/
2527
2628 function convertLatToDMS (val) {
2729 return Math.abs(val) + "° " + ( val < 0 ? "S" : "N" );
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -64,10 +64,11 @@
6565 include_once $egMapsIP . '/GoogleMaps/Maps_GoogleMaps.php'; // Google Maps
6666 include_once $egMapsIP . '/OpenLayers/Maps_OpenLayers.php'; // OpenLayers
6767 include_once $egMapsIP . '/YahooMaps/Maps_YahooMaps.php'; // Yahoo! Maps
 68+//include_once $egMapsIP . '/OpenStreetMaps/Maps_OSM.php'; // OpenLayers optimized for OSM
6869
6970 # Array of String. Array containing all the mapping services that will be made available to the user.
7071 # Currently Maps provides the following services: googlemaps, yahoomaps, openlayers
71 -$egMapsAvailableServices = array('googlemaps', 'yahoomaps', 'openlayers');
 72+$egMapsAvailableServices = array('googlemaps', 'yahoomaps', 'openlayers'/*, 'osm'*/);
7273
7374 # String. The default mapping service, which will be used when no default service is prsent in the
7475 # $egMapsDefaultServices array for a certain feature. A service that supports all features is recommended.
@@ -121,6 +122,12 @@
122123 $egMapsMapWidth = 600;
123124 $egMapsMapHeight = 350;
124125
 126+# Array. The minimum and maximum width and height for all maps.
 127+$egMapsSizeRestrictions = array(
 128+ 'width' => array( 100, 1000 ),
 129+ 'height' => array( 100, 1000 ),
 130+);
 131+
125132 # Strings. The default coordinates of the marker. This value will only be used when the user does not provide one.
126133 $egMapsMapLat = '1';
127134 $egMapsMapLon = '1';
@@ -203,3 +210,13 @@
204211 # Array of String. The default layers for Open Layers. This value will only be used when the user does not provide one.
205212 # Available values: google, bing, yahoo, openlayers, nasa
206213 $egMapsOLLayers = array('openlayers');
 214+
 215+
 216+
 217+# OpenStreetMaps (OpenLayers optimized for OSM)
 218+
 219+# String. The OSM map name prefix. It can not be identical to the one of another mapping service.
 220+$egMapsOSMPrefix = 'map_osm';
 221+
 222+# Integer. The default zoom of a map. This value will only be used when the user does not provide one.
 223+$egMapsOSMZoom = 13;
Index: trunk/extensions/Maps/Maps_Utils.php
@@ -35,6 +35,11 @@
3636 }
3737 }
3838
 39+ /**
 40+ *
 41+ * @param $deg_coord
 42+ * @return unknown_type
 43+ */
3944 private static function convertCoord($deg_coord = "") {
4045 if (preg_match ( '/°/', $deg_coord )) {
4146 if (preg_match ( '/"/', $deg_coord )) {
@@ -46,6 +51,11 @@
4752 return $deg_coord;
4853 }
4954
 55+ /**
 56+ *
 57+ * @param $deg_coord
 58+ * @return unknown_type
 59+ */
5060 private static function degree2Decimal($deg_coord = "") {
5161 $dpos = strpos ( $deg_coord, '°' );
5262 $mpos = strpos ( $deg_coord, '.' );
@@ -61,12 +71,17 @@
6272 $minutes = ($minutes / 60);
6373 $decimal = ($degrees + $minutes);
6474 //South latitudes and West longitudes need to return a negative result
65 - if (($direction == "S") or ($direction == "W")) {
 75+ if ($direction == "S" || $direction == "W") {
6676 $decimal *= - 1;
6777 }
6878 return $decimal;
6979 }
7080
 81+ /**
 82+ *
 83+ * @param $deg_coord
 84+ * @return unknown_type
 85+ */
7186 private static function decDegree2Decimal($deg_coord = "") {
7287 $direction = substr ( strrev ( $deg_coord ), 0, 1 );
7388 $decimal = floatval ( $deg_coord );
@@ -76,6 +91,11 @@
7792 return $decimal;
7893 }
7994
 95+ /**
 96+ *
 97+ * @param $decimal
 98+ * @return unknown_type
 99+ */
80100 public static function latDecimal2Degree($decimal) {
81101 if ($decimal < 0) {
82102 return abs ( $decimal ) . "° S";
@@ -84,6 +104,11 @@
85105 }
86106 }
87107
 108+ /**
 109+ *
 110+ * @param $decimal
 111+ * @return unknown_type
 112+ */
88113 public static function lonDecimal2Degree($decimal) {
89114 if ($decimal < 0) {
90115 return abs ( $decimal ) . "° W";
@@ -93,16 +118,62 @@
94119 }
95120
96121 /**
97 - * Add 'px' to a provided width/heigt value
98 - *
99 - * @param unknown_type $value
 122+ * If the provided height or width do not fall within the allowed interval,
 123+ * they are changed to the nearest allowed value.
 124+ *
 125+ * @param integer $width
 126+ * @param integer $height
100127 */
101 - public static function makePxValue(&$value) {
102 - if (substr ( $value, strlen ( $value ) - 2 ) != 'px')
103 - $value .= 'px';
 128+ public static function makeMapSizeValid(&$width, &$height) {
 129+ global $egMapsSizeRestrictions;
 130+
 131+ if ($width < $egMapsSizeRestrictions['width'][0]) {
 132+ $width = $egMapsSizeRestrictions['width'][0];
 133+ }
 134+ else if($width > $egMapsSizeRestrictions['width'][1]) {
 135+ $width = $egMapsSizeRestrictions['width'][1];
 136+ }
 137+
 138+ if ($width < $egMapsSizeRestrictions['height'][0]) {
 139+ $width = $egMapsSizeRestrictions['height'][0];
 140+ }
 141+ else if($width > $egMapsSizeRestrictions['height'][1]) {
 142+ $width = $egMapsSizeRestrictions['height'][1];
 143+ }
104144 }
105145
106146 /**
 147+ * Convert from WGS84 to spherical mercator.
 148+ */
 149+ public static function forwardMercator($lonlat) {
 150+ for ($i=0; $i<count($lonlat); $i+=2) {
 151+ /* lon */
 152+ $lonlat[$i] = $lonlat[$i] * (2 * M_PI * 6378137 / 2.0) / 180.0;
 153+
 154+ /* lat */
 155+ $lonlat[$i+1] = log(tan((90 + $lonlat[$i+1]) * M_PI / 360.0)) / (M_PI / 180.0);
 156+ $lonlat[$i+1] = $lonlat[$i+1] * (2 * M_PI * 6378137 / 2.0) / 180.0;
 157+ }
 158+ return $lonlat;
 159+ }
 160+
 161+ /**
 162+ * Convert from spherical mercator to WGS84.
 163+ */
 164+ public static function inverseMercator($lonlat) {
 165+ for ($i=0; $i<count($lonlat); $i+=2) {
 166+ /* lon */
 167+ $lonlat[$i] = $lonlat[$i] / ((2 * M_PI * 6378137 / 2.0) / 180.0);
 168+
 169+ /* lat */
 170+ $lonlat[$i+1] = $lonlat[$i+1] / ((2 * M_PI * 6378137 / 2.0) / 180.0);
 171+ $lonlat[$i+1] = 180.0 / M_PI * (2 * atan(exp($lonlat[$i+1] * M_PI / 180.0)) - M_PI / 2);
 172+ }
 173+
 174+ return $lonlat;
 175+ }
 176+
 177+ /**
107178 * Returns if the current php version is equal of bigger then the provided one.
108179 *
109180 * @param string $requiredVersion
Index: trunk/extensions/Maps/OpenStreetMaps/Maps_OSMDispMap.php
@@ -0,0 +1,76 @@
 2+<?php
 3+
 4+/**
 5+ * Class for handling the display_map parser function with OSM.
 6+ *
 7+ * @file Maps_OSMDispMap.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+class MapsOSMDispMap extends MapsBaseMap {
 18+
 19+ public $serviceName = MapsOSMUtils::SERVICE_NAME;
 20+
 21+ /**
 22+ * @see MapsBaseMap::setMapSettings()
 23+ *
 24+ */
 25+ protected function setMapSettings() {
 26+ global $egMapsOSMZoom, $egMapsOSMPrefix;
 27+
 28+ $this->defaultParams = MapsOSMUtils::getDefaultParams();
 29+
 30+ $this->elementNamePrefix = $egMapsOSMPrefix;
 31+ $this->defaultZoom = $egMapsOSMZoom;
 32+ }
 33+
 34+ /**
 35+ * @see MapsBaseMap::doMapServiceLoad()
 36+ *
 37+ */
 38+ protected function doMapServiceLoad() {
 39+ global $egOSMMapsOnThisPage;
 40+
 41+ MapsOSMUtils::addOSMDependencies($this->output);
 42+ $egOSMMapsOnThisPage++;
 43+
 44+ $this->elementNr = $egOSMMapsOnThisPage;
 45+ }
 46+
 47+ /**
 48+ * @see MapsBaseMap::addSpecificMapHTML()
 49+ *
 50+ */
 51+ public function addSpecificMapHTML() {
 52+ global $wgJsMimeType;
 53+
 54+ $this->output .= <<<EOT
 55+ <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', {
 56+ mode: 'osm-wm',
 57+ layer: 'osm-like',
 58+ locale: 'en',
 59+ lat: $this->centre_lat,
 60+ lon: $this->centre_lon,
 61+ zoom: $this->zoom,
 62+ width: $this->width,
 63+ height: $this->height,
 64+ marker: 0
 65+ });</script>
 66+
 67+ <!-- map div -->
 68+ <div id='$this->mapName' class='map' style='width:{$this->width}px; height:{$this->height}px;'>
 69+ <script type='$wgJsMimeType'>slippymaps['$this->mapName'].init();</script>
 70+ <!-- /map div -->
 71+ </div>
 72+EOT;
 73+
 74+ }
 75+
 76+}
 77+
Index: trunk/extensions/Maps/OpenStreetMaps/OSMFunctions.js
@@ -0,0 +1,136 @@
 2+/*
 3+ * @file OSMFunctions.js
 4+ * @ingroup Maps
 5+ *
 6+ * @author Harry Wood, Jens Frank, Grant Slater, Raymond Spekking, Jeroen De Dauw and others
 7+ *
 8+ * @description
 9+ *
 10+ * Javascript functions for OSM optimized Open Layers functionallity in Maps and it's extensions
 11+ *
 12+ * This defines what happens when <slippymap> tag is placed in the wikitext
 13+ *
 14+ * We show a map based on the lat/lon/zoom data passed in. This extension brings in
 15+ * the OpenLayers javascript, to show a slippy map.
 16+ *
 17+ * Usage example:
 18+ * <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender></slippymap>
 19+ *
 20+ * Tile images are not cached local to the wiki.
 21+ * To acheive this (remove the OSM dependency) you might set up a squid proxy,
 22+ * and modify the requests URLs here accordingly.
 23+ *
 24+ * This file should be placed in the mediawiki 'extensions' directory
 25+ * ...and then it needs to be 'included' within LocalSettings.php
 26+ *
 27+ * This program is free software; you can redistribute it and/or modify
 28+ * it under the terms of the GNU General Public License as published by
 29+ * the Free Software Foundation; either version 2 of the License, or
 30+ * (at your option) any later version.
 31+ *
 32+ * This program is distributed in the hope that it will be useful,
 33+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 34+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 35+ * GNU General Public License for more details.
 36+ *
 37+ * You should have received a copy of the GNU General Public License
 38+ * along with this program; if not, write to the Free Software
 39+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 40+ *
 41+ */
 42+
 43+var slippymaps = new Array();
 44+var mapId = 0;
 45+var layer = null;
 46+
 47+if (false) { // wgSlippyMapSlippyByDefault
 48+ addOnloadHook(slippymap_init);
 49+}
 50+
 51+function slippymap_init() {
 52+ for(keyName in slippymaps) {
 53+ slippymaps[keyName].init();
 54+ }
 55+}
 56+
 57+function slippymap_map(mapId, mapParams) {
 58+ var self = this;
 59+ this.mapId = mapId;
 60+
 61+ for (key in mapParams)
 62+ this[key] = mapParams[key];
 63+
 64+ /*
 65+ var buttonsPanel = new OpenLayers.Control.Panel( { displayClass: "buttonsPanel" } );
 66+ buttonsPanel.addControls([ new OpenLayers.Control.Button({
 67+ title: wgSlippyMapButtonCode,
 68+ displayClass: "getWikiCodeButton",
 69+ trigger: function() { self.getWikicode(); }
 70+ }),
 71+ new OpenLayers.Control.Button({
 72+ title: wgSlippyMapResetview,
 73+ displayClass: "resetButton",
 74+ trigger: function() { self.resetPosition(); }
 75+ })
 76+ ]);
 77+ */
 78+
 79+ this.mapOptions = { controls: [ new OpenLayers.Control.Navigation(),
 80+ new OpenLayers.Control.ArgParser(),
 81+ new OpenLayers.Control.Attribution(),
 82+ /* buttonsPanel */ ]
 83+ };
 84+
 85+ /* Add the zoom bar control, except if the map is only little */
 86+ if (this.height > 320)
 87+ this.mapOptions.controls.push(new OpenLayers.Control.PanZoomBar());
 88+ else if (this.height > 140)
 89+ this.mapOptions.controls.push(new OpenLayers.Control.PanZoom());
 90+}
 91+
 92+slippymap_map.prototype.init = function() {
 93+ /* Swap out against the preview image */
 94+ var previewImage = document.getElementById('mapPreview' + this.mapId);
 95+ if (previewImage)
 96+ previewImage.style.display = 'none';
 97+
 98+ this.map = this.osm_create(this.mapId, this.lon, this.lat, this.zoom);
 99+
 100+ if (this.marker) {
 101+ var markers = new OpenLayers.Layer.Markers( "Markers" );
 102+ this.map.addLayer(markers);
 103+ var icon = OpenLayers.Marker.defaultIcon();
 104+ markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(this.lon, this.lat).transform(new OpenLayers.Projection('EPSG:4326'), this.map.getProjectionObject()), icon));
 105+ }
 106+}
 107+
 108+slippymap_map.prototype.osm_create = function(mapId, lon, lat, zoom) {
 109+ var osmLayer;
 110+ var map = new OpenLayers.Map(mapId, this.mapOptions /* all provided for by OSM.js */);
 111+
 112+ if (this.layer == 'osm-like') {
 113+ osmLayer = new OpenLayers.Layer.OSM("meh", 'http://cassini.toolserver.org/tiles/osm-like/' + this.locale + '/${z}/${x}/${y}.png');
 114+ }
 115+
 116+ map.addLayers([osmLayer]);
 117+ map.setCenter(new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection('EPSG:4326'), map.getProjectionObject()), zoom);
 118+ return map;
 119+}
 120+
 121+slippymap_map.prototype.resetPosition = function() {
 122+ this.map.setCenter(new OpenLayers.LonLat(this.lon, this.lat).transform(new OpenLayers.Projection('EPSG:4326'), this.map.getProjectionObject()), this.zoom);
 123+}
 124+
 125+slippymap_map.prototype.getWikicode = function() {
 126+ LL = this.map.getCenter().transform(this.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
 127+ Z = this.map.getZoom();
 128+ size = this.map.getSize();
 129+
 130+ prompt(
 131+ wgSlippyMapCode,
 132+ "<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) + " />"
 133+ );
 134+}
 135+
 136+
 137+
Index: trunk/extensions/Maps/OpenStreetMaps/Maps_OSM.php
@@ -0,0 +1,23 @@
 2+<?php
 3+
 4+/**
 5+ * This file holds the general information for the OSM optimized OpenLayers service
 6+ *
 7+ * @file Maps_OSM.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+$egMapsServices['osm'] = array(
 14+ 'pf' => array(
 15+ 'display_point' => array('class' => 'MapsOSMDispPoint', 'file' => 'OpenStreetMaps/Maps_OSMDispPoint.php', 'local' => true),
 16+ 'display_map' => array('class' => 'MapsOSMDispMap', 'file' => 'OpenStreetMaps/Maps_OSMDispMap.php', 'local' => true),
 17+ ),
 18+ 'classes' => array(
 19+ array('class' => 'MapsOSMUtils', 'file' => 'OpenStreetMaps/Maps_OSMUtils.php', 'local' => true)
 20+ ),
 21+ 'aliases' => array('openstreetmaps'),
 22+ 'parameters' => array(
 23+ )
 24+ );
\ No newline at end of file
Index: trunk/extensions/Maps/OpenStreetMaps/Maps_OSMUtils.php
@@ -0,0 +1,109 @@
 2+<?php
 3+
 4+/**
 5+ * A class that holds static helper functions for OSM.
 6+ *
 7+ * @file Maps_OSMUtils.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+final class MapsOSMUtils {
 18+
 19+ const SERVICE_NAME = 'osm';
 20+
 21+ private static $layers = array(
 22+ 'osm-wm' => array(
 23+ // First layer = default
 24+ 'layers' => array( 'osm-like' ),
 25+
 26+ // Default "zoom=" argument
 27+ 'defaultZoomLevel' => 14,
 28+
 29+ 'static_rendering' => array(
 30+ 'type' => 'SlippyMapExportCgiBin',
 31+ 'options' => array(
 32+ 'base_url' => 'http://cassini.toolserver.org/cgi-bin/export',
 33+
 34+ 'format' => 'png',
 35+ 'numZoomLevels' => 19,
 36+ 'maxResolution' => 156543.0339,
 37+ 'unit' => 'm',
 38+ 'sphericalMercator' => true,
 39+
 40+ // More GET arguments
 41+ 'get_args' => array(
 42+ // Will use $wgContLang->getCode()
 43+ 'locale' => true,
 44+ 'maptype' => 'osm-like'
 45+ ),
 46+ ),
 47+ ),
 48+ ),
 49+ 'osm' => array(
 50+ // First layer = default
 51+ 'layers' => array( 'mapnik', 'osmarender', 'maplint', 'cycle' ),
 52+
 53+ // Default "zoom=" argument
 54+ 'defaultZoomLevel' => 14,
 55+
 56+ 'static_rendering' => array(
 57+ 'type' => 'SlippyMapExportCgiBin',
 58+ 'options' => array(
 59+ 'base_url' => 'http://tile.openstreetmap.org/cgi-bin/export',
 60+
 61+ 'format' => 'png',
 62+ 'numZoomLevels' => 19,
 63+ 'maxResolution' => 156543.0339,
 64+ 'unit' => 'm',
 65+ 'sphericalMercator' => true
 66+ ),
 67+ ),
 68+ ),
 69+ 'satellite' => array(
 70+ 'layers' => array( 'urban', 'landsat', 'bluemarble' ),
 71+ 'defaultZoomLevel' => 14,
 72+ 'static_rendering' => null,
 73+ ),
 74+ );
 75+
 76+ /**
 77+ * Retuns an array holding the default parameters and their values.
 78+ *
 79+ * @return array
 80+ */
 81+ public static function getDefaultParams() {
 82+ return array
 83+ (
 84+ 'layers' => array(),
 85+ 'baselayer' => ''
 86+ );
 87+ }
 88+
 89+ /**
 90+ * If this is the first open layers map on the page, load the API, styles and extra JS functions
 91+ *
 92+ * @param string $output
 93+ */
 94+ public static function addOSMDependencies(&$output) {
 95+ global $wgJsMimeType, $wgStyleVersion;
 96+ global $egOSMMapsOnThisPage, $egMapsScriptPath;
 97+
 98+ if (empty($egOSMMapsOnThisPage)) {
 99+ $egOSMMapsOnThisPage = 0;
 100+
 101+ $output .="<link rel='stylesheet' href='$egMapsScriptPath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
 102+ <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayers/OpenLayers.js'></script>
 103+ <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenStreetMaps/OSMFunctions.js?$wgStyleVersion'></script>
 104+ <script type='$wgJsMimeType'>slippymaps = Array();</script>\n";
 105+ }
 106+ }
 107+
 108+}
 109+
 110+?>
\ No newline at end of file
Index: trunk/extensions/Maps/OpenStreetMaps/Maps_OSMDispPoint.php
@@ -0,0 +1,80 @@
 2+<?php
 3+
 4+/**
 5+ * Class for handling the display_point(s) parser functions with OSM.
 6+ *
 7+ * @file Maps_OSMDispPoint.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+class MapsOSMDispPoint extends MapsBasePointMap {
 18+
 19+ public $serviceName = MapsOSMUtils::SERVICE_NAME;
 20+
 21+ /**
 22+ * @see MapsBaseMap::setMapSettings()
 23+ *
 24+ */
 25+ protected function setMapSettings() {
 26+ global $egMapsOSMZoom, $egMapsOSMPrefix;
 27+
 28+ $this->defaultParams = MapsOSMUtils::getDefaultParams();
 29+
 30+ $this->elementNamePrefix = $egMapsOSMPrefix;
 31+ $this->defaultZoom = $egMapsOSMZoom;
 32+ }
 33+
 34+ /**
 35+ * @see MapsBaseMap::doMapServiceLoad()
 36+ *
 37+ */
 38+ protected function doMapServiceLoad() {
 39+ global $egOSMMapsOnThisPage;
 40+
 41+ MapsOSMUtils::addOSMDependencies($this->output);
 42+ $egOSMMapsOnThisPage++;
 43+
 44+ $this->elementNr = $egOSMMapsOnThisPage;
 45+ }
 46+
 47+ /**
 48+ * @see MapsBaseMap::addSpecificMapHTML()
 49+ *
 50+ */
 51+ public function addSpecificMapHTML() {
 52+ global $wgJsMimeType;
 53+
 54+ $markerItems = array();
 55+
 56+ // TODO: Refactor up
 57+ foreach ($this->markerData as $markerData) {
 58+ $lat = $markerData['lat'];
 59+ $lon = $markerData['lon'];
 60+
 61+ $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
 62+ $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
 63+
 64+ $title = str_replace("'", "\'", $title);
 65+ $label = str_replace("'", "\'", $label);
 66+
 67+ $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
 68+ $markerItems[] = "getOLMarkerData($lon, $lat, '$title', '$label', '$icon')";
 69+ }
 70+
 71+ $markersString = implode(',', $markerItems);
 72+
 73+ $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div>
 74+ <script type='$wgJsMimeType'> /*<![CDATA[*/
 75+ addOnloadHook(
 76+ initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString])
 77+ );
 78+ /*]]>*/ </script>";
 79+ }
 80+
 81+}
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r58243Follow-up r58223: make new message optional for translatewikiraymond05:11, 28 October 2009

Status & tagging log