Index: trunk/extensions/gis/geo.php |
— | — | @@ -121,12 +121,20 @@ |
122 | 122 | $this->londeg_min = $this->londeg_max = $this->londeg; |
123 | 123 | if ($this->pieces[0] == "to") { |
124 | 124 | array_shift($this->pieces); |
125 | | - # FIXME: Shows only 2nd part |
126 | 125 | $this->get_coor(); |
127 | | - $this->latdeg_max = $this->latdeg; |
128 | | - $this->londeg_max = $this->londeg; |
| 126 | + if ($this->latdeg < $this->latdeg_max) { |
| 127 | + $this->latdeg_min = $this->latdeg; |
| 128 | + } else { |
| 129 | + $this->latdeg_max = $this->latdeg; |
| 130 | + } |
| 131 | + if ($this->londeg < $this->londeg_max) { |
| 132 | + $this->londeg_min = $this->londeg; |
| 133 | + } else { |
| 134 | + $this->londeg_max = $this->londeg; |
| 135 | + } |
129 | 136 | $this->latdeg = ($this->latdeg_max+$this->latdeg_min) / 2; |
130 | 137 | $this->londeg = ($this->londeg_max+$this->londeg_min) / 2; |
| 138 | + $this->coor = array(); |
131 | 139 | } |
132 | 140 | } |
133 | 141 | |
— | — | @@ -227,6 +235,28 @@ |
228 | 236 | } |
229 | 237 | |
230 | 238 | /** |
| 239 | + * Given decimal degrees latitude and longitude, convert to |
| 240 | + * string |
| 241 | + */ |
| 242 | + function make_position( $lat, $lon ) |
| 243 | + { |
| 244 | + $a = geo_param::make_minsec( $lat ); |
| 245 | + $b = geo_param::make_minsec( $lon ); |
| 246 | + $outa = intval(abs($a['deg'])) . "° "; |
| 247 | + $outb = intval(abs($b['deg'])) . "° "; |
| 248 | + if ($a['min'] != 0 or $b['min'] != 0 |
| 249 | + or $a['sec'] != 0 or $b['sec'] != 0) { |
| 250 | + $outa .= intval($a['min']) . "′ "; |
| 251 | + $outb .= intval($b['min']) . "′ "; |
| 252 | + if ($a['sec'] != 0 or $b['sec'] != 0) { |
| 253 | + $outa .= $a['sec']. "″ "; |
| 254 | + $outb .= $b['sec']. "″ "; |
| 255 | + } |
| 256 | + } |
| 257 | + return $outa . $a['NS'] . " " . $outb . $b['EW']; |
| 258 | + } |
| 259 | + |
| 260 | + /** |
231 | 261 | * Get the additional attributes in an associative array |
232 | 262 | */ |
233 | 263 | function get_attr() |
— | — | @@ -289,8 +319,14 @@ |
290 | 320 | { |
291 | 321 | $n = count($this->coor); |
292 | 322 | |
293 | | - # FIXME: how to show a range... |
294 | | - if ($n == 4) { |
| 323 | + if ($n == 0) { |
| 324 | + # Range is special case |
| 325 | + return $this->make_position( $this->latdeg_min, |
| 326 | + $this->londeg_min ) |
| 327 | + . " to " |
| 328 | + . $this->make_position( $this->latdeg_max, |
| 329 | + $this->londeg_max ); |
| 330 | + } elseif ($n == 4) { |
295 | 331 | return $this->coor[0].'° '. |
296 | 332 | $this->coor[1].' '. |
297 | 333 | $this->coor[2].'° '. |
Index: trunk/extensions/gis/neighbors.php |
— | — | @@ -48,35 +48,33 @@ |
49 | 49 | |
50 | 50 | function show() |
51 | 51 | { |
52 | | - global $wgOut; |
| 52 | + global $wgOut, $wgUser, $wgContLang; |
53 | 53 | |
54 | 54 | /* No reason for robots to follow map links */ |
55 | 55 | $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
56 | 56 | |
57 | 57 | $wgOut->setPagetitle( "Neighbors" ); |
58 | | - $this->showList(); |
59 | | - } |
60 | | - |
61 | | - function showList() |
62 | | - { |
63 | | - global $wgOut, $wgUser, $wgContLang; |
64 | 58 | |
65 | 59 | if (($e = $this->p->get_error()) != "") { |
66 | 60 | $wgOut->addHTML( |
67 | | - "<p>". |
68 | | - htmlspecialchars( $e )); |
| 61 | + "<p>" . htmlspecialchars( $e ) . "</p>"); |
69 | 62 | $wgOut->output(); |
70 | 63 | wfErrorExit(); |
71 | 64 | return; |
72 | 65 | } |
73 | 66 | |
| 67 | + $wgOut->addWikiText( $this->make_output() ); |
| 68 | + } |
| 69 | + |
| 70 | + function make_output() |
| 71 | + { |
74 | 72 | $lat0 = $this->p->latdeg; |
75 | 73 | $lon0 = $this->p->londeg; |
76 | 74 | |
77 | 75 | $g = new gis_database(); |
78 | 76 | $g->select_radius_m( $lat0, $lon0, $this->d * 1000); |
79 | 77 | $all = array(); |
80 | | - $all_pos = array(); |
| 78 | + $all_pos = array(); /* temporary store reqd due to sort */ |
81 | 79 | |
82 | 80 | while (($x = $g->fetch_position())) { |
83 | 81 | $id = $x->gis_id; |
— | — | @@ -97,20 +95,20 @@ |
98 | 96 | asort($all, SORT_NUMERIC); |
99 | 97 | reset($all); |
100 | 98 | |
101 | | - /* Output */ |
| 99 | + /* Generate output */ |
102 | 100 | $out .= "''List of ". count($all) |
103 | 101 | . " locations within approx. ".$this->d." km of "; |
104 | 102 | if ($this->title != "") { |
105 | 103 | $out .= $this->title . ", "; |
106 | 104 | } |
107 | 105 | $out .= "coordinates " |
108 | | - . $this->show_position($lat0,$lon0) |
| 106 | + . $this->p->make_position($lat0,$lon0) |
109 | 107 | . "''<br /><hr />\r\n"; |
110 | 108 | |
111 | 109 | while (list($id, $d) = each($all)) { |
112 | 110 | $out .= $this->show_location($id, $d, $all_pos[$id]); |
113 | 111 | } |
114 | | - $wgOut->addWikiText( $out ); |
| 112 | + return $out; |
115 | 113 | } |
116 | 114 | |
117 | 115 | function show_location( $id, $d, $pos ) |
— | — | @@ -136,29 +134,10 @@ |
137 | 135 | } |
138 | 136 | $out .= $d." km "; |
139 | 137 | } |
140 | | - return $out . $pos['octant'] . ", bearing " |
| 138 | + return $out . $pos['octant'] . " (bearing " |
141 | 139 | . round($pos['heading']) . "° towards " |
142 | | - . $this->show_position($pos['lat'],$pos['lon']) |
143 | | - . "<br />\r\n"; |
| 140 | + . $this->p->make_position($pos['lat'],$pos['lon']) |
| 141 | + . ")<br />\r\n"; |
144 | 142 | } |
145 | | - |
146 | | - function show_position( $lat, $lon ) |
147 | | - { |
148 | | - $a = geo_param::make_minsec( $lat ); |
149 | | - $b = geo_param::make_minsec( $lon ); |
150 | | - $outa = intval(abs($a['deg'])) . "° "; |
151 | | - $outb = intval(abs($b['deg'])) . "° "; |
152 | | - if ($a['min'] != 0 or $b['min'] != 0 |
153 | | - or $a['sec'] != 0 or $b['sec'] != 0) { |
154 | | - $outa .= intval($a['min']) . "′ "; |
155 | | - $outb .= intval($b['min']) . "′ "; |
156 | | - if ($a['sec'] != 0 or $b['sec'] != 0) { |
157 | | - $outa .= $a['sec']. "″ "; |
158 | | - $outb .= $b['sec']. "″ "; |
159 | | - } |
160 | | - } |
161 | | - |
162 | | - return $outa . $a['NS'] . " " . $outb . $b['EW']; |
163 | | - } |
164 | 143 | } |
165 | 144 | ?> |
Index: trunk/extensions/gis/mapsources.php |
— | — | @@ -67,8 +67,7 @@ |
68 | 68 | |
69 | 69 | if (($e = $this->p->get_error()) != "") { |
70 | 70 | $wgOut->addHTML( |
71 | | - "<p>". |
72 | | - htmlspecialchars( $e )); |
| 71 | + "<p>" . htmlspecialchars( $e ) . "</p>"); |
73 | 72 | $wgOut->output(); |
74 | 73 | wfErrorExit(); |
75 | 74 | return; |
Index: trunk/extensions/gis/database.php |
— | — | @@ -181,9 +181,9 @@ |
182 | 182 | function select_area( $latmin, $lonmin, $latmax, $lonmax ) |
183 | 183 | { |
184 | 184 | $condition = 'gis_latitude_max >= ' . $latmin . |
185 | | - 'AND gis_latitude_min <= ' . $latmax . |
186 | | - 'AND gis_longitude_max >= ' . $lonmin . |
187 | | - 'AND gis_longitude_min <= ' . $lonmax; |
| 185 | + ' AND gis_latitude_min <= ' . $latmax . |
| 186 | + ' AND gis_longitude_max >= ' . $lonmin . |
| 187 | + ' AND gis_longitude_min <= ' . $lonmax; |
188 | 188 | |
189 | 189 | return $this->select_position( $condition ); |
190 | 190 | } |
Index: trunk/extensions/gis/maparea.php |
— | — | @@ -0,0 +1,116 @@ |
| 2 | +<?php |
| 3 | +/** @file |
| 4 | + * |
| 5 | + * List all locations within an area in a format compatible with Wikimaps |
| 6 | + * |
| 7 | + * ---------------------------------------------------------------------- |
| 8 | + * |
| 9 | + * Copyright 2005, Egil Kvaleberg <egil@kvaleberg.no> |
| 10 | + * |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License |
| 22 | + * along with this program; if not, write to the Free Software |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | + */ |
| 25 | + |
| 26 | + |
| 27 | +include_once ( "gissettings.php" ) ; |
| 28 | + |
| 29 | +require_once( "geo.php" ); |
| 30 | +require_once( "database.php" ); |
| 31 | + |
| 32 | +/** |
| 33 | + * Base class |
| 34 | + */ |
| 35 | +class maparea { |
| 36 | + var $p; |
| 37 | + |
| 38 | + function maparea( $coor ) |
| 39 | + { |
| 40 | + $this->p = new geo_param( $coor ); |
| 41 | + } |
| 42 | + |
| 43 | + function show() |
| 44 | + { |
| 45 | + global $wgOut, $wgUser, $wgContLang; |
| 46 | + |
| 47 | + /* No reason for robots to follow map links */ |
| 48 | + $wgOut->setRobotpolicy( 'noindex,nofollow' ); |
| 49 | + |
| 50 | + $wgOut->setPagetitle( "Maparea" ); |
| 51 | + |
| 52 | + if (($e = $this->p->get_error()) != "") { |
| 53 | + $wgOut->addHTML( |
| 54 | + "<p>" . htmlspecialchars( $e ) . "</p>"); |
| 55 | + $wgOut->output(); |
| 56 | + wfErrorExit(); |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + $wgOut->addWikiText( $this->make_output() ); |
| 61 | + } |
| 62 | + |
| 63 | + function make_output() |
| 64 | + { |
| 65 | + $g = new gis_database(); |
| 66 | + $g->select_area( $this->p->latdeg_min, $this->p->londeg_min, |
| 67 | + $this->p->latdeg_max, $this->p->londeg_max); |
| 68 | + |
| 69 | + $out = ";type:abstract\r\n" |
| 70 | + . ";comment:" |
| 71 | + . $this->map_pos($this->p->latdeg_min,$this->p->londeg_min) . " to " |
| 72 | + . $this->map_pos($this->p->latdeg_max,$this->p->londeg_max) . " (" |
| 73 | + . $this->p->get_markup() . ")\r\n" |
| 74 | + . ";region:include(#*)\r\n" |
| 75 | + . "\r\n"; |
| 76 | + |
| 77 | + while (($x = $g->fetch_position())) { |
| 78 | + $id = $x->gis_id; |
| 79 | + $lat = ($x->gis_latitude_min+$x->gis_latitude_max)/2; |
| 80 | + $lon = ($x->gis_longitude_min+$x->gis_longitude_max)/2; |
| 81 | + $type = $x->gis_type; |
| 82 | + if ($type == "") $type = "unknown"; |
| 83 | + $out .= "==[[" . $g->get_title($id) . "]]==\r\n" |
| 84 | + . ";type:" . $type . "\r\n" |
| 85 | + . ";data:" . $this->map_pos($lat,$lon) . "\r\n" |
| 86 | + . "\r\n"; |
| 87 | + } |
| 88 | + return $out; |
| 89 | + } |
| 90 | + |
| 91 | + function map_pos( $lat, $lon ) |
| 92 | + { |
| 93 | + # |
| 94 | + # NOTE: This is the existing wikmap format |
| 95 | + # Simplify when wikmaps understand decimal degrees |
| 96 | + # |
| 97 | + $a = geo_param::make_minsec( $lat ); |
| 98 | + $b = geo_param::make_minsec( $lon ); |
| 99 | + $out = ""; |
| 100 | + if ($lat < 0) $out .= "-"; |
| 101 | + if (intval(abs( $a['deg'])) <= 9) $out .= "0"; |
| 102 | + $out .= intval(abs($a['deg'])); |
| 103 | + if (intval($a['min']) <= 9) $out .= "0"; |
| 104 | + $out .= intval($a['min']); |
| 105 | + if (intval($a['sec']) <= 9) $out .= "0"; |
| 106 | + $out .= intval($a['sec']) . ","; |
| 107 | + if ($lon < 0) $out .= "-"; |
| 108 | + if (intval(abs( $b['deg'])) <= 9) $out .= "0"; |
| 109 | + $out .= intval(abs($b['deg'])); |
| 110 | + if (intval($b['min']) <= 9) $out .= "0"; |
| 111 | + $out .= intval($b['min']); |
| 112 | + if (intval($b['sec']) <= 9) $out .= "0"; |
| 113 | + $out .= intval($b['sec']); |
| 114 | + return $out; |
| 115 | + } |
| 116 | +} |
| 117 | +?> |
Property changes on: trunk/extensions/gis/maparea.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 118 | + native |
Added: svn:keywords |
2 | 119 | + Author Date Id Revision |
Index: trunk/extensions/gis/index.php |
— | — | @@ -45,6 +45,7 @@ |
46 | 46 | |
47 | 47 | require_once( "mapsources.php"); |
48 | 48 | require_once( "neighbors.php"); |
| 49 | +require_once( "maparea.php"); |
49 | 50 | |
50 | 51 | if ( isset ( $_GET['geo'] ) ) { |
51 | 52 | $geo = urldecode ( $_GET['geo'] ); |
— | — | @@ -53,11 +54,16 @@ |
54 | 55 | $near = urldecode ( $_GET['near'] ) ; |
55 | 56 | $dist = urldecode ( $_GET['dist'] ) ; |
56 | 57 | $title = urldecode ( $_GET['title'] ); |
| 58 | +} else if ( isset ( $_GET['maparea'] ) ) { |
| 59 | + $maparea = urldecode ( $_GET['maparea'] ) ; |
57 | 60 | } |
58 | 61 | |
59 | 62 | # FIXME: if no params, then what? |
60 | 63 | |
61 | | -if ($near != "") { |
| 64 | +if ($maparea != "") { |
| 65 | + $bsl = new maparea( $maparea ); |
| 66 | + $bsl->show(); |
| 67 | +} else if ($near != "") { |
62 | 68 | $bsl = new neighbors( $near, $dist, $title ); |
63 | 69 | $bsl->show(); |
64 | 70 | } else { |