Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php |
— | — | @@ -54,9 +54,6 @@ |
55 | 55 | |
56 | 56 | MapsMapper::enforceArrayValues($this->layers); |
57 | 57 | $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); |
58 | | - |
59 | | - MapsUtils::makePxValue($this->width); |
60 | | - MapsUtils::makePxValue($this->height); |
61 | 58 | |
62 | 59 | $markerItems = array(); |
63 | 60 | |
— | — | @@ -77,9 +74,9 @@ |
78 | 75 | |
79 | 76 | $markersString = implode(',', $markerItems); |
80 | 77 | |
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> |
82 | 79 | <script type='$wgJsMimeType'> /*<![CDATA[*/ |
83 | | - addLoadEvent( |
| 80 | + addOnloadHook( |
84 | 81 | initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString]) |
85 | 82 | ); |
86 | 83 | /*]]>*/ </script>"; |
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php |
— | — | @@ -54,13 +54,10 @@ |
55 | 55 | |
56 | 56 | MapsMapper::enforceArrayValues($this->layers); |
57 | 57 | $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); |
58 | | - |
59 | | - MapsUtils::makePxValue($this->width); |
60 | | - MapsUtils::makePxValue($this->height); |
61 | 58 | |
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> |
63 | 60 | <script type='$wgJsMimeType'> /*<![CDATA[*/ |
64 | | - addLoadEvent( |
| 61 | + addOnloadHook( |
65 | 62 | initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[]) |
66 | 63 | ); |
67 | 64 | /*]]>*/ </script>"; |
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | * @param string $layer The layer to check (and load the dependencies for |
31 | 31 | */ |
32 | 32 | public static function loadDependencyWhenNeeded(&$output, $layer) { |
33 | | - global $wgJsMimeType; |
| 33 | + global $wgJsMimeType, $wgStyleVersion; |
34 | 34 | global $egGoogleMapsOnThisPage, $egMapsScriptPath; |
35 | 35 | |
36 | 36 | switch ($layer) { |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | if (!self::$loadedOL) { $output .= "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>\n"; self::$loadedOL = true; } |
51 | 51 | break; |
52 | 52 | 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; } |
54 | 54 | break; |
55 | 55 | } |
56 | 56 | } |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php |
— | — | @@ -154,7 +154,7 @@ |
155 | 155 | $this->centre_lat = $egMapsMapLat; |
156 | 156 | $this->centre_lon = $egMapsMapLon; |
157 | 157 | } |
158 | | - |
| 158 | + |
159 | 159 | /** |
160 | 160 | * Parse the wiki text in the title and label values. |
161 | 161 | * |
— | — | @@ -167,7 +167,6 @@ |
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Escape the title and label text |
171 | | - * |
172 | 171 | */ |
173 | 172 | private function doEscaping() { |
174 | 173 | $this->title = str_replace("'", "\'", $this->title); |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php |
— | — | @@ -109,13 +109,13 @@ |
110 | 110 | |
111 | 111 | /** |
112 | 112 | * |
113 | | - * @param $coordsOrAddress |
114 | | - * @return unknown_type |
| 113 | + * |
| 114 | + * @param string $coordsOrAddress |
115 | 115 | */ |
116 | 116 | private static function isCoordinate($coordsOrAddress) { |
117 | 117 | $coordRegexes = array( // TODO: change . to �, this won't work for some reason |
118 | 118 | '/^\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 |
120 | 120 | '/^(-)?\d{1,3}(|\.\d{1,7}).,(\s)?(-)?(\s)?\d{1,3}(|\.\d{1,7}).$/', // DD |
121 | 121 | '/(-)?\d{1,3}.\d{1,3}(\.\d{1,7}\')?,(\s)?(-)?\d{1,3}.\d{1,3}(\.\d{1,7}\')?$/', // DM |
122 | 122 | ); |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -define('Maps_VERSION', '0.4 a8'); |
| 27 | +define('Maps_VERSION', '0.4 a9'); |
28 | 28 | |
29 | 29 | $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; |
30 | 30 | $egMapsIP = $IP . '/extensions/Maps'; |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | |
66 | 66 | <div id="$this->mapName" class="$this->class" style="$this->style" ></div> |
67 | 67 | <script type="$wgJsMimeType"> /*<![CDATA[*/ |
68 | | -addLoadEvent( |
| 68 | +addOnloadHook( |
69 | 69 | initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, []) |
70 | 70 | ); |
71 | 71 | /*]]>*/ </script> |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php |
— | — | @@ -115,7 +115,7 @@ |
116 | 116 | * @param string $output |
117 | 117 | */ |
118 | 118 | public static function addGMapDependencies(&$output) { |
119 | | - global $wgJsMimeType, $wgLang, $wgOut; |
| 119 | + global $wgJsMimeType, $wgLang, $wgStyleVersion; |
120 | 120 | global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage; |
121 | 121 | |
122 | 122 | if (empty($egGoogleMapsOnThisPage)) { |
— | — | @@ -123,11 +123,9 @@ |
124 | 124 | |
125 | 125 | MapsGoogleMapsUtils::validateGoogleMapsKey(); |
126 | 126 | |
127 | | - $wgOut->addScriptFile($egMapsScriptPath . '/GoogleMaps/GoogleMapFunctions.js'); |
128 | | - |
129 | 127 | // TODO: use strbuilder for performance gain? |
130 | 128 | $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>"; |
132 | 130 | } |
133 | 131 | } |
134 | 132 | |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | |
87 | 87 | <div id="$this->mapName" class="$this->class" style="$this->style" ></div> |
88 | 88 | <script type="$wgJsMimeType"> /*<![CDATA[*/ |
89 | | -addLoadEvent( |
| 89 | +addOnloadHook( |
90 | 90 | initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString]) |
91 | 91 | ); |
92 | 92 | /*]]>*/ </script> |
Index: trunk/extensions/Maps/Maps_MapFeature.php |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * MapsMapFeature bundles some base functionallity for all general mapping feature classes |
| 5 | + * MapsMapFeature bundles some base functionallity for all general mapping feature classes. |
6 | 6 | * |
7 | 7 | * @file Maps_MapFeature.php |
8 | 8 | * @ingroup Maps |
— | — | @@ -67,7 +67,10 @@ |
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
| 71 | + // TODO: refactor down - not every mapping feature/service should support a controls parameter |
71 | 72 | MapsMapper::enforceArrayValues($this->controls); |
| 73 | + |
| 74 | + MapsUtils::makeMapSizeValid($this->width, $this->height); |
72 | 75 | } |
73 | 76 | |
74 | 77 | /** |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php |
— | — | @@ -53,9 +53,6 @@ |
54 | 54 | $this->type = MapsYahooMapsUtils::getYMapType($this->type, true); |
55 | 55 | |
56 | 56 | $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); |
57 | | - |
58 | | - MapsUtils::makePxValue($this->width); |
59 | | - MapsUtils::makePxValue($this->height); |
60 | 57 | |
61 | 58 | $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); |
62 | 59 | |
— | — | @@ -83,10 +80,10 @@ |
84 | 81 | $typesString = MapsYahooMapsUtils::createTypesString($this->types); |
85 | 82 | |
86 | 83 | $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> |
88 | 85 | |
89 | 86 | <script type="$wgJsMimeType">/*<![CDATA[*/ |
90 | | - addLoadEvent( |
| 87 | + addOnloadHook( |
91 | 88 | initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString]) |
92 | 89 | ); |
93 | 90 | /*]]>*/</script> |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php |
— | — | @@ -53,9 +53,6 @@ |
54 | 54 | $this->type = MapsYahooMapsUtils::getYMapType($this->type, true); |
55 | 55 | |
56 | 56 | $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); |
57 | | - |
58 | | - MapsUtils::makePxValue($this->width); |
59 | | - MapsUtils::makePxValue($this->height); |
60 | 57 | |
61 | 58 | $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); |
62 | 59 | |
— | — | @@ -64,10 +61,10 @@ |
65 | 62 | $typesString = MapsYahooMapsUtils::createTypesString($this->types); |
66 | 63 | |
67 | 64 | $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> |
69 | 66 | |
70 | 67 | <script type="$wgJsMimeType">/*<![CDATA[*/ |
71 | | - addLoadEvent( |
| 68 | + addOnloadHook( |
72 | 69 | initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, []) |
73 | 70 | ); |
74 | 71 | /*]]>*/</script> |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php |
— | — | @@ -80,13 +80,13 @@ |
81 | 81 | * @param string $output |
82 | 82 | */ |
83 | 83 | public static function addYMapDependencies(&$output) { |
84 | | - global $wgJsMimeType; |
| 84 | + global $wgJsMimeType, $wgStyleVersion; |
85 | 85 | global $egYahooMapsKey, $egMapsScriptPath, $egYahooMapsOnThisPage; |
86 | 86 | |
87 | 87 | if (empty($egYahooMapsOnThisPage)) { |
88 | 88 | $egYahooMapsOnThisPage = 0; |
89 | 89 | $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>"; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
Index: trunk/extensions/Maps/Maps.i18n.php |
— | — | @@ -30,6 +30,7 @@ |
31 | 31 | 'maps_googlemaps' => 'Google Maps', |
32 | 32 | 'maps_yahoomaps' => 'Yahoo! Maps', |
33 | 33 | 'maps_openlayers' => 'OpenLayers', |
| 34 | + 'maps_osm' => 'OpenStreetMaps', |
34 | 35 | ); |
35 | 36 | |
36 | 37 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Maps/MapUtilityFunctions.js |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | * @author Jeroen De Dauw |
11 | 11 | */ |
12 | 12 | |
| 13 | +/* |
13 | 14 | function addLoadEvent(func) { |
14 | 15 | var oldonload = window.onload; |
15 | 16 | if (typeof oldonload == 'function') { |
— | — | @@ -21,6 +22,7 @@ |
22 | 23 | window.onload = func; |
23 | 24 | } |
24 | 25 | } |
| 26 | +*/ |
25 | 27 | |
26 | 28 | function convertLatToDMS (val) { |
27 | 29 | return Math.abs(val) + "° " + ( val < 0 ? "S" : "N" ); |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -64,10 +64,11 @@ |
65 | 65 | include_once $egMapsIP . '/GoogleMaps/Maps_GoogleMaps.php'; // Google Maps |
66 | 66 | include_once $egMapsIP . '/OpenLayers/Maps_OpenLayers.php'; // OpenLayers |
67 | 67 | include_once $egMapsIP . '/YahooMaps/Maps_YahooMaps.php'; // Yahoo! Maps |
| 68 | +//include_once $egMapsIP . '/OpenStreetMaps/Maps_OSM.php'; // OpenLayers optimized for OSM |
68 | 69 | |
69 | 70 | # Array of String. Array containing all the mapping services that will be made available to the user. |
70 | 71 | # Currently Maps provides the following services: googlemaps, yahoomaps, openlayers |
71 | | -$egMapsAvailableServices = array('googlemaps', 'yahoomaps', 'openlayers'); |
| 72 | +$egMapsAvailableServices = array('googlemaps', 'yahoomaps', 'openlayers'/*, 'osm'*/); |
72 | 73 | |
73 | 74 | # String. The default mapping service, which will be used when no default service is prsent in the |
74 | 75 | # $egMapsDefaultServices array for a certain feature. A service that supports all features is recommended. |
— | — | @@ -121,6 +122,12 @@ |
122 | 123 | $egMapsMapWidth = 600; |
123 | 124 | $egMapsMapHeight = 350; |
124 | 125 | |
| 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 | + |
125 | 132 | # Strings. The default coordinates of the marker. This value will only be used when the user does not provide one. |
126 | 133 | $egMapsMapLat = '1'; |
127 | 134 | $egMapsMapLon = '1'; |
— | — | @@ -203,3 +210,13 @@ |
204 | 211 | # Array of String. The default layers for Open Layers. This value will only be used when the user does not provide one. |
205 | 212 | # Available values: google, bing, yahoo, openlayers, nasa |
206 | 213 | $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 @@ |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
| 39 | + /** |
| 40 | + * |
| 41 | + * @param $deg_coord |
| 42 | + * @return unknown_type |
| 43 | + */ |
39 | 44 | private static function convertCoord($deg_coord = "") { |
40 | 45 | if (preg_match ( '/°/', $deg_coord )) { |
41 | 46 | if (preg_match ( '/"/', $deg_coord )) { |
— | — | @@ -46,6 +51,11 @@ |
47 | 52 | return $deg_coord; |
48 | 53 | } |
49 | 54 | |
| 55 | + /** |
| 56 | + * |
| 57 | + * @param $deg_coord |
| 58 | + * @return unknown_type |
| 59 | + */ |
50 | 60 | private static function degree2Decimal($deg_coord = "") { |
51 | 61 | $dpos = strpos ( $deg_coord, '°' ); |
52 | 62 | $mpos = strpos ( $deg_coord, '.' ); |
— | — | @@ -61,12 +71,17 @@ |
62 | 72 | $minutes = ($minutes / 60); |
63 | 73 | $decimal = ($degrees + $minutes); |
64 | 74 | //South latitudes and West longitudes need to return a negative result |
65 | | - if (($direction == "S") or ($direction == "W")) { |
| 75 | + if ($direction == "S" || $direction == "W") { |
66 | 76 | $decimal *= - 1; |
67 | 77 | } |
68 | 78 | return $decimal; |
69 | 79 | } |
70 | 80 | |
| 81 | + /** |
| 82 | + * |
| 83 | + * @param $deg_coord |
| 84 | + * @return unknown_type |
| 85 | + */ |
71 | 86 | private static function decDegree2Decimal($deg_coord = "") { |
72 | 87 | $direction = substr ( strrev ( $deg_coord ), 0, 1 ); |
73 | 88 | $decimal = floatval ( $deg_coord ); |
— | — | @@ -76,6 +91,11 @@ |
77 | 92 | return $decimal; |
78 | 93 | } |
79 | 94 | |
| 95 | + /** |
| 96 | + * |
| 97 | + * @param $decimal |
| 98 | + * @return unknown_type |
| 99 | + */ |
80 | 100 | public static function latDecimal2Degree($decimal) { |
81 | 101 | if ($decimal < 0) { |
82 | 102 | return abs ( $decimal ) . "° S"; |
— | — | @@ -84,6 +104,11 @@ |
85 | 105 | } |
86 | 106 | } |
87 | 107 | |
| 108 | + /** |
| 109 | + * |
| 110 | + * @param $decimal |
| 111 | + * @return unknown_type |
| 112 | + */ |
88 | 113 | public static function lonDecimal2Degree($decimal) { |
89 | 114 | if ($decimal < 0) { |
90 | 115 | return abs ( $decimal ) . "° W"; |
— | — | @@ -93,16 +118,62 @@ |
94 | 119 | } |
95 | 120 | |
96 | 121 | /** |
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 |
100 | 127 | */ |
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 | + } |
104 | 144 | } |
105 | 145 | |
106 | 146 | /** |
| 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 | + /** |
107 | 178 | * Returns if the current php version is equal of bigger then the provided one. |
108 | 179 | * |
109 | 180 | * @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 |