Compare commits
No commits in common. "1a2f9908fac4917abdb54ef0c52dcf702a140ba2" and "657867309e110e842d36b960e7d6b8158eddccc9" have entirely different histories.
1a2f9908fa
...
657867309e
@ -1,4 +1,3 @@
|
||||
var editor_mode = 0;
|
||||
var mymap;
|
||||
var streetLabelsRenderer = new L.StreetLabels({
|
||||
collisionFlg: true,
|
||||
@ -120,7 +119,7 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
||||
permanent: true,
|
||||
direction: "center",
|
||||
className: "city-names"
|
||||
}).openTooltip().on('click', jump_to_marker);
|
||||
}).openTooltip();
|
||||
};
|
||||
pointToLayer = function(feature, latlng) {
|
||||
label = String(feature.properties.name)
|
||||
@ -174,62 +173,6 @@ load_geojson("Streets", "./geojson/streets.json", "street", "blue", 0);
|
||||
|
||||
L.control.scale().addTo(mymap);
|
||||
|
||||
function get_current_location_str() {
|
||||
var latlng = mymap.getCenter();
|
||||
return Math.round(latlng.lat) + "," + Math.round(latlng.lng) + "," + mymap.getZoom();
|
||||
}
|
||||
|
||||
/* Important: Do not use mymap.setView, use this function instead */
|
||||
function jump_to(latlng, zoom = -1) {
|
||||
if (zoom == -1)
|
||||
zoom = mymap.getZoom();
|
||||
document.location.hash = "#" + Math.round(latlng.lat) + "," + Math.round(latlng.lng) + "," + zoom;
|
||||
}
|
||||
|
||||
function jump_to_marker(e) {
|
||||
if (!editor_mode)
|
||||
jump_to(e.target.getLatLng());
|
||||
}
|
||||
|
||||
function prompt_location() {
|
||||
var str = prompt("Enter coordinates to jump to:\n\n" +
|
||||
"Format: x, y [, zoom]", get_current_location_str());
|
||||
if (str)
|
||||
document.location.hash = "#" + str;
|
||||
}
|
||||
|
||||
L.MyControl = L.Control.extend({
|
||||
options: {
|
||||
position: 'topleft',
|
||||
callback: null,
|
||||
kind: '',
|
||||
html: ''
|
||||
},
|
||||
onAdd: function (map) {
|
||||
var container = L.DomUtil.create('div', 'leaflet-control leaflet-bar'),
|
||||
link = L.DomUtil.create('a', '', container);
|
||||
|
||||
link.href = '#';
|
||||
link.title = this.options.title;
|
||||
link.innerHTML = this.options.html;
|
||||
L.DomEvent.on(link, 'click', L.DomEvent.stop)
|
||||
.on(link, 'click', function () {
|
||||
window.LAYER = this.options.callback.call();
|
||||
}, this);
|
||||
return container;
|
||||
}
|
||||
});
|
||||
|
||||
L.GotoControl = L.MyControl.extend({
|
||||
options: {
|
||||
position: 'topleft',
|
||||
callback: prompt_location,
|
||||
title: 'Jump to coordinates.',
|
||||
html: '⌖'
|
||||
}
|
||||
});
|
||||
mymap.addControl(new L.GotoControl());
|
||||
|
||||
var popup = L.popup();
|
||||
|
||||
L.AwesomeMarkers.Icon.prototype.options.prefix = 'fa';
|
||||
@ -243,23 +186,3 @@ function onMapClick(e) {
|
||||
}
|
||||
|
||||
mymap.on('click', onMapClick);
|
||||
|
||||
function update_hash_from_position(e) {
|
||||
document.location.hash = "#" + get_current_location_str();
|
||||
}
|
||||
mymap.on('zoomend', update_hash_from_position);
|
||||
mymap.on('dragend', update_hash_from_position);
|
||||
|
||||
function onHashChange(e) {
|
||||
if (document.location.hash == "#" + get_current_location_str())
|
||||
return; // We're already there
|
||||
coordstr = window.location.hash.slice(1).replace(/%20/g, "").split(",");
|
||||
if (coordstr.length < 2)
|
||||
coordstr.push(0); // Default y
|
||||
if (coordstr.length < 3)
|
||||
coordstr.push(mymap.getZoom()); // Default zoom
|
||||
var latlng = L.latLng(parseFloat(coordstr[0]), parseFloat(coordstr[1]));
|
||||
mymap.setView(latlng, parseInt(coordstr[2]));
|
||||
}
|
||||
window.addEventListener("hashchange", onHashChange, false);
|
||||
onHashChange(null);
|
||||
|
@ -1,7 +1,6 @@
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
editor_mode = urlParams.has('editor');
|
||||
if (editor_mode) {
|
||||
if (urlParams.has('editor')) {
|
||||
var draw_layer;
|
||||
var polyline;
|
||||
|
||||
@ -28,8 +27,6 @@ if (editor_mode) {
|
||||
}
|
||||
|
||||
function onDragEnd(e) {
|
||||
if (!polyline)
|
||||
return;
|
||||
var latlngs = polyline.getLatLngs();
|
||||
|
||||
for (var i = 0; i < latlngs.length; i++) {
|
||||
@ -63,23 +60,22 @@ if (editor_mode) {
|
||||
}
|
||||
}
|
||||
|
||||
function editor_onHashChange() {
|
||||
function onHashChange() {
|
||||
if (("#" + get_location_string()) != window.location.hash) {
|
||||
polyline.remove(mymap);
|
||||
onLoad(0);
|
||||
}
|
||||
}
|
||||
|
||||
window.removeEventListener("hashchange", onHashChange, false);
|
||||
window.addEventListener("hashchange", editor_onHashChange, false);
|
||||
window.addEventListener("hashchange", onHashChange, false);
|
||||
window.addEventListener("mouseup", onDragEnd, false); // Workaround as polyline.on(dragend, ) doesn't seem to work
|
||||
|
||||
// Configure map for better editing
|
||||
document.getElementById('mapid').classList.add("no-aa");
|
||||
mymap.setMaxZoom(14);
|
||||
mymap.off('click', onMapClick);
|
||||
mymap.off('zoomend', update_hash_from_position);
|
||||
mymap.off('dragend', update_hash_from_position);
|
||||
//mymap.setOpacity(0.7);
|
||||
|
||||
onLoad();
|
||||
|
||||
function get_location_string() {
|
||||
|
Loading…
Reference in New Issue
Block a user