fixes GMaps usage & Command creation

This commit is contained in:
Paul Schneider 2019-09-01 01:31:55 +01:00
commit 4999284419
12 changed files with 192 additions and 269 deletions

View file

@ -24,14 +24,6 @@
<link rel="stylesheet" href="@Startup.SiteSetup.StyleSheet" asp-append-version="true"/>
<script>
$(document).ready(function() {
if (typeof(allowCircleToBlog) !== 'undefined') {
$('input.Blogcirle[type=checkbox]').on('change', allowCircleToBlog);
}
});
</script>
@RenderSection("header", required: false)
</head>
<body>

View file

@ -1,108 +1,2 @@
<script src="https://maps.googleapis.com/maps/api/js?key=@Yavsc.Startup.GoogleSettings.BrowserApiKey"></script>
<script>
$(document).ready(function(){
function setCoord(config, pos)
{
var culture = '@System.Globalization.CultureInfo.CurrentCulture.Name';
$('#'+config.latId).val(pos.lat.toLocaleString(culture, { minimumFractionDigits: 7 }));
$('#'+config.lonId).val(pos.lng.toLocaleString(culture, { minimumFractionDigits: 7 }));
}
var marker=null;
function chooseLoc(config, sender, loc) {
if (sender === 'user') $('#'+config.addrId).val(loc.formatted_address);
var pos = loc.geometry.location;
var mapid = '#'+config.addrId;
var gmap = config.gmap;
gmap.setCenter(pos);
setCoord(config, pos);
if (marker!=null) {
marker.position = pos;
}
else {
marker = new google.maps.Marker({
map: gmap,
draggable: true,
animation: google.maps.Animation.DROP,
position: pos
});
google.maps.event.addListener(marker, 'dragend', function() {
var pos = marker.getPosition();
setCoord(config, { lat: pos.lat(), lng: pos.lng() });
});
}
$('#'+config.addrId).valid();
return true;
}
function setupInputAddress (mapDiv)
{
var config = {
mapId: $(mapDiv).attr('id'),
addrId: $(mapDiv).data('addr'),
lonId: $(mapDiv).data('lon'),
latId: $(mapDiv).data('lat'),
locComboId: $(mapDiv).data('loccombo')
};
var scenter = { lat: parseFloat($('#'+config.latId).val().replace(',','.')), lng: parseFloat($('#'+config.lonId).val().replace(',','.')) } ;
var input = '#'+config.addrId;
$(input).data("val-required", '@SR["SpecifyPlace"]') ;
$(input).data("val-remote", '@SR[ "GoogleDidntGeoLocalized"]') ;
$(input).rules("add",
{
remote: {
url: 'https://maps.googleapis.com/maps/api/geocode/json',
type: 'get',
data: {
key: '@Startup.GoogleSettings.BrowserApiKey',
sensor: false,
address: function () { return $('#'+config.addrId).val() }
},
dataType: 'json',
dataFilter: function(datastr,type) {
$('#'+config.locComboId).html("");
var data = JSON.parse(datastr);
data.results.forEach(function(element) {
if (element.formatted_address !== $('#'+config.addrId).val()) {
$('<li style="pointer:cursor;">'+element.formatted_address+'</li>')
.data("geoloc",element)
.click(function() { chooseLoc(config, 'user', $(this).data("geoloc")) })
.appendTo($('#'+config.locComboId));}
});
if ((data.status === 'OK') && (data.results.length == 1))
{
chooseLoc(config, 'google', data.results[0]);
return true
}
return false
},
error: function(xhr, textStatus, errorThrown)
{
console.log('ajax loading error ... '+textStatus+' ... '+ errorThrown);
return false
}
}
});
var gmap = new google.maps.Map(document.getElementById(config.mapId), {
zoom: 8,
center: scenter
});
config.gmap = gmap;
marker = new google.maps.Marker({
map: gmap,
draggable: true,
animation: google.maps.Animation.DROP,
position: scenter
});
}
$("div.map").each(function(indexMap){
setupInputAddress(this)
});
});
</script>
<script src="~/js/google-geoloc.js" asp-append-version="true"></script>