Only initialize the various elements if they are in the dom.
This commit is contained in:
parent
d64f78dc5e
commit
509a4f501b
1 changed files with 55 additions and 48 deletions
|
@ -9,57 +9,64 @@ function addGeoCoordinates(ev) {
|
||||||
}
|
}
|
||||||
var map = null;
|
var map = null;
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('.icon.link').popup();
|
if ($('.icon.link').length > 0) {
|
||||||
jQuery('input[type=datetime]').datetimepicker({lang: 'de', format: 'Y-m-d H:i'});
|
$('.icon.link').popup();
|
||||||
|
|
||||||
$('.add_geo').click(addGeoCoordinates);
|
|
||||||
map = L.map('map');
|
|
||||||
|
|
||||||
// add an OpenStreetMap tile layer
|
|
||||||
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
|
||||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
||||||
}).addTo(map);
|
|
||||||
|
|
||||||
map.setView([51.505, -0.09], 0);
|
|
||||||
|
|
||||||
L.Icon.Default.imagePath = '/css/images';
|
|
||||||
var popup = L.popup();
|
|
||||||
|
|
||||||
var marker = L.marker();
|
|
||||||
|
|
||||||
function onMapClick(e) {
|
|
||||||
marker
|
|
||||||
.setLatLng(e.latlng)
|
|
||||||
//.setContent("You clicked the map at " + e.latlng.toString())
|
|
||||||
.addTo(map);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map.on('click', onMapClick);
|
if (jQuery('input[type=datetime]').length > 0) {
|
||||||
|
jQuery('input[type=datetime]').datetimepicker({lang: 'de', format: 'Y-m-d H:i'});
|
||||||
|
}
|
||||||
|
|
||||||
$('.geo.chooser').modal('setting', {
|
if (jQuery('#map').length == 1) {
|
||||||
closable: false,
|
$('.add_geo').click(addGeoCoordinates);
|
||||||
onApprove: function () {
|
map = L.map('map');
|
||||||
var coords = marker.getLatLng();
|
|
||||||
$('input[name=location_lat]').val(coords.lat);
|
|
||||||
$('input[name=location_lon]').val(coords.lng);
|
|
||||||
$('input[name=location]').css('margin-bottom', '3.2rem');
|
|
||||||
$('span.coords').text('Folgende Koordinaten sind angegeben: lat:' + coords.lat + ', lon:' + coords.lng);
|
|
||||||
},
|
|
||||||
onDeny: function () {
|
|
||||||
|
|
||||||
},
|
// add an OpenStreetMap tile layer
|
||||||
onVisible: function () {
|
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
||||||
map.invalidateSize(true);
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||||
var lat = parseFloat($('input[name=location_lat]').val());
|
}).addTo(map);
|
||||||
var lon = parseFloat($('input[name=location_lon]').val());
|
|
||||||
if ((lat > 0) && (lon > 0)) {
|
map.setView([51.505, -0.09], 0);
|
||||||
map.setView([lat,lon],16);
|
|
||||||
var latlng = new L.LatLng(lat,lon);
|
L.Icon.Default.imagePath = '/css/images';
|
||||||
marker.setLatLng(latlng);
|
var popup = L.popup();
|
||||||
marker.addTo(map);
|
|
||||||
} else {
|
var marker = L.marker();
|
||||||
map.locate({setView: true});
|
|
||||||
}
|
function onMapClick(e) {
|
||||||
|
marker
|
||||||
|
.setLatLng(e.latlng)
|
||||||
|
//.setContent("You clicked the map at " + e.latlng.toString())
|
||||||
|
.addTo(map);
|
||||||
}
|
}
|
||||||
}).modal('attach events', '.add_geo', 'show');
|
|
||||||
|
map.on('click', onMapClick);
|
||||||
|
|
||||||
|
$('.geo.chooser').modal('setting', {
|
||||||
|
closable: false,
|
||||||
|
onApprove: function () {
|
||||||
|
var coords = marker.getLatLng();
|
||||||
|
$('input[name=location_lat]').val(coords.lat);
|
||||||
|
$('input[name=location_lon]').val(coords.lng);
|
||||||
|
$('input[name=location]').css('margin-bottom', '3.2rem');
|
||||||
|
$('span.coords').text('Folgende Koordinaten sind angegeben: lat:' + coords.lat + ', lon:' + coords.lng);
|
||||||
|
},
|
||||||
|
onDeny: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
onVisible: function () {
|
||||||
|
map.invalidateSize(true);
|
||||||
|
var lat = parseFloat($('input[name=location_lat]').val());
|
||||||
|
var lon = parseFloat($('input[name=location_lon]').val());
|
||||||
|
if ((lat > 0) && (lon > 0)) {
|
||||||
|
map.setView([lat, lon], 16);
|
||||||
|
var latlng = new L.LatLng(lat, lon);
|
||||||
|
marker.setLatLng(latlng);
|
||||||
|
marker.addTo(map);
|
||||||
|
} else {
|
||||||
|
map.locate({setView: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).modal('attach events', '.add_geo', 'show');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue