Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3MultiInput.php |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Google Maps v3 form input class for multiple locations. |
| 6 | + * |
| 7 | + * @since 0.8 |
| 8 | + * @file SM_GoogleMaps3MultiInput.php |
| 9 | + * @ingroup SemanticMaps |
| 10 | + * |
| 11 | + * @licence GNU GPL v3 |
| 12 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 13 | + */ |
| 14 | +class SMGoogleMaps3MultiInput extends SMFormInput { |
| 15 | + |
| 16 | + /** |
| 17 | + * @see SMFormInput::getResourceModules |
| 18 | + * |
| 19 | + * @since 0.8 |
| 20 | + * |
| 21 | + * @return array of string |
| 22 | + */ |
| 23 | + protected function getResourceModules() { |
| 24 | + return array_merge( parent::getResourceModules(), array( 'ext.sm.fi.googlemaps3.multi' ) ); |
| 25 | + } |
| 26 | + |
| 27 | + public static function onInputRequest( $coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args ) { |
| 28 | + $formInput = new self( MapsMappingServices::getServiceInstance( 'googlemaps3' ) ); |
| 29 | + return $formInput->getInputOutput( $coordinates, $input_name, $is_mandatory, $is_disabled, $field_args ); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Returns a PHP object to encode to JSON with the map data. |
| 34 | + * |
| 35 | + * @since 0.8 |
| 36 | + * |
| 37 | + * @param array $params |
| 38 | + * @param Parser $parser |
| 39 | + * |
| 40 | + * @return mixed |
| 41 | + */ |
| 42 | + protected function getJSONObject( array $params, Parser $parser ) { |
| 43 | + $params['ismulti'] = true; |
| 44 | + |
| 45 | + return $params; |
| 46 | + } |
| 47 | + |
| 48 | +} |
Property changes on: branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3MultiInput.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 49 | + native |
Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3.php |
— | — | @@ -23,31 +23,61 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -$wgResourceModules['ext.sm.fi.googlemaps3'] = array( |
28 | | - 'dependencies' => array( 'ext.maps.googlemaps3', 'jquery.ui.button', 'jquery.ui.dialog' ), |
| 27 | +$moduleTemplate = array( |
29 | 28 | 'localBasePath' => dirname( __FILE__ ), |
30 | 29 | 'remoteBasePath' => $smgScriptPath . '/includes/services/GoogleMaps3', |
31 | 30 | 'group' => 'ext.semanticmaps', |
| 31 | +); |
| 32 | + |
| 33 | +$wgResourceModules['ext.sm.fi.googlemaps3'] = $moduleTemplate + array( |
| 34 | + 'dependencies' => array( 'ext.maps.googlemaps3' ), |
32 | 35 | 'scripts' => array( |
33 | | - 'jquery.googlemapsinput.js', |
34 | 36 | 'ext.sm.googlemapsinput.js' |
35 | 37 | ), |
| 38 | +); |
| 39 | + |
| 40 | +$wgResourceModules['ext.sm.fi.googlemaps3.single'] = $moduleTemplate + array( |
| 41 | + 'dependencies' => array( 'ext.sm.fi.googlemaps3' ), |
| 42 | + 'scripts' => array( |
| 43 | + 'jquery.googlemapsinput.js', |
| 44 | + ), |
36 | 45 | 'messages' => array( |
| 46 | + 'semanticmaps_enteraddresshere', |
| 47 | + 'semanticmaps-updatemap', |
| 48 | + 'semanticmaps_lookupcoordinates', |
37 | 49 | 'semanticmaps-forminput-remove', |
38 | 50 | 'semanticmaps-forminput-add', |
39 | 51 | 'semanticmaps-forminput-locations' |
40 | 52 | ) |
41 | 53 | ); |
42 | 54 | |
| 55 | +$wgResourceModules['ext.sm.fi.googlemaps3.multi'] = $moduleTemplate + array( |
| 56 | + 'dependencies' => array( 'ext.sm.fi.googlemaps3', 'jquery.ui.button', 'jquery.ui.dialog' ), |
| 57 | + 'localBasePath' => dirname( __FILE__ ), |
| 58 | + 'scripts' => array( |
| 59 | + 'jquery.gmapsmultiinput.js', |
| 60 | + ), |
| 61 | + 'messages' => array( |
| 62 | + 'semanticmaps-forminput-remove', |
| 63 | + 'semanticmaps-forminput-add', |
| 64 | + 'semanticmaps-forminput-locations' |
| 65 | + ) |
| 66 | +); |
| 67 | + |
| 68 | +unset( $moduleTemplate ); |
| 69 | + |
43 | 70 | $wgHooks['MappingServiceLoad'][] = 'smfInitGoogleMaps3'; |
44 | 71 | |
45 | 72 | function smfInitGoogleMaps3() { |
46 | | - global $wgAutoloadClasses; |
| 73 | + global $wgAutoloadClasses, $sfgFormPrinter; |
47 | 74 | |
48 | 75 | $wgAutoloadClasses['SMGoogleMaps3FormInput'] = dirname( __FILE__ ) . '/SM_GoogleMaps3FormInput.php'; |
| 76 | + $wgAutoloadClasses['SMGoogleMaps3MultiInput'] = dirname( __FILE__ ) . '/SM_GoogleMaps3MultiInput.php'; |
49 | 77 | |
50 | 78 | MapsMappingServices::registerServiceFeature( 'googlemaps3', 'qp', 'SMMapPrinter' ); |
51 | 79 | MapsMappingServices::registerServiceFeature( 'googlemaps3', 'fi', 'SMGoogleMaps3FormInput' ); |
52 | 80 | |
| 81 | + $sfgFormPrinter->setInputTypeHook( 'googlemapsmulti', array( 'SMGoogleMaps3MultiInput', 'onInputRequest' ), array() ); |
| 82 | + |
53 | 83 | return true; |
54 | 84 | } |
Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/ext.sm.googlemapsinput.js |
— | — | @@ -10,9 +10,14 @@ |
11 | 11 | */ |
12 | 12 | |
13 | 13 | jQuery(document).ready(function() { |
14 | | - if ( false ) { |
| 14 | + if ( true ) { // TODO |
15 | 15 | for ( i in window.maps.googlemaps3_forminputs ) { |
16 | | - jQuery( '#' + i + '_forminput' ).googlemapsinput( i, window.maps.googlemaps3_forminputs[i] ); |
| 16 | + if ( window.maps.googlemaps3_forminputs[i].ismulti ) { |
| 17 | + jQuery( '#' + i + '_forminput' ).gmapsmultiinput( i, window.maps.googlemaps3_forminputs[i] ); |
| 18 | + } |
| 19 | + else { |
| 20 | + jQuery( '#' + i + '_forminput' ).googlemapsinput( i, window.maps.googlemaps3_forminputs[i] ); |
| 21 | + } |
17 | 22 | } |
18 | 23 | } |
19 | 24 | else { |
Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js |
— | — | @@ -10,307 +10,9 @@ |
11 | 11 | */ |
12 | 12 | |
13 | 13 | (function( $ ){ $.fn.googlemapsinput = function( mapDivId, options ) { |
14 | | - var MAPFILES_URL = "http://maps.gstatic.com/intl/en_us/mapfiles/"; |
15 | | - |
16 | | - var clickIcon = new google.maps.MarkerImage( |
17 | | - MAPFILES_URL + 'dd-start.png', |
18 | | - new google.maps.Size(20, 34), |
19 | | - new google.maps.Point(0, 0), |
20 | | - new google.maps.Point(10, 34) |
21 | | - ); |
22 | | - |
23 | | - var clickMarker = null; |
24 | | - |
25 | | - var geocoder = new google.maps.Geocoder(); |
26 | | - |
27 | | - this.attr( { 'class': "ui-widget" } ).css( { 'width': 'auto' } ); |
28 | | - |
29 | | - this.html( |
30 | | - $( '<div />' ).css( { |
31 | | - 'display': 'none' |
32 | | - } ).append( $( '<input />' ).attr( { 'type': 'text', 'name': options.inputname, 'id': mapDivId + '_values' } ) ) |
33 | | - ); |
34 | | - |
35 | | - updateInputValue( semanticMaps.buildInputValue( options.locations ) ); |
36 | | - |
37 | | - var table = $( '<table />' ).attr( { 'class' : 'mapinput ui-widget ui-widget-content' } ); |
38 | | - this.append( table ); |
39 | | - |
40 | | - var mapDiv = $( '<div />' ) |
41 | | - .attr( { |
42 | | - 'id': mapDivId, |
43 | | - 'class': 'ui-widget ui-widget-content' |
44 | | - } ) |
45 | | - .css( { |
46 | | - 'width': options.width, |
47 | | - 'height': options.height |
48 | | - } ) |
49 | | - .googlemaps( options ); |
50 | | - |
51 | | - google.maps.event.addListener( mapDiv.map, 'click', onClickCallback ); |
52 | | - |
53 | | - function onClickCallback() { |
54 | | - // TODO |
55 | | - } |
56 | | - |
57 | | - table.append( |
58 | | - '<thead><tr class="ui-widget-header "><th colspan="2">' + mediaWiki.msg( 'semanticmaps-forminput-locations' ) + '</th></tr></thead><tbody>' |
59 | | - ); |
60 | | - |
61 | | - var rowNr = options.locations.length; |
62 | | - |
63 | | - for ( i in options.locations ) { |
64 | | - appendTableRow( i, options.locations[i].lat, options.locations[i].lon ); |
65 | | - } |
66 | | - |
67 | | - table.append( |
68 | | - '<tr id="' + mapDivId + '_addrow"><td width="300px">' + |
69 | | - '<input type="text" class="text ui-widget-content ui-corner-all" width="95%" id="' + mapDivId + '_addfield" />' + |
70 | | - '</td><td>' + |
71 | | - '<button id="' + mapDivId + '_addbutton" mapid="' + mapDivId + '">' + mediaWiki.msg( 'semanticmaps-forminput-add' ) + '</button>' + |
72 | | - '</td></tr></tbody>' |
73 | | - ); |
74 | | - |
75 | | - $( "#" + mapDivId + '_addbutton' ).button().click( onAddButtonClick ); |
76 | | - |
77 | | - function onAddButtonClick() { |
78 | | - var location = $( '#' + mapDivId + '_addfield' ).attr( 'value' ); |
79 | | - submitGeocodeQuery( location ); |
80 | | - return false; |
81 | | - } |
82 | | - |
83 | | - function submitGeocodeQuery( query ) { |
84 | | - if ( /\s*^\-?\d+(\.\d+)?\s*\,\s*\-?\d+(\.\d+)?\s*$/.test( query ) ) { |
85 | | - var latlng = parseLatLng(query); |
86 | | - |
87 | | - if (latlng == null) { |
88 | | - $( '#' + mapDivId + '_addfield' ).attr( 'value', '' ); |
89 | | - } else { |
90 | | - geocode({ 'latLng': latlng }); |
91 | | - } |
92 | | - } else { |
93 | | - geocode({ 'address': query }); |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - function parseLatLng(value) { |
98 | | - value.replace('/\s//g'); |
99 | | - var coords = value.split(','); |
100 | | - var lat = parseFloat(coords[0]); |
101 | | - var lng = parseFloat(coords[1]); |
102 | | - if (isNaN(lat) || isNaN(lng)) { |
103 | | - return null; |
104 | | - } else { |
105 | | - return new google.maps.LatLng(lat, lng); |
106 | | - } |
107 | | - } |
108 | | - |
109 | | - function geocode(request) { |
110 | | - var hash = ''; |
111 | | - |
112 | | - if (request.latLng) { |
113 | | - clickMarker = new google.maps.Marker({ |
114 | | - 'position': request.latLng, |
115 | | - 'map': map, |
116 | | - 'title': request.latLng.toString(), |
117 | | - 'clickable': false, |
118 | | - 'icon': clickIcon, |
119 | | - 'shadow': shadow |
120 | | - }); |
121 | | - hash = 'q=' + request.latLng.toUrlValue(6); |
122 | | - } else { |
123 | | - hash = 'q=' + request.address; |
124 | | - } |
125 | | - |
126 | | - var vpbias = false; |
127 | | - var country = ''; |
128 | | - var language = ''; |
129 | | - |
130 | | - if (vpbias) { |
131 | | - hash += '&vpcenter=' + map.getCenter().toUrlValue(6); |
132 | | - hash += '&vpzoom=' + map.getZoom(); |
133 | | - request.bounds = map.getBounds(); |
134 | | - } |
135 | | - |
136 | | - if (country) { |
137 | | - hash += '&country=' + country; |
138 | | - request.country = country; |
139 | | - } |
140 | | - |
141 | | - if (language) { |
142 | | - hash += '&language=' + language; |
143 | | - request.language = language; |
144 | | - } |
145 | 14 | |
146 | | - hashFragment = '#' + escape(hash); |
147 | | - window.location.hash = escape(hash); |
148 | | - geocoder.geocode(request, showResults); |
149 | | - } |
| 15 | + // TODO |
150 | 16 | |
151 | | - function showResults(results, status) { |
152 | | - var reverse = (clickMarker != null); // TODO |
153 | | - |
154 | | - if (! results) { |
155 | | - // TODO |
156 | | - alert("Geocoder did not return a valid response"); |
157 | | - } else { |
158 | | - //document.getElementById("statusValue").innerHTML = status; |
159 | | - |
160 | | - if (status == google.maps.GeocoderStatus.OK) { |
161 | | - //document.getElementById("matchCount").innerHTML = results.length; |
162 | | - var marker = new google.maps.Marker( { |
163 | | - map: mapDiv.map, |
164 | | - position: results[0].geometry.location, |
165 | | - title: results[0].geometry.location.toString() |
166 | | - } ); |
167 | | - addLocationRow( results[0].geometry.location.lat(), results[0].geometry.location.lng() ); |
168 | | - //plotMatchesOnMap(results, reverse); |
169 | | - } else { |
170 | | - if ( !reverse) { |
171 | | - mapDiv.map.setCenter(new google.maps.LatLng(0.0, 0.0)); |
172 | | - mapDiv.map.setZoom(1); // TODO |
173 | | - } |
174 | | - } |
175 | | - } |
176 | | - } |
177 | | - |
178 | | - function plotMatchesOnMap(results, reverse) { |
179 | | - markers = new Array(results.length); |
180 | | - var resultsListHtml = ""; |
181 | | - |
182 | | - var openInfoWindow = function(resultNum, result, marker) { |
183 | | - return function() { |
184 | | - if (selected != null) { |
185 | | - document.getElementById('p' + selected).style.backgroundColor = "white"; |
186 | | - clearBoundsOverlays(); |
187 | | - } |
188 | | - |
189 | | - map.fitBounds(result.geometry.viewport); |
190 | | - infowindow.setContent(getAddressComponentsHtml(result.address_components)); |
191 | | - infowindow.open(map, marker); |
192 | | - |
193 | | - if (result.geometry.bounds) { |
194 | | - boundsOverlay = new google.maps.Rectangle({ |
195 | | - 'bounds': result.geometry.bounds, |
196 | | - 'strokeColor': '#ff0000', |
197 | | - 'strokeOpacity': 1.0, |
198 | | - 'strokeWeight': 2.0, |
199 | | - 'fillOpacity': 0.0 |
200 | | - }); |
201 | | - boundsOverlay.setMap(map); |
202 | | - google.maps.event.addListener(boundsOverlay, 'click', onClickCallback); |
203 | | - document.getElementById('boundsLegend').style.display = 'block'; |
204 | | - } else { |
205 | | - boundsOverlay = null; |
206 | | - } |
207 | | - |
208 | | - viewportOverlay = new google.maps.Rectangle({ |
209 | | - 'bounds': result.geometry.viewport, |
210 | | - 'strokeColor': '#0000ff', |
211 | | - 'strokeOpacity': 1.0, |
212 | | - 'strokeWeight': 2.0, |
213 | | - 'fillOpacity': 0.0 |
214 | | - }); |
215 | | - viewportOverlay.setMap(map); |
216 | | - google.maps.event.addListener(viewportOverlay, 'click', onClickCallback); |
217 | | - document.getElementById('viewportLegend').style.display = 'block'; |
218 | | - |
219 | | - document.getElementById('p' + resultNum).style.backgroundColor = "#eeeeff"; |
220 | | - document.getElementById('matches').scrollTop = |
221 | | - document.getElementById('p' + resultNum).offsetTop - |
222 | | - document.getElementById('matches').offsetTop; |
223 | | - selected = resultNum; |
224 | | - } |
225 | | - } |
226 | | - |
227 | | - for (var i = 0; i < results.length; i++) { |
228 | | - var icon = new google.maps.MarkerImage( |
229 | | - getMarkerImageUrl(i), |
230 | | - new google.maps.Size(20, 34), |
231 | | - new google.maps.Point(0, 0), |
232 | | - new google.maps.Point(10, 34) |
233 | | - ); |
234 | | - |
235 | | - markers[i] = new google.maps.Marker({ |
236 | | - 'position': results[i].geometry.location, |
237 | | - 'map': map, |
238 | | - 'icon': icon, |
239 | | - 'shadow': shadow |
240 | | - }); |
241 | | - |
242 | | - google.maps.event.addListener(markers[i], 'click', openInfoWindow(i, results[i], markers[i])); |
243 | | - |
244 | | - resultsListHtml += getResultsListItem(i, getResultDescription(results[i])); |
245 | | - } |
246 | | - |
247 | | - document.getElementById("matches").innerHTML = resultsListHtml; |
248 | | - document.getElementById("p0").style.border = "none"; |
249 | | - document.getElementById("matches").style.display = "block"; |
250 | | - |
251 | | - if (reverse){ |
252 | | - // make a smooth movement to the clicked position |
253 | | - map.panTo(clickMarker.getPosition()); |
254 | | - google.maps.event.addListenerOnce(map, 'idle', function(){ |
255 | | - selectMarker(0); |
256 | | - }); |
257 | | - } |
258 | | - else { |
259 | | - zoomToViewports(results); |
260 | | - selectMarker(0); |
261 | | - } |
262 | | - } |
263 | | - |
264 | | - function getMarkerImageUrl(resultNum) { |
265 | | - return MAPFILES_URL + "marker" + String.fromCharCode(65 + resultNum) + ".png"; |
266 | | - } |
267 | | - |
268 | | - function addLocationRow( lat, lon ) { |
269 | | - var addRow = $( '#' + mapDivId + '_addrow' ); |
270 | | - |
271 | | - addRow.remove(); |
272 | | - appendTableRow( rowNr, lat, lon ); // TODO |
273 | | - table.append( addRow ); |
274 | | - $( '#' + mapDivId + '_addfield' ).attr( 'value', '' ); |
275 | | - $( "#" + mapDivId + '_addbutton' ).button().click( onAddButtonClick ); |
276 | | - rowNr++; |
277 | | - |
278 | | - updateInput(); |
279 | | - } |
280 | | - |
281 | | - function onRemoveButtonClick() { |
282 | | - $( '#' + mapDivId + '_row_' + $( this ).attr( 'rowid' ) ).remove(); |
283 | | - updateInput(); |
284 | | - return false; |
285 | | - } |
286 | | - |
287 | | - function appendTableRow( i, lat, lon ) { |
288 | | - table.append( |
289 | | - '<tr id="' + mapDivId + '_row_' + i + '"><td>' + |
290 | | - semanticMaps.locationToDMS( lat, lon ) + |
291 | | - '</td><td>' + |
292 | | - '<button class="forminput-remove" rowid="' + i + '" id="' + mapDivId + '_addbutton_' + i + '">' + |
293 | | - mediaWiki.msg( 'semanticmaps-forminput-remove' ) + |
294 | | - '</button>' + |
295 | | - '</td></tr>' |
296 | | - ); |
297 | | - |
298 | | - $( "#" + mapDivId + '_addbutton_' + i ).button().click( onRemoveButtonClick ); |
299 | | - } |
300 | | - |
301 | | - |
302 | | - |
303 | | - function updateInput() { |
304 | | - var locations = []; |
305 | | - |
306 | | - //$( '' ).each(); |
307 | | - |
308 | | - updateInputValue( semanticMaps.buildInputValue( locations ) ); |
309 | | - } |
310 | | - |
311 | | - function updateInputValue( value ) { |
312 | | - $( '#' + mapDivId + '_values' ).text( value ); |
313 | | - } |
314 | | - |
315 | 17 | return this; |
316 | 18 | |
317 | 19 | }; })( jQuery ); |
\ No newline at end of file |
Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/SM_GoogleMaps3FormInput.php |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | /** |
5 | 5 | * Google Maps v3 form input class. |
6 | 6 | * |
| 7 | + * @since 0.8 |
7 | 8 | * @file SM_GoogleMaps3FormInput.php |
8 | 9 | * @ingroup SemanticMaps |
9 | 10 | * |
— | — | @@ -19,7 +20,7 @@ |
20 | 21 | * @return array of string |
21 | 22 | */ |
22 | 23 | protected function getResourceModules() { |
23 | | - return array_merge( parent::getResourceModules(), array( 'ext.sm.fi.googlemaps3' ) ); |
| 24 | + return array_merge( parent::getResourceModules(), array( 'ext.sm.fi.googlemaps3.single' ) ); |
24 | 25 | } |
25 | 26 | |
26 | 27 | } |
Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.gmapsmultiinput.js |
— | — | @@ -1,3 +1,316 @@ |
2 | 2 | /** |
| 3 | + * JavasSript for the Google Maps v3 form input of the Semantic Maps extension. |
| 4 | + * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps |
3 | 5 | * |
4 | | - */ |
\ No newline at end of file |
| 6 | + * @since 0.8 |
| 7 | + * @ingroup SemanticMaps |
| 8 | + * |
| 9 | + * @licence GNU GPL v3 |
| 10 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 11 | + */ |
| 12 | + |
| 13 | +(function( $ ){ $.fn.gmapsmultiinput = function( mapDivId, options ) { |
| 14 | + var MAPFILES_URL = "http://maps.gstatic.com/intl/en_us/mapfiles/"; |
| 15 | + |
| 16 | + var clickIcon = new google.maps.MarkerImage( |
| 17 | + MAPFILES_URL + 'dd-start.png', |
| 18 | + new google.maps.Size(20, 34), |
| 19 | + new google.maps.Point(0, 0), |
| 20 | + new google.maps.Point(10, 34) |
| 21 | + ); |
| 22 | + |
| 23 | + var clickMarker = null; |
| 24 | + |
| 25 | + var geocoder = new google.maps.Geocoder(); |
| 26 | + |
| 27 | + this.attr( { 'class': "ui-widget" } ).css( { 'width': 'auto' } ); |
| 28 | + |
| 29 | + this.html( |
| 30 | + $( '<div />' ).css( { |
| 31 | + 'display': 'none' |
| 32 | + } ).append( $( '<input />' ).attr( { 'type': 'text', 'name': options.inputname, 'id': mapDivId + '_values' } ) ) |
| 33 | + ); |
| 34 | + |
| 35 | + updateInputValue( semanticMaps.buildInputValue( options.locations ) ); |
| 36 | + |
| 37 | + var table = $( '<table />' ).attr( { 'class' : 'mapinput ui-widget ui-widget-content' } ); |
| 38 | + this.append( table ); |
| 39 | + |
| 40 | + var mapDiv = $( '<div />' ) |
| 41 | + .attr( { |
| 42 | + 'id': mapDivId, |
| 43 | + 'class': 'ui-widget ui-widget-content' |
| 44 | + } ) |
| 45 | + .css( { |
| 46 | + 'width': options.width, |
| 47 | + 'height': options.height |
| 48 | + } ) |
| 49 | + .googlemaps( options ); |
| 50 | + |
| 51 | + google.maps.event.addListener( mapDiv.map, 'click', onClickCallback ); |
| 52 | + |
| 53 | + function onClickCallback() { |
| 54 | + // TODO |
| 55 | + } |
| 56 | + |
| 57 | + table.append( |
| 58 | + '<thead><tr class="ui-widget-header "><th colspan="2">' + mediaWiki.msg( 'semanticmaps-forminput-locations' ) + '</th></tr></thead><tbody>' |
| 59 | + ); |
| 60 | + |
| 61 | + var rowNr = options.locations.length; |
| 62 | + |
| 63 | + for ( i in options.locations ) { |
| 64 | + appendTableRow( i, options.locations[i].lat, options.locations[i].lon ); |
| 65 | + } |
| 66 | + |
| 67 | + table.append( |
| 68 | + '<tr id="' + mapDivId + '_addrow"><td width="300px">' + |
| 69 | + '<input type="text" class="text ui-widget-content ui-corner-all" width="95%" id="' + mapDivId + '_addfield" />' + |
| 70 | + '</td><td>' + |
| 71 | + '<button id="' + mapDivId + '_addbutton" mapid="' + mapDivId + '">' + mediaWiki.msg( 'semanticmaps-forminput-add' ) + '</button>' + |
| 72 | + '</td></tr></tbody>' |
| 73 | + ); |
| 74 | + |
| 75 | + $( "#" + mapDivId + '_addbutton' ).button().click( onAddButtonClick ); |
| 76 | + |
| 77 | + function onAddButtonClick() { |
| 78 | + var location = $( '#' + mapDivId + '_addfield' ).attr( 'value' ); |
| 79 | + submitGeocodeQuery( location ); |
| 80 | + return false; |
| 81 | + } |
| 82 | + |
| 83 | + function submitGeocodeQuery( query ) { |
| 84 | + if ( /\s*^\-?\d+(\.\d+)?\s*\,\s*\-?\d+(\.\d+)?\s*$/.test( query ) ) { |
| 85 | + var latlng = parseLatLng(query); |
| 86 | + |
| 87 | + if (latlng == null) { |
| 88 | + $( '#' + mapDivId + '_addfield' ).attr( 'value', '' ); |
| 89 | + } else { |
| 90 | + geocode({ 'latLng': latlng }); |
| 91 | + } |
| 92 | + } else { |
| 93 | + geocode({ 'address': query }); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + function parseLatLng(value) { |
| 98 | + value.replace('/\s//g'); |
| 99 | + var coords = value.split(','); |
| 100 | + var lat = parseFloat(coords[0]); |
| 101 | + var lng = parseFloat(coords[1]); |
| 102 | + if (isNaN(lat) || isNaN(lng)) { |
| 103 | + return null; |
| 104 | + } else { |
| 105 | + return new google.maps.LatLng(lat, lng); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + function geocode(request) { |
| 110 | + var hash = ''; |
| 111 | + |
| 112 | + if (request.latLng) { |
| 113 | + clickMarker = new google.maps.Marker({ |
| 114 | + 'position': request.latLng, |
| 115 | + 'map': map, |
| 116 | + 'title': request.latLng.toString(), |
| 117 | + 'clickable': false, |
| 118 | + 'icon': clickIcon, |
| 119 | + 'shadow': shadow |
| 120 | + }); |
| 121 | + hash = 'q=' + request.latLng.toUrlValue(6); |
| 122 | + } else { |
| 123 | + hash = 'q=' + request.address; |
| 124 | + } |
| 125 | + |
| 126 | + var vpbias = false; |
| 127 | + var country = ''; |
| 128 | + var language = ''; |
| 129 | + |
| 130 | + if (vpbias) { |
| 131 | + hash += '&vpcenter=' + map.getCenter().toUrlValue(6); |
| 132 | + hash += '&vpzoom=' + map.getZoom(); |
| 133 | + request.bounds = map.getBounds(); |
| 134 | + } |
| 135 | + |
| 136 | + if (country) { |
| 137 | + hash += '&country=' + country; |
| 138 | + request.country = country; |
| 139 | + } |
| 140 | + |
| 141 | + if (language) { |
| 142 | + hash += '&language=' + language; |
| 143 | + request.language = language; |
| 144 | + } |
| 145 | + |
| 146 | + hashFragment = '#' + escape(hash); |
| 147 | + window.location.hash = escape(hash); |
| 148 | + geocoder.geocode(request, showResults); |
| 149 | + } |
| 150 | + |
| 151 | + function showResults(results, status) { |
| 152 | + var reverse = (clickMarker != null); // TODO |
| 153 | + |
| 154 | + if (! results) { |
| 155 | + // TODO |
| 156 | + alert("Geocoder did not return a valid response"); |
| 157 | + } else { |
| 158 | + //document.getElementById("statusValue").innerHTML = status; |
| 159 | + |
| 160 | + if (status == google.maps.GeocoderStatus.OK) { |
| 161 | + //document.getElementById("matchCount").innerHTML = results.length; |
| 162 | + var marker = new google.maps.Marker( { |
| 163 | + map: mapDiv.map, |
| 164 | + position: results[0].geometry.location, |
| 165 | + title: results[0].geometry.location.toString() |
| 166 | + } ); |
| 167 | + addLocationRow( results[0].geometry.location.lat(), results[0].geometry.location.lng() ); |
| 168 | + //plotMatchesOnMap(results, reverse); |
| 169 | + } else { |
| 170 | + if ( !reverse) { |
| 171 | + mapDiv.map.setCenter(new google.maps.LatLng(0.0, 0.0)); |
| 172 | + mapDiv.map.setZoom(1); // TODO |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + function plotMatchesOnMap(results, reverse) { |
| 179 | + markers = new Array(results.length); |
| 180 | + var resultsListHtml = ""; |
| 181 | + |
| 182 | + var openInfoWindow = function(resultNum, result, marker) { |
| 183 | + return function() { |
| 184 | + if (selected != null) { |
| 185 | + document.getElementById('p' + selected).style.backgroundColor = "white"; |
| 186 | + clearBoundsOverlays(); |
| 187 | + } |
| 188 | + |
| 189 | + map.fitBounds(result.geometry.viewport); |
| 190 | + infowindow.setContent(getAddressComponentsHtml(result.address_components)); |
| 191 | + infowindow.open(map, marker); |
| 192 | + |
| 193 | + if (result.geometry.bounds) { |
| 194 | + boundsOverlay = new google.maps.Rectangle({ |
| 195 | + 'bounds': result.geometry.bounds, |
| 196 | + 'strokeColor': '#ff0000', |
| 197 | + 'strokeOpacity': 1.0, |
| 198 | + 'strokeWeight': 2.0, |
| 199 | + 'fillOpacity': 0.0 |
| 200 | + }); |
| 201 | + boundsOverlay.setMap(map); |
| 202 | + google.maps.event.addListener(boundsOverlay, 'click', onClickCallback); |
| 203 | + document.getElementById('boundsLegend').style.display = 'block'; |
| 204 | + } else { |
| 205 | + boundsOverlay = null; |
| 206 | + } |
| 207 | + |
| 208 | + viewportOverlay = new google.maps.Rectangle({ |
| 209 | + 'bounds': result.geometry.viewport, |
| 210 | + 'strokeColor': '#0000ff', |
| 211 | + 'strokeOpacity': 1.0, |
| 212 | + 'strokeWeight': 2.0, |
| 213 | + 'fillOpacity': 0.0 |
| 214 | + }); |
| 215 | + viewportOverlay.setMap(map); |
| 216 | + google.maps.event.addListener(viewportOverlay, 'click', onClickCallback); |
| 217 | + document.getElementById('viewportLegend').style.display = 'block'; |
| 218 | + |
| 219 | + document.getElementById('p' + resultNum).style.backgroundColor = "#eeeeff"; |
| 220 | + document.getElementById('matches').scrollTop = |
| 221 | + document.getElementById('p' + resultNum).offsetTop - |
| 222 | + document.getElementById('matches').offsetTop; |
| 223 | + selected = resultNum; |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + for (var i = 0; i < results.length; i++) { |
| 228 | + var icon = new google.maps.MarkerImage( |
| 229 | + getMarkerImageUrl(i), |
| 230 | + new google.maps.Size(20, 34), |
| 231 | + new google.maps.Point(0, 0), |
| 232 | + new google.maps.Point(10, 34) |
| 233 | + ); |
| 234 | + |
| 235 | + markers[i] = new google.maps.Marker({ |
| 236 | + 'position': results[i].geometry.location, |
| 237 | + 'map': map, |
| 238 | + 'icon': icon, |
| 239 | + 'shadow': shadow |
| 240 | + }); |
| 241 | + |
| 242 | + google.maps.event.addListener(markers[i], 'click', openInfoWindow(i, results[i], markers[i])); |
| 243 | + |
| 244 | + resultsListHtml += getResultsListItem(i, getResultDescription(results[i])); |
| 245 | + } |
| 246 | + |
| 247 | + document.getElementById("matches").innerHTML = resultsListHtml; |
| 248 | + document.getElementById("p0").style.border = "none"; |
| 249 | + document.getElementById("matches").style.display = "block"; |
| 250 | + |
| 251 | + if (reverse){ |
| 252 | + // make a smooth movement to the clicked position |
| 253 | + map.panTo(clickMarker.getPosition()); |
| 254 | + google.maps.event.addListenerOnce(map, 'idle', function(){ |
| 255 | + selectMarker(0); |
| 256 | + }); |
| 257 | + } |
| 258 | + else { |
| 259 | + zoomToViewports(results); |
| 260 | + selectMarker(0); |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + function getMarkerImageUrl(resultNum) { |
| 265 | + return MAPFILES_URL + "marker" + String.fromCharCode(65 + resultNum) + ".png"; |
| 266 | + } |
| 267 | + |
| 268 | + function addLocationRow( lat, lon ) { |
| 269 | + var addRow = $( '#' + mapDivId + '_addrow' ); |
| 270 | + |
| 271 | + addRow.remove(); |
| 272 | + appendTableRow( rowNr, lat, lon ); // TODO |
| 273 | + table.append( addRow ); |
| 274 | + $( '#' + mapDivId + '_addfield' ).attr( 'value', '' ); |
| 275 | + $( "#" + mapDivId + '_addbutton' ).button().click( onAddButtonClick ); |
| 276 | + rowNr++; |
| 277 | + |
| 278 | + updateInput(); |
| 279 | + } |
| 280 | + |
| 281 | + function onRemoveButtonClick() { |
| 282 | + $( '#' + mapDivId + '_row_' + $( this ).attr( 'rowid' ) ).remove(); |
| 283 | + updateInput(); |
| 284 | + return false; |
| 285 | + } |
| 286 | + |
| 287 | + function appendTableRow( i, lat, lon ) { |
| 288 | + table.append( |
| 289 | + '<tr id="' + mapDivId + '_row_' + i + '"><td>' + |
| 290 | + coord.dms( lat, lon ) + |
| 291 | + '</td><td>' + |
| 292 | + '<button class="forminput-remove" rowid="' + i + '" id="' + mapDivId + '_addbutton_' + i + '">' + |
| 293 | + mediaWiki.msg( 'semanticmaps-forminput-remove' ) + |
| 294 | + '</button>' + |
| 295 | + '</td></tr>' |
| 296 | + ); |
| 297 | + |
| 298 | + $( "#" + mapDivId + '_addbutton_' + i ).button().click( onRemoveButtonClick ); |
| 299 | + } |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | + function updateInput() { |
| 304 | + var locations = []; |
| 305 | + |
| 306 | + //$( '' ).each(); |
| 307 | + |
| 308 | + updateInputValue( semanticMaps.buildInputValue( locations ) ); |
| 309 | + } |
| 310 | + |
| 311 | + function updateInputValue( value ) { |
| 312 | + $( '#' + mapDivId + '_values' ).text( value ); |
| 313 | + } |
| 314 | + |
| 315 | + return this; |
| 316 | + |
| 317 | +}; })( jQuery ); |
\ No newline at end of file |