prepares refactorisation for geocoding
This commit is contained in:
parent
9293ee4ec9
commit
56d0654fdc
2 changed files with 118 additions and 113 deletions
|
|
@ -27,24 +27,34 @@
|
|||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
var config = {
|
||||
mapId: 'map',
|
||||
addrId: 'Location_Address',
|
||||
longId: 'Location_Longitude',
|
||||
latId: 'Location_Latitude',
|
||||
addrValidationId: 'valloc',
|
||||
formValidId: 'valsum',
|
||||
locComboId: 'loccomb'
|
||||
};
|
||||
|
||||
$.validator.setDefaults({
|
||||
messages: {
|
||||
remote: "Ce lieu n'est pas identifié par les services de géo-localisation Google",
|
||||
required: "Veuillez renseigner ce champ"
|
||||
}
|
||||
});
|
||||
var gmap = new google.maps.Map(document.getElementById('map'), {
|
||||
var gmap = new google.maps.Map(document.getElementById(config.mapId), {
|
||||
zoom: 16,
|
||||
center: { lat: 48.862854, lng: 2.2056466 }
|
||||
});
|
||||
var marker;
|
||||
function chooseLoc(loc) {
|
||||
$('#Location_Address').val(loc.formatted_address);
|
||||
function chooseLoc(sender,loc) {
|
||||
if (sender === 'user') $('#'+config.addrId).val(loc.formatted_address);
|
||||
var pos = loc.geometry.location;
|
||||
var lat = new Number(pos.lat);
|
||||
var lng = new Number(pos.lng);
|
||||
$('#Location_Latitude').val(lat.toLocaleString('en'));
|
||||
$('#Location_Longitude').val(lng.toLocaleString('en'));
|
||||
$('#'+config.latId).val(lat.toLocaleString('en'));
|
||||
$('#'+config.longId).val(lng.toLocaleString('en'));
|
||||
gmap.setCenter(pos);
|
||||
if (marker) {
|
||||
marker.setMap(null);
|
||||
|
|
@ -58,41 +68,43 @@ $(document).ready(function(){
|
|||
google.maps.event.addListener(marker, 'dragend', function() {
|
||||
// TODO reverse geo code
|
||||
var pos = marker.getPosition();
|
||||
$('#Location_Latitude').val(pos.lat);
|
||||
$('#Location_Longitude').val(pos.lng);
|
||||
$('#'+config.latId).val(pos.lat);
|
||||
$('#'+config.longId).val(pos.lng);
|
||||
});
|
||||
$('#Location_Address').valid();
|
||||
$('#'+config.addrId).valid();
|
||||
$('#'+config.addrValidationId).empty();
|
||||
$('#'+config.formValidId).empty();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$('#EventDate').datepicker({language:'fr'});
|
||||
|
||||
$('#Location_Address').rules("add",
|
||||
$('#'+config.addrId).rules("add",
|
||||
{
|
||||
remote: {
|
||||
url: 'http://maps.googleapis.com/maps/api/geocode/json',
|
||||
url: 'https://maps.googleapis.com/maps/api/geocode/json',
|
||||
type: 'get',
|
||||
data: {
|
||||
sensor: false,
|
||||
address: function () { return $('#Location_Address').val() }
|
||||
address: function () { return $('#'+config.addrId).val() }
|
||||
},
|
||||
dataType: 'json',
|
||||
dataFilter: function(datastr,type) {
|
||||
$('#Location_combo').html("");
|
||||
$('#'+config.locComboId).html("");
|
||||
var data = JSON.parse(datastr);
|
||||
data.results.forEach(function(element) {
|
||||
if (element.formatted_address !== $('#Location_Address').val()) {
|
||||
if (element.formatted_address !== $('#'+config.addrId).val()) {
|
||||
$('<li>'+element.formatted_address+'</li>')
|
||||
.data("geoloc",element)
|
||||
.click(function() { chooseLoc($(this).data("geoloc")) })
|
||||
.appendTo($('#Location_combo'));}
|
||||
.click(function() { chooseLoc('user',$(this).data("geoloc")) })
|
||||
.appendTo($('#'+config.locComboId));}
|
||||
else { }
|
||||
});
|
||||
if ((data.status === 'OK') && (data.results.length == 1))
|
||||
if ((data.status === 'OK') && (data.results.length == 1))
|
||||
{
|
||||
chooseLoc(data.results[0]);
|
||||
chooseLoc('google',data.results[0]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown)
|
||||
|
|
@ -110,9 +122,8 @@ $(document).ready(function(){
|
|||
<div class="form-horizontal">
|
||||
<h4>@SR["Fill in your book query"]</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
|
||||
<div asp-validation-summary="ValidationSummary.All" class="text-danger" id="valsum"></div>
|
||||
<div class="form-group" has-feedback>
|
||||
@Html.ValidationSummary()
|
||||
<fieldset>
|
||||
<legend><label for="EventDate" class="col-md-2 control-label" >
|
||||
@SR["Event date"]
|
||||
|
|
@ -154,8 +165,8 @@ $(document).ready(function(){
|
|||
<input asp-for="Location.Address" type="text" name="Location.Address" id="Location_Address"
|
||||
class="form-control" data-val-required=@SR["SpecifyPlace"]
|
||||
data-val-remote=@SR["GoogleDidntGeoLocalized"]>
|
||||
<span asp-validation-for="Location.Address" class="text-danger" ></span>
|
||||
<ul id="Location_combo" >
|
||||
<span asp-validation-for="Location.Address" class="text-danger" id="valloc" ></span>
|
||||
<ul id="loccomb" >
|
||||
</ul>
|
||||
<div id="map"></div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue