Property changes on: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 1 | + native |
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMQP.php |
— | — | @@ -1,95 +1,95 @@ |
2 | | -<?php
|
3 | | -
|
4 | | -/**
|
5 | | - * A query printer for maps using the Open Layers API optimized for OSM
|
6 | | - *
|
7 | | - * @file SM_OSMQP.php
|
8 | | - * @ingroup SMOSM
|
9 | | - *
|
10 | | - * @author Jeroen De Dauw
|
11 | | - */
|
12 | | -
|
13 | | -if( !defined( 'MEDIAWIKI' ) ) {
|
14 | | - die( 'Not an entry point.' );
|
15 | | -}
|
16 | | -
|
17 | | -final class SMOSMQP extends SMMapPrinter {
|
18 | | -
|
19 | | - public $serviceName = MapsOSM::SERVICE_NAME;
|
20 | | -
|
21 | | - /**
|
22 | | - * @see SMMapPrinter::setQueryPrinterSettings()
|
23 | | - *
|
24 | | - */
|
25 | | - protected function setQueryPrinterSettings() {
|
26 | | - global $egMapsOSMZoom, $egMapsOSMPrefix;
|
27 | | -
|
28 | | - $this->elementNamePrefix = $egMapsOSMPrefix;
|
29 | | - $this->defaultZoom = $egMapsOSMZoom;
|
30 | | -
|
31 | | - $this->spesificParameters = array(
|
32 | | - 'zoom' => array(
|
33 | | - 'default' => '',
|
34 | | - )
|
35 | | - );
|
36 | | - }
|
37 | | -
|
38 | | - /**
|
39 | | - * @see SMMapPrinter::doMapServiceLoad()
|
40 | | - *
|
41 | | - */
|
42 | | - protected function doMapServiceLoad() {
|
43 | | - global $egOSMMapsOnThisPage;
|
44 | | -
|
45 | | - MapsOSM::addOSMDependencies($this->output);
|
46 | | - $egOSMMapsOnThisPage++;
|
47 | | -
|
48 | | - $this->elementNr = $egOSMMapsOnThisPage;
|
49 | | - }
|
50 | | -
|
51 | | - /**
|
52 | | - * @see SMMapPrinter::addSpecificMapHTML()
|
53 | | - *
|
54 | | - */
|
55 | | - protected function addSpecificMapHTML() {
|
56 | | - global $wgJsMimeType;
|
57 | | -
|
58 | | - $markerItems = array();
|
59 | | -
|
60 | | - foreach ($this->m_locations as $location) {
|
61 | | - // Create a string containing the marker JS
|
62 | | - list($lat, $lon, $title, $label, $icon) = $location;
|
63 | | -
|
64 | | - $title = str_replace("'", "\'", $title);
|
65 | | - $label = str_replace("'", "\'", $label);
|
66 | | -
|
67 | | - $markerItems[] = "getOSMMarkerData($lon, $lat, '$title', '$label', '$icon')";
|
68 | | - }
|
69 | | -
|
70 | | - $markersString = implode(',', $markerItems);
|
71 | | -
|
72 | | - $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls));
|
73 | | -
|
74 | | - $this->output .= <<<EOT
|
75 | | - <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', {
|
76 | | - mode: 'osm-wm',
|
77 | | - layer: 'osm-like',
|
78 | | - locale: '$this->lang',
|
79 | | - lat: $this->centre_lat,
|
80 | | - lon: $this->centre_lon,
|
81 | | - zoom: $this->zoom,
|
82 | | - width: $this->width,
|
83 | | - height: $this->height,
|
84 | | - markers: [$markersString],
|
85 | | - controls: [$controlItems]
|
86 | | - });</script>
|
87 | | -
|
88 | | - <!-- map div -->
|
89 | | - <div id='$this->mapName' class='map' style='width:{$this->width}px; height:{$this->height}px;'>
|
90 | | - <script type='$wgJsMimeType'>slippymaps['$this->mapName'].init();</script>
|
91 | | - <!-- /map div -->
|
92 | | - </div>
|
93 | | -EOT;
|
94 | | - }
|
95 | | -
|
96 | | -}
|
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * A query printer for maps using the Open Layers API optimized for OSM |
| 6 | + * |
| 7 | + * @file SM_OSMQP.php |
| 8 | + * @ingroup SMOSM |
| 9 | + * |
| 10 | + * @author Jeroen De Dauw |
| 11 | + */ |
| 12 | + |
| 13 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 14 | + die( 'Not an entry point.' ); |
| 15 | +} |
| 16 | + |
| 17 | +final class SMOSMQP extends SMMapPrinter { |
| 18 | + |
| 19 | + public $serviceName = MapsOSM::SERVICE_NAME; |
| 20 | + |
| 21 | + /** |
| 22 | + * @see SMMapPrinter::setQueryPrinterSettings() |
| 23 | + * |
| 24 | + */ |
| 25 | + protected function setQueryPrinterSettings() { |
| 26 | + global $egMapsOSMZoom, $egMapsOSMPrefix; |
| 27 | + |
| 28 | + $this->elementNamePrefix = $egMapsOSMPrefix; |
| 29 | + $this->defaultZoom = $egMapsOSMZoom; |
| 30 | + |
| 31 | + $this->spesificParameters = array( |
| 32 | + 'zoom' => array( |
| 33 | + 'default' => '', |
| 34 | + ) |
| 35 | + ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * @see SMMapPrinter::doMapServiceLoad() |
| 40 | + * |
| 41 | + */ |
| 42 | + protected function doMapServiceLoad() { |
| 43 | + global $egOSMMapsOnThisPage; |
| 44 | + |
| 45 | + MapsOSM::addOSMDependencies($this->output); |
| 46 | + $egOSMMapsOnThisPage++; |
| 47 | + |
| 48 | + $this->elementNr = $egOSMMapsOnThisPage; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @see SMMapPrinter::addSpecificMapHTML() |
| 53 | + * |
| 54 | + */ |
| 55 | + protected function addSpecificMapHTML() { |
| 56 | + global $wgJsMimeType; |
| 57 | + |
| 58 | + $markerItems = array(); |
| 59 | + |
| 60 | + foreach ($this->m_locations as $location) { |
| 61 | + // Create a string containing the marker JS |
| 62 | + list($lat, $lon, $title, $label, $icon) = $location; |
| 63 | + |
| 64 | + $title = str_replace("'", "\'", $title); |
| 65 | + $label = str_replace("'", "\'", $label); |
| 66 | + |
| 67 | + $markerItems[] = "getOSMMarkerData($lon, $lat, '$title', '$label', '$icon')"; |
| 68 | + } |
| 69 | + |
| 70 | + $markersString = implode(',', $markerItems); |
| 71 | + |
| 72 | + $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
| 73 | + |
| 74 | + $this->output .= <<<EOT |
| 75 | + <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', { |
| 76 | + mode: 'osm-wm', |
| 77 | + layer: 'osm-like', |
| 78 | + locale: '$this->lang', |
| 79 | + lat: $this->centre_lat, |
| 80 | + lon: $this->centre_lon, |
| 81 | + zoom: $this->zoom, |
| 82 | + width: $this->width, |
| 83 | + height: $this->height, |
| 84 | + markers: [$markersString], |
| 85 | + controls: [$controlItems] |
| 86 | + });</script> |
| 87 | + |
| 88 | + <!-- map div --> |
| 89 | + <div id='$this->mapName' class='map' style='width:{$this->width}px; height:{$this->height}px;'> |
| 90 | + <script type='$wgJsMimeType'>slippymaps['$this->mapName'].init();</script> |
| 91 | + <!-- /map div --> |
| 92 | + </div> |
| 93 | +EOT; |
| 94 | + } |
| 95 | + |
| 96 | +} |
Property changes on: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMQP.php |
___________________________________________________________________ |
Name: svn:eol-style |
97 | 97 | + native |
Index: trunk/extensions/SemanticMaps/SM_GeoCoordsValue.php |
— | — | @@ -1,335 +1,335 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * File holding the SMGeoCoordsValue class.
|
5 | | - *
|
6 | | - * @file SM_GeoCoordsValue.php
|
7 | | - * @ingroup SMWDataValues
|
8 | | - *
|
9 | | - * @author Markus Krötzsch
|
10 | | - * @author Jeroen De Dauw
|
11 | | - */
|
12 | | -
|
13 | | -/// Unicode symbols for coordinate minutes and seconds;
|
14 | | -/// may not display in every font ...
|
15 | | -define('SM_GEO_MIN','′');
|
16 | | -define('SM_GEO_SEC','″');
|
17 | | -
|
18 | | -/**
|
19 | | - * Implementation of datavalues that are geographic coordinates.
|
20 | | - *
|
21 | | - * @author Markus Krötzsch
|
22 | | - * @author Jeroen De Dauw
|
23 | | - *
|
24 | | - * @ingroup SemanticMaps
|
25 | | - */
|
26 | | -class SMGeoCoordsValue extends SMWDataValue {
|
27 | | -
|
28 | | - protected $m_N = false; // cache for localised direction labels
|
29 | | - protected $m_E = false; // cache for localised direction labels
|
30 | | - protected $m_W = false; // cache for localised direction labels
|
31 | | - protected $m_S = false; // cache for localised direction labels
|
32 | | -
|
33 | | - protected $m_wikivalue;
|
34 | | - protected $m_lat; // decimal latitude of current value
|
35 | | - protected $m_long; // decimal longitude of current value
|
36 | | - protected $m_latparts; // latitude array of four entries: degrees, minutes, seconds, direction
|
37 | | - protected $m_longparts; // longitude array of four entries: degrees, minutes, seconds, direction
|
38 | | - // Note: signs are used as e.g. on Google maps, i.e. S and W are negative numbers.
|
39 | | -
|
40 | | - protected function parseUserValue($value) {
|
41 | | - $this->m_lat = false;
|
42 | | - $this->m_long = false;
|
43 | | - $this->m_latparts = false;
|
44 | | - $this->m_longparts = false;
|
45 | | - $this->m_wikivalue = $value;
|
46 | | -
|
47 | | - // first normalise some typical symbols
|
48 | | - $this->initDirectionLabels();
|
49 | | - $value = str_replace(array(' ', $this->m_N, $this->m_E, $this->m_W, $this->m_S, ),
|
50 | | - array(' ','N','E','W','S'),$value);
|
51 | | - $value = str_replace(array('°', '°'), '°', $value);
|
52 | | - $value = str_replace(array('´', '´'),'´',$value);
|
53 | | - $value = str_replace(array('″', '″', "''", '"', '´´', SM_GEO_MIN . SM_GEO_MIN),SM_GEO_SEC,$value);
|
54 | | - $value = str_replace(array('′', '′', "'", '´'),SM_GEO_MIN,$value);
|
55 | | - // now split the string
|
56 | | - $parts = preg_split('/\s*(°|' . SM_GEO_MIN . '|' . SM_GEO_SEC . '|N|E|W|S|;)\s*/u',str_replace(', ', ';', $value) . ';', -1, PREG_SPLIT_DELIM_CAPTURE);
|
57 | | - $curnum = false;
|
58 | | - $angles = array(false, false, false); // temporary values for deg, min, sec
|
59 | | - foreach ($parts as $part) {
|
60 | | - switch ($part) {
|
61 | | - case '°':
|
62 | | - if ( ($angles[0] !== false) && ($this->m_lat === false) ) { // work off values found earlier
|
63 | | - $this->setAngleValues('N',$angles);
|
64 | | - } // else: we do not accept interchange of order (lat must be first), so there are just too many °s
|
65 | | - if ( $curnum !== false ) {
|
66 | | - $angles[0] = $curnum;
|
67 | | - $curnum = false;
|
68 | | - } else {
|
69 | | - $this->addError(wfMsgForContent('semanticmaps_lonely_unit', $part));
|
70 | | - }
|
71 | | - break;
|
72 | | - case SM_GEO_MIN:
|
73 | | - if ( ($curnum !== false) && ($angles[1] === false) ) {
|
74 | | - $angles[1] = $curnum;
|
75 | | - if ($angles[0] === false) $angles[0] = 0;
|
76 | | - $curnum = false;
|
77 | | - } else {
|
78 | | - $this->addError(wfMsgForContent('semanticmaps_lonely_unit', $part));
|
79 | | - }
|
80 | | - break;
|
81 | | - case SM_GEO_SEC:
|
82 | | - if ( ($curnum !== false) && ($angles[2] === false) ) {
|
83 | | - $angles[2] = $curnum;
|
84 | | - if ($angles[0] === false) $angles[0] = 0;
|
85 | | - if ($angles[1] === false) $angles[1] = 0;
|
86 | | - $curnum = false;
|
87 | | - } else {
|
88 | | - $this->addError(wfMsgForContent('semanticmaps_lonely_unit', $part));
|
89 | | - }
|
90 | | - break;
|
91 | | - case 'N': case 'S': // interpret findings as latitude
|
92 | | - if ( $curnum !== false ) { // work off number without °
|
93 | | - if ($angles[0] !== false) { // "12° 34" as coordinate, complain
|
94 | | - $this->addError(wfMsgForContent('semanticmaps_bad_latlong'));
|
95 | | - break;
|
96 | | - } else {
|
97 | | - $angles[0] = $curnum;
|
98 | | - $curnum = false;
|
99 | | - }
|
100 | | - }
|
101 | | - if (($this->m_lat === false) && ($angles[0] !== false)) {
|
102 | | - $this->setAngleValues($part,$angles);
|
103 | | - } else {
|
104 | | - $this->addError(wfMsgForContent('semanticmaps_bad_latlong'));
|
105 | | - }
|
106 | | - break;
|
107 | | - case 'E': case 'W': // interpret findings as longitude
|
108 | | - if ( $curnum !== false ) { // work off number without °
|
109 | | - if ($angles[0] !== false) { // "12° 34" as coordinate, complain
|
110 | | - $this->addError(wfMsgForContent('semanticmaps_bad_latlong'));
|
111 | | - break;
|
112 | | - } else {
|
113 | | - $angles[0] = $curnum;
|
114 | | - $curnum = false;
|
115 | | - }
|
116 | | - }
|
117 | | - if (($this->m_long === false) && ($angles[0] !== false)) {
|
118 | | - $this->setAngleValues($part,$angles);
|
119 | | - } else {
|
120 | | - $this->addError(wfMsgForContent('semanticmaps_bad_latlong'));
|
121 | | - }
|
122 | | - break;
|
123 | | - case ';': // interpret findings as latitude
|
124 | | - if ( $curnum !== false ) { // work off number without °
|
125 | | - if ($angles[0] !== false) { // "12° 34" as coordinate, complain
|
126 | | - $this->addError(wfMsgForContent('semanticmaps_bad_latlong'));
|
127 | | - break;
|
128 | | - } else {
|
129 | | - $angles[0] = $curnum;
|
130 | | - $curnum = false;
|
131 | | - }
|
132 | | - }
|
133 | | - if (($this->m_lat === false) && ($angles[0] !== false)) {
|
134 | | - $this->setAngleValues('N',$angles);
|
135 | | - } // else: ignore ";" without complaining
|
136 | | - break;
|
137 | | - case '': break; // ignore
|
138 | | - default: // should be a number (if not, errors appear elsewhere)
|
139 | | - // no kiloseps in coordinates, use as decsep as a convenience to some users (Bug 11808):
|
140 | | - $curnum = str_replace(wfMsgForContent('semanticmaps_kiloseparator'), wfMsgForContent('semanticmaps_decseparator'), $part);
|
141 | | - break;
|
142 | | - }
|
143 | | - }
|
144 | | -
|
145 | | - if ( ($this->m_lat !== false) && ($this->m_long === false) && ($angles[0] !== false) ) { // no final E or W?
|
146 | | - $this->setAngleValues('E',$angles);
|
147 | | - }
|
148 | | - if ( ($angles[0] !== false)||($curnum !== false)) { // unprocessed chunk, error
|
149 | | -
|
150 | | - }
|
151 | | -
|
152 | | - if ($this->m_caption === false) {
|
153 | | - $this->m_caption = $value;
|
154 | | - }
|
155 | | - return true;
|
156 | | - }
|
157 | | -
|
158 | | - protected function parseDBkeys($args) {
|
159 | | - $this->m_lat = false;
|
160 | | - $this->m_long = false;
|
161 | | - $this->m_latparts = false;
|
162 | | - $this->m_longparts = false;
|
163 | | -
|
164 | | - list($this->m_lat, $this->m_long) = explode(',', $args[0]);
|
165 | | - $this->m_caption = $this->formatAngleValues(true) . ', ' . $this->formatAngleValues(false); // this is our output text
|
166 | | - $this->m_wikivalue = $this->m_caption;
|
167 | | - }
|
168 | | -
|
169 | | - public function getShortWikiText($linked = NULL) {
|
170 | | - if ($this->isValid() && ($linked !== NULL) && ($linked !== false)) {
|
171 | | - SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP);
|
172 | | - return '<span class="smwttinline">' . $this->m_caption . '<span class="smwttcontent">' .
|
173 | | - wfMsgForContent('semanticmaps_label_latitude') . ' ' . $this->formatAngleValues(true) . '<br />' .
|
174 | | - wfMsgForContent('semanticmaps_label_longitude') . ' ' . $this->formatAngleValues(false) .
|
175 | | - '</span></span>';
|
176 | | - } else {
|
177 | | - return $this->m_caption;
|
178 | | - }
|
179 | | - }
|
180 | | -
|
181 | | - public function getShortHTMLText($linker = NULL) {
|
182 | | - return $this->getShortWikiText($linker); // should be save (based on xsdvalue)
|
183 | | - }
|
184 | | -
|
185 | | - public function getLongWikiText($linked = NULL) {
|
186 | | - if (!$this->isValid()) {
|
187 | | - return $this->getErrorText();
|
188 | | - } else {
|
189 | | - return $this->formatAngleValues(true) . ', ' . $this->formatAngleValues(false);
|
190 | | - }
|
191 | | - }
|
192 | | -
|
193 | | - public function getLongHTMLText($linker = NULL) {
|
194 | | - return $this->getLongWikiText($linker);
|
195 | | - }
|
196 | | -
|
197 | | - public function getDBkeys() {
|
198 | | - $this->unstub();
|
199 | | - return array($this->m_lat . ',' . $this->m_long);
|
200 | | - }
|
201 | | -
|
202 | | - public function getWikiValue(){
|
203 | | - $this->unstub();
|
204 | | - return $this->m_wikivalue;
|
205 | | - }
|
206 | | -
|
207 | | - public function getExportData() {
|
208 | | - if ($this->isValid()) {
|
209 | | - $lit = new SMWExpLiteral($this->formatAngleValues(true, false) . ', ' . $this->formatAngleValues(false, false), $this, 'http://www.w3.org/2001/XMLSchema#string');
|
210 | | - return new SMWExpData($lit);
|
211 | | - } else {
|
212 | | - return NULL;
|
213 | | - }
|
214 | | - }
|
215 | | -
|
216 | | - /**
|
217 | | - * Get and cache localised direction labels. Just for convenience.
|
218 | | - */
|
219 | | - protected function initDirectionLabels() {
|
220 | | - $this->m_N = wfMsgForContent('semanticmaps_abb_north');
|
221 | | - $this->m_E = wfMsgForContent('semanticmaps_abb_east');
|
222 | | - $this->m_W = wfMsgForContent('semanticmaps_abb_west');
|
223 | | - $this->m_S = wfMsgForContent('semanticmaps_abb_south');
|
224 | | - }
|
225 | | -
|
226 | | - /**
|
227 | | - * Helper function: read a possibly incomplete array of angles for one coordinate.
|
228 | | - * The direction is one of N, E, W, S, and $angles is an array of three values,
|
229 | | - * each possibly false if unset.
|
230 | | - */
|
231 | | - protected function setAngleValues($direction, &$angles) {
|
232 | | - $numvalue = SMWDataValueFactory::newTypeIDValue('_num');
|
233 | | - $res = 0;
|
234 | | - $factor = 1;
|
235 | | - for ($i=0; $i<3; $i++) {
|
236 | | - if ($angles[$i] !== false) {
|
237 | | - $numvalue->setUserValue($angles[$i]);
|
238 | | - if ($numvalue->isValid() && ($numvalue->getUnit() == '')) {
|
239 | | - $res += $numvalue->getNumericValue() / $factor;
|
240 | | - } else {
|
241 | | - $this->addError(wfMsgForContent('semanticmaps_nofloat', $angles[$i]));
|
242 | | - }
|
243 | | - }
|
244 | | - $factor = $factor * 60;
|
245 | | - }
|
246 | | - switch ($direction) {
|
247 | | - case 'N': $this->m_lat = $res; break;
|
248 | | - case 'S': $this->m_lat = -1 * $res; break;
|
249 | | - case 'E': $this->m_long = $res; break;
|
250 | | - case 'W': $this->m_long = -1 * $res; break;
|
251 | | - }
|
252 | | - if ( (($direction == 'E') || ($direction == 'W')) &&
|
253 | | - (($this->m_long > 180) || ($this->m_long <= -180)) ) { // bring values back into [180, -180)
|
254 | | - $this->m_long += ($this->m_long<0)?(round(abs($this->m_long)/360)*360):(round($this->m_long/360)*-360);
|
255 | | - }
|
256 | | - ///TODO: also make such a normalisation for lat ...
|
257 | | - $angles = array(false, false, false);
|
258 | | - }
|
259 | | -
|
260 | | - /**
|
261 | | - * Return array with four entries for deg, min, sec, direction,
|
262 | | - * that corresponds to the current latitude or longitude.
|
263 | | - */
|
264 | | - protected function getAngleValues($lat = true) {
|
265 | | - if ($lat) {
|
266 | | - if ($this->m_latparts !== false) {
|
267 | | - return $this->m_latparts;
|
268 | | - }
|
269 | | - $num = abs($this->m_lat);
|
270 | | - $d = ($this->m_lat<0)?'S':'N';
|
271 | | - } else {
|
272 | | - if ($this->m_longparts !== false) {
|
273 | | - return $this->m_longparts;
|
274 | | - }
|
275 | | - $num = abs($this->m_long);
|
276 | | - $d = ($this->m_long<0)?'W':'E';
|
277 | | - }
|
278 | | - $result = array(0,0,0,$d);
|
279 | | - $result[0] = floor($num);
|
280 | | - $num = ($num-$result[0]) * 60;
|
281 | | - $result[1] = floor($num);
|
282 | | - $result[2] = ($num-$result[1]) * 60;
|
283 | | - if ( abs($result[2]) < 0.001 ) { // limit precission, avoid conversion generated junk and EXP notation in coords
|
284 | | - $result[2] = 0;
|
285 | | - }
|
286 | | - if ($lat) {
|
287 | | - $this->m_latparts = $result;
|
288 | | - } else {
|
289 | | - $this->m_longparts = $result;
|
290 | | - }
|
291 | | - return $result;
|
292 | | - }
|
293 | | -
|
294 | | - /**
|
295 | | - * Format the current latitude or longitude. The parameter $content states
|
296 | | - * whether the result is for content printout. Alternatively, a language-
|
297 | | - * independent result is generated.
|
298 | | - */
|
299 | | - protected function formatAngleValues($lat = true, $content = true) {
|
300 | | - $values = $this->getAngleValues($lat);
|
301 | | - if ($content) {
|
302 | | - $this->initDirectionLabels();
|
303 | | - $result = smwfNumberFormat($values[0]) . '°' . smwfNumberFormat($values[1]) . SM_GEO_MIN .
|
304 | | - smwfNumberFormat($values[2]) . SM_GEO_SEC;
|
305 | | - switch ($values[3]) {
|
306 | | - case 'N': return $result . $this->m_N;
|
307 | | - case 'E': return $result . $this->m_E;
|
308 | | - case 'W': return $result . $this->m_W;
|
309 | | - case 'S': return $result . $this->m_S;
|
310 | | - }
|
311 | | - } else {
|
312 | | - return smwfNumberFormat($values[0]) . '°' . smwfNumberFormat($values[1]) . SM_GEO_MIN .
|
313 | | - smwfNumberFormat($values[2]) . SM_GEO_SEC . $values[3];
|
314 | | - }
|
315 | | - }
|
316 | | -
|
317 | | - protected function getServiceLinkParams() {
|
318 | | - // Create links to mapping services based on a wiki-editable message. The parameters
|
319 | | - // available to the message are:
|
320 | | - // $1: latitude integer degrees, $2: longitude integer degrees
|
321 | | - // $3: latitude integer minutes, $4: longitude integer minutes
|
322 | | - // $5: latitude integer seconds, $6: longitude integer seconds,
|
323 | | - // $7: latitude direction string (N or S), $8: longitude direction string (W or E)
|
324 | | - // $9: latitude in decimal degrees, $10: longitude in decimal degrees
|
325 | | - // $11: sign (- if south) for latitude, $12: sign (- if west) for longitude
|
326 | | - $latvals = $this->getAngleValues(true);
|
327 | | - $longvals = $this->getAngleValues(false);
|
328 | | - return array($latvals[0], $longvals[0],
|
329 | | - $latvals[1], $longvals[1],
|
330 | | - round($latvals[2]), round($longvals[2]),
|
331 | | - $latvals[3], $longvals[3],
|
332 | | - abs($this->m_lat), abs($this->m_long),
|
333 | | - $latvals[3]=='S'?'-':'', $longvals[3]=='W'?'-':'');
|
334 | | - }
|
335 | | -
|
336 | | -}
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * File holding the SMGeoCoordsValue class. |
| 5 | + * |
| 6 | + * @file SM_GeoCoordsValue.php |
| 7 | + * @ingroup SMWDataValues |
| 8 | + * |
| 9 | + * @author Markus Krötzsch |
| 10 | + * @author Jeroen De Dauw |
| 11 | + */ |
| 12 | + |
| 13 | +/// Unicode symbols for coordinate minutes and seconds; |
| 14 | +/// may not display in every font ... |
| 15 | +define('SM_GEO_MIN','′'); |
| 16 | +define('SM_GEO_SEC','″'); |
| 17 | + |
| 18 | +/** |
| 19 | + * Implementation of datavalues that are geographic coordinates. |
| 20 | + * |
| 21 | + * @author Markus Krötzsch |
| 22 | + * @author Jeroen De Dauw |
| 23 | + * |
| 24 | + * @ingroup SemanticMaps |
| 25 | + */ |
| 26 | +class SMGeoCoordsValue extends SMWDataValue { |
| 27 | + |
| 28 | + protected $m_N = false; // cache for localised direction labels |
| 29 | + protected $m_E = false; // cache for localised direction labels |
| 30 | + protected $m_W = false; // cache for localised direction labels |
| 31 | + protected $m_S = false; // cache for localised direction labels |
| 32 | + |
| 33 | + protected $m_wikivalue; |
| 34 | + protected $m_lat; // decimal latitude of current value |
| 35 | + protected $m_long; // decimal longitude of current value |
| 36 | + protected $m_latparts; // latitude array of four entries: degrees, minutes, seconds, direction |
| 37 | + protected $m_longparts; // longitude array of four entries: degrees, minutes, seconds, direction |
| 38 | + // Note: signs are used as e.g. on Google maps, i.e. S and W are negative numbers. |
| 39 | + |
| 40 | + protected function parseUserValue($value) { |
| 41 | + $this->m_lat = false; |
| 42 | + $this->m_long = false; |
| 43 | + $this->m_latparts = false; |
| 44 | + $this->m_longparts = false; |
| 45 | + $this->m_wikivalue = $value; |
| 46 | + |
| 47 | + // first normalise some typical symbols |
| 48 | + $this->initDirectionLabels(); |
| 49 | + $value = str_replace(array(' ', $this->m_N, $this->m_E, $this->m_W, $this->m_S, ), |
| 50 | + array(' ','N','E','W','S'),$value); |
| 51 | + $value = str_replace(array('°', '°'), '°', $value); |
| 52 | + $value = str_replace(array('´', '´'),'´',$value); |
| 53 | + $value = str_replace(array('″', '″', "''", '"', '´´', SM_GEO_MIN . SM_GEO_MIN),SM_GEO_SEC,$value); |
| 54 | + $value = str_replace(array('′', '′', "'", '´'),SM_GEO_MIN,$value); |
| 55 | + // now split the string |
| 56 | + $parts = preg_split('/\s*(°|' . SM_GEO_MIN . '|' . SM_GEO_SEC . '|N|E|W|S|;)\s*/u',str_replace(', ', ';', $value) . ';', -1, PREG_SPLIT_DELIM_CAPTURE); |
| 57 | + $curnum = false; |
| 58 | + $angles = array(false, false, false); // temporary values for deg, min, sec |
| 59 | + foreach ($parts as $part) { |
| 60 | + switch ($part) { |
| 61 | + case '°': |
| 62 | + if ( ($angles[0] !== false) && ($this->m_lat === false) ) { // work off values found earlier |
| 63 | + $this->setAngleValues('N',$angles); |
| 64 | + } // else: we do not accept interchange of order (lat must be first), so there are just too many °s |
| 65 | + if ( $curnum !== false ) { |
| 66 | + $angles[0] = $curnum; |
| 67 | + $curnum = false; |
| 68 | + } else { |
| 69 | + $this->addError(wfMsgForContent('semanticmaps_lonely_unit', $part)); |
| 70 | + } |
| 71 | + break; |
| 72 | + case SM_GEO_MIN: |
| 73 | + if ( ($curnum !== false) && ($angles[1] === false) ) { |
| 74 | + $angles[1] = $curnum; |
| 75 | + if ($angles[0] === false) $angles[0] = 0; |
| 76 | + $curnum = false; |
| 77 | + } else { |
| 78 | + $this->addError(wfMsgForContent('semanticmaps_lonely_unit', $part)); |
| 79 | + } |
| 80 | + break; |
| 81 | + case SM_GEO_SEC: |
| 82 | + if ( ($curnum !== false) && ($angles[2] === false) ) { |
| 83 | + $angles[2] = $curnum; |
| 84 | + if ($angles[0] === false) $angles[0] = 0; |
| 85 | + if ($angles[1] === false) $angles[1] = 0; |
| 86 | + $curnum = false; |
| 87 | + } else { |
| 88 | + $this->addError(wfMsgForContent('semanticmaps_lonely_unit', $part)); |
| 89 | + } |
| 90 | + break; |
| 91 | + case 'N': case 'S': // interpret findings as latitude |
| 92 | + if ( $curnum !== false ) { // work off number without ° |
| 93 | + if ($angles[0] !== false) { // "12° 34" as coordinate, complain |
| 94 | + $this->addError(wfMsgForContent('semanticmaps_bad_latlong')); |
| 95 | + break; |
| 96 | + } else { |
| 97 | + $angles[0] = $curnum; |
| 98 | + $curnum = false; |
| 99 | + } |
| 100 | + } |
| 101 | + if (($this->m_lat === false) && ($angles[0] !== false)) { |
| 102 | + $this->setAngleValues($part,$angles); |
| 103 | + } else { |
| 104 | + $this->addError(wfMsgForContent('semanticmaps_bad_latlong')); |
| 105 | + } |
| 106 | + break; |
| 107 | + case 'E': case 'W': // interpret findings as longitude |
| 108 | + if ( $curnum !== false ) { // work off number without ° |
| 109 | + if ($angles[0] !== false) { // "12° 34" as coordinate, complain |
| 110 | + $this->addError(wfMsgForContent('semanticmaps_bad_latlong')); |
| 111 | + break; |
| 112 | + } else { |
| 113 | + $angles[0] = $curnum; |
| 114 | + $curnum = false; |
| 115 | + } |
| 116 | + } |
| 117 | + if (($this->m_long === false) && ($angles[0] !== false)) { |
| 118 | + $this->setAngleValues($part,$angles); |
| 119 | + } else { |
| 120 | + $this->addError(wfMsgForContent('semanticmaps_bad_latlong')); |
| 121 | + } |
| 122 | + break; |
| 123 | + case ';': // interpret findings as latitude |
| 124 | + if ( $curnum !== false ) { // work off number without ° |
| 125 | + if ($angles[0] !== false) { // "12° 34" as coordinate, complain |
| 126 | + $this->addError(wfMsgForContent('semanticmaps_bad_latlong')); |
| 127 | + break; |
| 128 | + } else { |
| 129 | + $angles[0] = $curnum; |
| 130 | + $curnum = false; |
| 131 | + } |
| 132 | + } |
| 133 | + if (($this->m_lat === false) && ($angles[0] !== false)) { |
| 134 | + $this->setAngleValues('N',$angles); |
| 135 | + } // else: ignore ";" without complaining |
| 136 | + break; |
| 137 | + case '': break; // ignore |
| 138 | + default: // should be a number (if not, errors appear elsewhere) |
| 139 | + // no kiloseps in coordinates, use as decsep as a convenience to some users (Bug 11808): |
| 140 | + $curnum = str_replace(wfMsgForContent('semanticmaps_kiloseparator'), wfMsgForContent('semanticmaps_decseparator'), $part); |
| 141 | + break; |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + if ( ($this->m_lat !== false) && ($this->m_long === false) && ($angles[0] !== false) ) { // no final E or W? |
| 146 | + $this->setAngleValues('E',$angles); |
| 147 | + } |
| 148 | + if ( ($angles[0] !== false)||($curnum !== false)) { // unprocessed chunk, error |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | + if ($this->m_caption === false) { |
| 153 | + $this->m_caption = $value; |
| 154 | + } |
| 155 | + return true; |
| 156 | + } |
| 157 | + |
| 158 | + protected function parseDBkeys($args) { |
| 159 | + $this->m_lat = false; |
| 160 | + $this->m_long = false; |
| 161 | + $this->m_latparts = false; |
| 162 | + $this->m_longparts = false; |
| 163 | + |
| 164 | + list($this->m_lat, $this->m_long) = explode(',', $args[0]); |
| 165 | + $this->m_caption = $this->formatAngleValues(true) . ', ' . $this->formatAngleValues(false); // this is our output text |
| 166 | + $this->m_wikivalue = $this->m_caption; |
| 167 | + } |
| 168 | + |
| 169 | + public function getShortWikiText($linked = NULL) { |
| 170 | + if ($this->isValid() && ($linked !== NULL) && ($linked !== false)) { |
| 171 | + SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP); |
| 172 | + return '<span class="smwttinline">' . $this->m_caption . '<span class="smwttcontent">' . |
| 173 | + wfMsgForContent('semanticmaps_label_latitude') . ' ' . $this->formatAngleValues(true) . '<br />' . |
| 174 | + wfMsgForContent('semanticmaps_label_longitude') . ' ' . $this->formatAngleValues(false) . |
| 175 | + '</span></span>'; |
| 176 | + } else { |
| 177 | + return $this->m_caption; |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + public function getShortHTMLText($linker = NULL) { |
| 182 | + return $this->getShortWikiText($linker); // should be save (based on xsdvalue) |
| 183 | + } |
| 184 | + |
| 185 | + public function getLongWikiText($linked = NULL) { |
| 186 | + if (!$this->isValid()) { |
| 187 | + return $this->getErrorText(); |
| 188 | + } else { |
| 189 | + return $this->formatAngleValues(true) . ', ' . $this->formatAngleValues(false); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + public function getLongHTMLText($linker = NULL) { |
| 194 | + return $this->getLongWikiText($linker); |
| 195 | + } |
| 196 | + |
| 197 | + public function getDBkeys() { |
| 198 | + $this->unstub(); |
| 199 | + return array($this->m_lat . ',' . $this->m_long); |
| 200 | + } |
| 201 | + |
| 202 | + public function getWikiValue(){ |
| 203 | + $this->unstub(); |
| 204 | + return $this->m_wikivalue; |
| 205 | + } |
| 206 | + |
| 207 | + public function getExportData() { |
| 208 | + if ($this->isValid()) { |
| 209 | + $lit = new SMWExpLiteral($this->formatAngleValues(true, false) . ', ' . $this->formatAngleValues(false, false), $this, 'http://www.w3.org/2001/XMLSchema#string'); |
| 210 | + return new SMWExpData($lit); |
| 211 | + } else { |
| 212 | + return NULL; |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + /** |
| 217 | + * Get and cache localised direction labels. Just for convenience. |
| 218 | + */ |
| 219 | + protected function initDirectionLabels() { |
| 220 | + $this->m_N = wfMsgForContent('semanticmaps_abb_north'); |
| 221 | + $this->m_E = wfMsgForContent('semanticmaps_abb_east'); |
| 222 | + $this->m_W = wfMsgForContent('semanticmaps_abb_west'); |
| 223 | + $this->m_S = wfMsgForContent('semanticmaps_abb_south'); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Helper function: read a possibly incomplete array of angles for one coordinate. |
| 228 | + * The direction is one of N, E, W, S, and $angles is an array of three values, |
| 229 | + * each possibly false if unset. |
| 230 | + */ |
| 231 | + protected function setAngleValues($direction, &$angles) { |
| 232 | + $numvalue = SMWDataValueFactory::newTypeIDValue('_num'); |
| 233 | + $res = 0; |
| 234 | + $factor = 1; |
| 235 | + for ($i=0; $i<3; $i++) { |
| 236 | + if ($angles[$i] !== false) { |
| 237 | + $numvalue->setUserValue($angles[$i]); |
| 238 | + if ($numvalue->isValid() && ($numvalue->getUnit() == '')) { |
| 239 | + $res += $numvalue->getNumericValue() / $factor; |
| 240 | + } else { |
| 241 | + $this->addError(wfMsgForContent('semanticmaps_nofloat', $angles[$i])); |
| 242 | + } |
| 243 | + } |
| 244 | + $factor = $factor * 60; |
| 245 | + } |
| 246 | + switch ($direction) { |
| 247 | + case 'N': $this->m_lat = $res; break; |
| 248 | + case 'S': $this->m_lat = -1 * $res; break; |
| 249 | + case 'E': $this->m_long = $res; break; |
| 250 | + case 'W': $this->m_long = -1 * $res; break; |
| 251 | + } |
| 252 | + if ( (($direction == 'E') || ($direction == 'W')) && |
| 253 | + (($this->m_long > 180) || ($this->m_long <= -180)) ) { // bring values back into [180, -180) |
| 254 | + $this->m_long += ($this->m_long<0)?(round(abs($this->m_long)/360)*360):(round($this->m_long/360)*-360); |
| 255 | + } |
| 256 | + ///TODO: also make such a normalisation for lat ... |
| 257 | + $angles = array(false, false, false); |
| 258 | + } |
| 259 | + |
| 260 | + /** |
| 261 | + * Return array with four entries for deg, min, sec, direction, |
| 262 | + * that corresponds to the current latitude or longitude. |
| 263 | + */ |
| 264 | + protected function getAngleValues($lat = true) { |
| 265 | + if ($lat) { |
| 266 | + if ($this->m_latparts !== false) { |
| 267 | + return $this->m_latparts; |
| 268 | + } |
| 269 | + $num = abs($this->m_lat); |
| 270 | + $d = ($this->m_lat<0)?'S':'N'; |
| 271 | + } else { |
| 272 | + if ($this->m_longparts !== false) { |
| 273 | + return $this->m_longparts; |
| 274 | + } |
| 275 | + $num = abs($this->m_long); |
| 276 | + $d = ($this->m_long<0)?'W':'E'; |
| 277 | + } |
| 278 | + $result = array(0,0,0,$d); |
| 279 | + $result[0] = floor($num); |
| 280 | + $num = ($num-$result[0]) * 60; |
| 281 | + $result[1] = floor($num); |
| 282 | + $result[2] = ($num-$result[1]) * 60; |
| 283 | + if ( abs($result[2]) < 0.001 ) { // limit precission, avoid conversion generated junk and EXP notation in coords |
| 284 | + $result[2] = 0; |
| 285 | + } |
| 286 | + if ($lat) { |
| 287 | + $this->m_latparts = $result; |
| 288 | + } else { |
| 289 | + $this->m_longparts = $result; |
| 290 | + } |
| 291 | + return $result; |
| 292 | + } |
| 293 | + |
| 294 | + /** |
| 295 | + * Format the current latitude or longitude. The parameter $content states |
| 296 | + * whether the result is for content printout. Alternatively, a language- |
| 297 | + * independent result is generated. |
| 298 | + */ |
| 299 | + protected function formatAngleValues($lat = true, $content = true) { |
| 300 | + $values = $this->getAngleValues($lat); |
| 301 | + if ($content) { |
| 302 | + $this->initDirectionLabels(); |
| 303 | + $result = smwfNumberFormat($values[0]) . '°' . smwfNumberFormat($values[1]) . SM_GEO_MIN . |
| 304 | + smwfNumberFormat($values[2]) . SM_GEO_SEC; |
| 305 | + switch ($values[3]) { |
| 306 | + case 'N': return $result . $this->m_N; |
| 307 | + case 'E': return $result . $this->m_E; |
| 308 | + case 'W': return $result . $this->m_W; |
| 309 | + case 'S': return $result . $this->m_S; |
| 310 | + } |
| 311 | + } else { |
| 312 | + return smwfNumberFormat($values[0]) . '°' . smwfNumberFormat($values[1]) . SM_GEO_MIN . |
| 313 | + smwfNumberFormat($values[2]) . SM_GEO_SEC . $values[3]; |
| 314 | + } |
| 315 | + } |
| 316 | + |
| 317 | + protected function getServiceLinkParams() { |
| 318 | + // Create links to mapping services based on a wiki-editable message. The parameters |
| 319 | + // available to the message are: |
| 320 | + // $1: latitude integer degrees, $2: longitude integer degrees |
| 321 | + // $3: latitude integer minutes, $4: longitude integer minutes |
| 322 | + // $5: latitude integer seconds, $6: longitude integer seconds, |
| 323 | + // $7: latitude direction string (N or S), $8: longitude direction string (W or E) |
| 324 | + // $9: latitude in decimal degrees, $10: longitude in decimal degrees |
| 325 | + // $11: sign (- if south) for latitude, $12: sign (- if west) for longitude |
| 326 | + $latvals = $this->getAngleValues(true); |
| 327 | + $longvals = $this->getAngleValues(false); |
| 328 | + return array($latvals[0], $longvals[0], |
| 329 | + $latvals[1], $longvals[1], |
| 330 | + round($latvals[2]), round($longvals[2]), |
| 331 | + $latvals[3], $longvals[3], |
| 332 | + abs($this->m_lat), abs($this->m_long), |
| 333 | + $latvals[3]=='S'?'-':'', $longvals[3]=='W'?'-':''); |
| 334 | + } |
| 335 | + |
| 336 | +} |
Property changes on: trunk/extensions/SemanticMaps/SM_GeoCoordsValue.php |
___________________________________________________________________ |
Name: svn:eol-style |
337 | 337 | + native |
Property changes on: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html |
___________________________________________________________________ |
Name: svn:eol-style |
338 | 338 | + native |