We discussed this in the Talk page here: https://www.mediawiki.org/wiki/Extension_talk:Page_Forms#Use_textinput_.22Address.22_field_as_input_for_googlemaps_.22look_up_coordinates.22_button
This proposed change has two effects:
- It allows other inputs to be used for geocoding by the googlemaps input instead of its own "enter address here" box. This has the potential benefits of (a) avoiding having to enter an address twice, and/or (b) saving, in Cargo, the address used for geocoding.
To achieve this, select a name for a googlemaps input, set the id of that googlemaps input as that name, and the class of the other associated inputs as that name, e.g. {{{field|Coordinates|input type=googlemaps|id=mapone}}} and {{{field|Location|input type=text|class=mapone}}}
- If a googlemaps input has no 'id' set it operates the way it used to
- Multiple googlemaps inputs can appear on a form.
- Multiple inputs can be associated with each googlemap input. Their values are concatenated, separated by commas, for geocoding.
- Each input can be associated with more than one googlemaps input, e.g. {{{field|Location|input type=text|class=mapone maptwo}}}
- Tested for text and textarea fields, but should work with any form field with a value.
- It adds an ability to hide the "set marker" button, for when form users will not be expected to type coordinates as figures. Achieved by a "hidesetmarkerbutton" parameter, e.g. {{{field|Coordinates|input type=googlemaps|id=mapone|hidesetmarkerbutton}}}
index b190088..d67d94f 100644 --- a/includes/forminputs/PF_GoogleMapsInput.php +++ b/includes/forminputs/PF_GoogleMapsInput.php @@ -55,19 +55,24 @@ class PFGoogleMapsInput extends PFOpenLayersInput { $width = self::getWidth( $other_args ); $mapCanvas = Html::element( 'div', array( 'class' => 'pfMapCanvas', 'style' => "height: $height; width: $width;" ), 'Map goes here...' ); - $fullInputHTML = <<<END -<div style="padding-bottom: 10px;"> -$coordsInput -$mapUpdateButton -</div> -<div style="padding-bottom: 10px;"> -$addressLookupInput -$addressLookupButton -</div> -$mapCanvas + $fullInputHTML = '<div style="padding-bottom: 10px;">'; + if ( !array_key_exists( 'id', $other_args ) ) { + $fullInputHTML .= $addressLookupInput; + } + $fullInputHTML .= $addressLookupButton; + $fullInputHTML .= '</div><div style="padding-bottom: 10px;">'; + $fullInputHTML .= $coordsInput; + if ( !array_key_exists( 'hidesetmarkerbutton', $other_args ) ) { + $fullInputHTML .= $mapUpdateButton; + } + $fullInputHTML .= '</div>'; + $fullInputHTML .= $mapCanvas; -END; - $text = Html::rawElement( 'div', array( 'class' => 'pfGoogleMapsInput' ), $fullInputHTML ); + $divAttrs = array ('class' => 'pfGoogleMapsInput'); + if ( array_key_exists( 'id', $other_args ) ) { + $divAttrs['id'] = $other_args['id']; + } + $text = Html::rawElement( 'div', $divAttrs, $fullInputHTML ); return $text; } diff --git a/libs/PF_maps.js b/libs/PF_maps.js index 1a918e1..fc0f2a0 100644 --- a/libs/PF_maps.js +++ b/libs/PF_maps.js @@ -75,7 +75,21 @@ function setupMapFormInput( inputDiv, mapService ) { } function doLookup() { - var addressText = inputDiv.find('.pfAddressInput').val(); + var currentMapId = inputDiv.attr('id'); + if (document.getElementsByClassName(currentMapId).length!=0) { + var addressText = ''; + var allAddrs = document.getElementsByClassName(currentMapId); + for (var i=0; i<allAddrs.length; i++) { + if (addressText!="") { + addressText += ", "; + } + addressText += allAddrs[i].value; + } + } else { + var addressText = inputDiv.find('.pfAddressInput').val(); + } + alert("Looking up coordinates for: " + addressText); //Remove when happy it works + if ( mapService == "Google Maps" ) { geocoder.geocode( { 'address': addressText }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) {