Index: branches/SemanticMaps0.8/includes/services/GoogleMaps3/jquery.googlemapsinput.js |
— | — | @@ -12,17 +12,49 @@ |
13 | 13 | (function( $ ){ $.fn.googlemapsinput = function( mapDivId, options ) { |
14 | 14 | |
15 | 15 | var self = this; |
| 16 | + var geocoder = false; |
16 | 17 | |
| 18 | + /** |
| 19 | + * Creates and places a new marker on the map at the provided |
| 20 | + * coordinate set and the pans to it. |
| 21 | + * @param {Object} coordinate |
| 22 | + */ |
17 | 23 | this.showCoordinate = function( coordinate ) { |
18 | 24 | this.mapDiv.removeMarkers(); |
19 | 25 | coordinate.icon = ''; |
20 | 26 | coordinate.title = ''; |
21 | 27 | coordinate.text = coord.dms( coordinate.lat, coordinate.lon ); |
22 | | - this.mapDiv.addMarker( coordinate ); |
| 28 | + var marker = this.mapDiv.addMarker( coordinate ); |
| 29 | + this.mapDiv.map.panTo( marker.getPosition() ); |
23 | 30 | }; |
24 | 31 | |
| 32 | + /** |
| 33 | + * Calls this.showCoordinate with the provided latLng and updates the input field. |
| 34 | + * @param {google.maps.LatLng} latLng |
| 35 | + */ |
| 36 | + this.showLatLng = function( latLng ) { |
| 37 | + var location = { lat: latLng.lat(), lon: latLng.lng() }; |
| 38 | + this.showCoordinate( location ); |
| 39 | + this.updateInput( [ location ] ); |
| 40 | + } |
| 41 | + |
| 42 | + this.setupGeocoder = function() { |
| 43 | + if ( geocoder === false ) { |
| 44 | + geocoder = new google.maps.Geocoder(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
25 | 48 | this.geocodeAddress = function( address ) { |
26 | | - |
| 49 | + this.setupGeocoder(); |
| 50 | + geocoder.geocode( { 'address': address }, function( results, status ) { |
| 51 | + if ( status == google.maps.GeocoderStatus.OK ) { |
| 52 | + self.showLatLng( results[0].geometry.location ); |
| 53 | + } |
| 54 | + else { |
| 55 | + // TODO: i18n |
| 56 | + alert( "Geocode was not successful for the following reason: " + status ); |
| 57 | + } |
| 58 | + } ); |
27 | 59 | }; |
28 | 60 | |
29 | 61 | this.mapforminput( mapDivId, options, { canGeocode: true } ); |
— | — | @@ -30,10 +62,7 @@ |
31 | 63 | this.mapDiv.googlemaps( options ); |
32 | 64 | |
33 | 65 | google.maps.event.addListener( this.mapDiv.map, 'click', function( event ) { |
34 | | - var location = { lat: event.latLng.lat(), lon: event.latLng.lng() }; |
35 | | - self.mapDiv.map.panTo( event.latLng ); |
36 | | - self.showCoordinate( location ); |
37 | | - self.input.attr( 'value', semanticMaps.buildInputValue( [ location ] ) ); |
| 66 | + self.showLatLng( event.latLng ); |
38 | 67 | } ); |
39 | 68 | |
40 | 69 | return this; |
Index: branches/SemanticMaps0.8/includes/forminputs/ext.sm.forminputs.js |
— | — | @@ -1,24 +0,0 @@ |
2 | | -/** |
3 | | - * JavasSript for the Semantic Maps extension. |
4 | | - * @see http://www.mediawiki.org/wiki/Extension:Semantic_Maps |
5 | | - * |
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 | | -window.semanticMaps = new ( function( $ ) { |
14 | | - |
15 | | - this.buildInputValue = function( locations ) { |
16 | | - var floats = []; |
17 | | - |
18 | | - for ( i in locations ) { |
19 | | - floats.push( coord.float( locations[i].lat, locations[i].lon ) ); |
20 | | - } |
21 | | - |
22 | | - return floats.join( '; ' ); |
23 | | - }; |
24 | | - |
25 | | -} )( jQuery ); |
Index: branches/SemanticMaps0.8/includes/forminputs/jquery.mapforminput.js |
— | — | @@ -23,11 +23,34 @@ |
24 | 24 | |
25 | 25 | var self = this; |
26 | 26 | |
| 27 | + /** |
| 28 | + * Creates a string with the provided coordinates to populate the main input field with. |
| 29 | + * @param {Array} locations |
| 30 | + * @return {string} |
| 31 | + */ |
| 32 | + this.buildInputValue = function( locations ) { |
| 33 | + var floats = []; |
| 34 | + |
| 35 | + for ( i in locations ) { |
| 36 | + floats.push( coord.float( locations[i].lat, locations[i].lon ) ); |
| 37 | + } |
| 38 | + |
| 39 | + return floats.join( '; ' ); |
| 40 | + }; |
| 41 | + |
| 42 | + /** |
| 43 | + * Populate the main input field with the provided coordinates. |
| 44 | + * @param {Array} locations |
| 45 | + */ |
| 46 | + this.updateInput = function( locations ) { |
| 47 | + this.input.attr( 'value', this.buildInputValue( locations ) ); |
| 48 | + } |
| 49 | + |
27 | 50 | this.input = $( '<input />' ).attr( { |
28 | 51 | 'type': 'text', |
29 | 52 | 'name': options.inputname, |
30 | 53 | 'id': mapDivId + '_values', |
31 | | - 'value': semanticMaps.buildInputValue( options.locations ), |
| 54 | + 'value': this.buildInputValue( options.locations ), |
32 | 55 | 'size': options.fieldsize |
33 | 56 | } ); |
34 | 57 | |
Index: branches/SemanticMaps0.8/includes/forminputs/SM_FormInputs.php |
— | — | @@ -19,8 +19,7 @@ |
20 | 20 | 'remoteBasePath' => $smgScriptPath . '/includes/forminputs', |
21 | 21 | 'group' => 'ext.semanticmaps', |
22 | 22 | 'scripts' => array( |
23 | | - 'jquery.mapforminput.js', |
24 | | - 'ext.sm.forminputs.js', |
| 23 | + 'jquery.mapforminput.js' |
25 | 24 | ), |
26 | 25 | 'messages' => array( |
27 | 26 | ) |