2020-06-05 00:22:41 +02:00
|
|
|
'use strict';
|
|
|
|
|
2020-06-01 21:13:02 +02:00
|
|
|
(function () {
|
|
|
|
var MapEditor = {
|
2020-06-06 02:18:12 +02:00
|
|
|
metadata: {
|
|
|
|
name: null,
|
|
|
|
description: null
|
|
|
|
},
|
2020-06-01 21:13:02 +02:00
|
|
|
map: null,
|
|
|
|
panorama: null,
|
|
|
|
selectedMarker: null,
|
2020-06-05 00:22:41 +02:00
|
|
|
added: {},
|
|
|
|
edited: {},
|
|
|
|
deleted: {},
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
editMetadata: function () {
|
|
|
|
var form = document.getElementById('metadataForm');
|
|
|
|
|
|
|
|
MapEditor.metadata.name = form.elements.name.value;
|
|
|
|
MapEditor.metadata.description = form.elements.description.value;
|
|
|
|
|
|
|
|
document.getElementById('mapName').innerHTML = form.elements.name.value ? form.elements.name.value : '[unnamed map]';
|
|
|
|
|
2020-06-14 02:31:09 +02:00
|
|
|
MapGuesser.hideModal();
|
2020-06-06 02:18:12 +02:00
|
|
|
|
|
|
|
document.getElementById('saveButton').disabled = false;
|
|
|
|
},
|
|
|
|
|
2020-06-03 23:41:08 +02:00
|
|
|
getPlace: function (placeId, marker) {
|
2020-06-13 22:39:44 +02:00
|
|
|
MapGuesser.httpRequest('GET', '/admin/place.json/' + placeId, function () {
|
2020-06-02 21:44:01 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
|
|
|
|
if (!this.response.panoId) {
|
|
|
|
document.getElementById('noPano').style.visibility = 'visible';
|
2020-06-03 23:41:08 +02:00
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
places[marker.placeId].panoId = -1;
|
|
|
|
places[marker.placeId].noPano = true;
|
2020-06-03 23:41:08 +02:00
|
|
|
|
2020-06-02 21:44:01 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
places[marker.placeId].panoId = this.response.panoId;
|
|
|
|
places[marker.placeId].noPano = false;
|
|
|
|
|
|
|
|
MapEditor.loadPano(this.response.panoId, places[marker.placeId].pov);
|
2020-06-13 22:39:44 +02:00
|
|
|
});
|
2020-06-02 21:44:01 +02:00
|
|
|
},
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
loadPano: function (panoId, pov) {
|
2020-06-01 21:13:02 +02:00
|
|
|
MapEditor.panorama.setVisible(true);
|
2020-06-05 00:22:41 +02:00
|
|
|
MapEditor.panorama.setPov({ heading: pov.heading, pitch: pov.pitch });
|
|
|
|
MapEditor.panorama.setZoom(pov.zoom);
|
2020-06-02 21:44:01 +02:00
|
|
|
MapEditor.panorama.setPano(panoId);
|
2020-06-01 21:13:02 +02:00
|
|
|
},
|
|
|
|
|
2020-06-04 19:30:35 +02:00
|
|
|
loadPanoForNewPlace: function (panoLocationData) {
|
2020-06-05 00:22:41 +02:00
|
|
|
var placeId = MapEditor.selectedMarker.placeId;
|
|
|
|
|
2020-06-04 19:30:35 +02:00
|
|
|
if (!panoLocationData) {
|
2020-06-05 00:22:41 +02:00
|
|
|
places[placeId].panoId = -1;
|
|
|
|
places[placeId].noPano = true;
|
2020-06-04 19:30:35 +02:00
|
|
|
|
|
|
|
document.getElementById('noPano').style.visibility = 'visible';
|
2020-06-05 00:22:41 +02:00
|
|
|
|
2020-06-04 19:30:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
var latLng = panoLocationData.latLng;
|
|
|
|
|
|
|
|
places[placeId].panoId = panoLocationData.pano;
|
|
|
|
places[placeId].lat = latLng.lat();
|
|
|
|
places[placeId].lng = latLng.lng();
|
|
|
|
|
|
|
|
MapEditor.selectedMarker.setLatLng({ lat: places[placeId].lat, lng: places[placeId].lng });
|
|
|
|
MapEditor.map.panTo(MapEditor.selectedMarker.getLatLng());
|
2020-06-04 19:30:35 +02:00
|
|
|
|
|
|
|
MapEditor.panorama.setVisible(true);
|
2020-06-05 00:22:41 +02:00
|
|
|
MapEditor.panorama.setPov({ heading: 0.0, pitch: 0.0 });
|
|
|
|
MapEditor.panorama.setZoom(0.0);
|
2020-06-04 19:30:35 +02:00
|
|
|
MapEditor.panorama.setPano(panoLocationData.pano);
|
|
|
|
},
|
|
|
|
|
2021-05-09 11:46:03 +02:00
|
|
|
requestPanoData: function (location, canBeIndoor) {
|
2020-06-04 19:30:35 +02:00
|
|
|
var sv = new google.maps.StreetViewService();
|
|
|
|
|
|
|
|
sv.getPanorama({
|
|
|
|
location: location,
|
|
|
|
preference: google.maps.StreetViewPreference.NEAREST,
|
2021-05-02 16:57:47 +02:00
|
|
|
radius: MapEditor.map.getSearchRadius(location),
|
2021-05-09 11:46:03 +02:00
|
|
|
source: canBeIndoor ? google.maps.StreetViewSource.DEFAULT : google.maps.StreetViewSource.OUTDOOR
|
2020-06-04 19:30:35 +02:00
|
|
|
}, function (data, status) {
|
|
|
|
var panoLocationData = status === google.maps.StreetViewStatus.OK ? data.location : null;
|
|
|
|
|
2021-05-09 11:46:03 +02:00
|
|
|
if (panoLocationData === null && !canBeIndoor) {
|
|
|
|
MapEditor.requestPanoData(location, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-04 19:30:35 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
|
|
|
|
MapEditor.loadPanoForNewPlace(panoLocationData);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-06-01 21:13:02 +02:00
|
|
|
select: function (marker) {
|
2020-06-05 00:22:41 +02:00
|
|
|
if (MapEditor.selectedMarker === marker) {
|
2020-06-06 02:18:12 +02:00
|
|
|
MapEditor.closePlace();
|
2020-06-05 00:22:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-06-01 21:13:02 +02:00
|
|
|
|
|
|
|
document.getElementById('map').classList.add('selected');
|
2020-06-02 21:49:37 +02:00
|
|
|
document.getElementById('control').classList.add('selected');
|
2020-06-01 21:13:02 +02:00
|
|
|
document.getElementById('noPano').style.visibility = 'hidden';
|
2020-06-02 21:49:37 +02:00
|
|
|
document.getElementById('panorama').style.visibility = 'visible';
|
2020-06-01 21:13:02 +02:00
|
|
|
document.getElementById('placeControl').style.visibility = 'visible';
|
|
|
|
|
|
|
|
MapEditor.resetSelected();
|
|
|
|
MapEditor.selectedMarker = marker;
|
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
MapEditor.map.resize();
|
2020-06-01 21:13:02 +02:00
|
|
|
MapEditor.map.panTo(marker.getLatLng());
|
|
|
|
|
|
|
|
MapEditor.panorama.setVisible(false);
|
|
|
|
|
2020-06-04 19:30:35 +02:00
|
|
|
if (marker.placeId) {
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.map.changeMarkerIcon(marker, MapEditor.map.iconCollection.iconBlue);
|
2020-06-05 00:22:41 +02:00
|
|
|
|
|
|
|
document.getElementById('deleteButton').style.display = 'block';
|
|
|
|
|
|
|
|
if (places[marker.placeId].panoId) {
|
|
|
|
if (places[marker.placeId].panoId === -1) {
|
|
|
|
document.getElementById('noPano').style.visibility = 'visible';
|
|
|
|
} else {
|
|
|
|
MapEditor.loadPano(places[marker.placeId].panoId, places[marker.placeId].pov);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
|
2020-06-04 19:30:35 +02:00
|
|
|
MapEditor.getPlace(marker.placeId, marker);
|
|
|
|
} else {
|
2020-06-05 00:22:41 +02:00
|
|
|
marker.placeId = 'new_' + new Date().getTime();
|
|
|
|
|
|
|
|
var latLng = marker.getLatLng();
|
|
|
|
|
|
|
|
places[marker.placeId] = { id: null, lat: latLng.lat, lng: latLng.lng, panoId: null, pov: { heading: 0.0, pitch: 0.0, zoom: 0 }, noPano: false };
|
|
|
|
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
|
|
|
|
MapEditor.requestPanoData(latLng);
|
2020-06-04 19:30:35 +02:00
|
|
|
}
|
2020-06-01 21:13:02 +02:00
|
|
|
},
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
resetSelected: function (del) {
|
2020-06-01 21:13:02 +02:00
|
|
|
if (!MapEditor.selectedMarker) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
var placeId = MapEditor.selectedMarker.placeId
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
if (places[placeId].id && !del) {
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.map.changeMarkerIcon(
|
|
|
|
MapEditor.selectedMarker,
|
|
|
|
places[placeId].noPano ? MapEditor.map.iconCollection.iconRed : MapEditor.map.iconCollection.iconGreen
|
|
|
|
);
|
2020-06-04 19:30:35 +02:00
|
|
|
} else {
|
2020-06-05 00:22:41 +02:00
|
|
|
delete places[placeId];
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.map.removeMarker(MapEditor.selectedMarker);
|
2020-06-04 19:30:35 +02:00
|
|
|
}
|
2020-06-05 00:22:41 +02:00
|
|
|
|
|
|
|
document.getElementById('deleteButton').style.display = 'none';
|
|
|
|
},
|
|
|
|
|
|
|
|
applyPlace: function () {
|
|
|
|
var placeId = MapEditor.selectedMarker.placeId;
|
|
|
|
|
|
|
|
if (!places[placeId].noPano) {
|
|
|
|
var latLng = MapEditor.panorama.getPosition();
|
|
|
|
var pov = MapEditor.panorama.getPov();
|
|
|
|
var zoom = MapEditor.panorama.getZoom();
|
|
|
|
|
|
|
|
places[placeId].lat = latLng.lat();
|
|
|
|
places[placeId].lng = latLng.lng();
|
|
|
|
places[placeId].panoId = MapEditor.panorama.getPano();
|
|
|
|
places[placeId].pov = { heading: pov.heading, pitch: pov.pitch, zoom: zoom };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!places[placeId].id) {
|
2020-06-05 19:38:30 +02:00
|
|
|
places[placeId].id = placeId;
|
2020-06-05 00:22:41 +02:00
|
|
|
MapEditor.added[placeId] = places[placeId];
|
|
|
|
|
2020-06-05 19:38:30 +02:00
|
|
|
document.getElementById('added').innerHTML = String(Object.keys(MapEditor.added).length);
|
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
document.getElementById('deleteButton').style.display = 'block';
|
|
|
|
} else {
|
2020-06-05 19:38:30 +02:00
|
|
|
if (!MapEditor.added[placeId]) {
|
|
|
|
MapEditor.edited[placeId] = places[placeId];
|
|
|
|
|
|
|
|
document.getElementById('edited').innerHTML = String(Object.keys(MapEditor.edited).length);
|
|
|
|
} else {
|
|
|
|
MapEditor.added[placeId] = places[placeId];
|
|
|
|
}
|
2020-06-05 00:22:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MapEditor.selectedMarker.setLatLng({ lat: places[placeId].lat, lng: places[placeId].lng });
|
2020-06-06 02:18:12 +02:00
|
|
|
|
|
|
|
document.getElementById('saveButton').disabled = false;
|
2020-06-05 00:22:41 +02:00
|
|
|
},
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
closePlace: function (del) {
|
2020-06-05 00:22:41 +02:00
|
|
|
document.getElementById('map').classList.remove('selected');
|
|
|
|
document.getElementById('control').classList.remove('selected');
|
|
|
|
document.getElementById('noPano').style.visibility = 'hidden';
|
|
|
|
document.getElementById('panorama').style.visibility = 'hidden';
|
|
|
|
document.getElementById('placeControl').style.visibility = 'hidden';
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
MapEditor.resetSelected(del);
|
2020-06-05 00:22:41 +02:00
|
|
|
MapEditor.selectedMarker = null;
|
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
MapEditor.map.resize();
|
2020-06-05 00:22:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
deletePlace: function () {
|
|
|
|
var placeId = MapEditor.selectedMarker.placeId;
|
|
|
|
|
|
|
|
if (places[placeId].id && !MapEditor.added[placeId]) {
|
|
|
|
MapEditor.deleted[placeId] = places[placeId];
|
2020-06-05 19:38:30 +02:00
|
|
|
|
|
|
|
document.getElementById('deleted').innerHTML = String(Object.keys(MapEditor.deleted).length);
|
2020-06-05 00:22:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
MapEditor.closePlace(true);
|
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
delete MapEditor.added[placeId];
|
|
|
|
delete MapEditor.edited[placeId];
|
2021-05-01 20:13:13 +02:00
|
|
|
delete places[placeId];
|
2020-06-05 00:22:41 +02:00
|
|
|
|
2020-06-05 19:38:30 +02:00
|
|
|
document.getElementById('added').innerHTML = String(Object.keys(MapEditor.added).length);
|
|
|
|
document.getElementById('edited').innerHTML = String(Object.keys(MapEditor.edited).length);
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
document.getElementById('saveButton').disabled = false;
|
2020-06-05 19:38:30 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
saveMap: function () {
|
|
|
|
document.getElementById('loading').style.visibility = 'visible';
|
|
|
|
|
|
|
|
var data = new FormData();
|
2020-06-06 02:18:12 +02:00
|
|
|
|
|
|
|
if (MapEditor.metadata.name !== null) {
|
|
|
|
data.append('name', MapEditor.metadata.name);
|
|
|
|
}
|
|
|
|
if (MapEditor.metadata.description !== null) {
|
|
|
|
data.append('description', MapEditor.metadata.description);
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:38:30 +02:00
|
|
|
for (var placeId in MapEditor.added) {
|
|
|
|
if (!MapEditor.added.hasOwnProperty(placeId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
data.append('added[]', JSON.stringify(MapEditor.added[placeId]));
|
|
|
|
}
|
|
|
|
for (var placeId in MapEditor.edited) {
|
|
|
|
if (!MapEditor.edited.hasOwnProperty(placeId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
data.append('edited[]', JSON.stringify(MapEditor.edited[placeId]));
|
|
|
|
}
|
|
|
|
for (var placeId in MapEditor.deleted) {
|
|
|
|
if (!MapEditor.deleted.hasOwnProperty(placeId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
data.append('deleted[]', JSON.stringify(MapEditor.deleted[placeId]));
|
|
|
|
}
|
|
|
|
|
2020-06-13 22:39:44 +02:00
|
|
|
MapGuesser.httpRequest('POST', '/admin/saveMap/' + mapId + '/json', function () {
|
2020-06-05 19:38:30 +02:00
|
|
|
document.getElementById('loading').style.visibility = 'hidden';
|
|
|
|
|
|
|
|
if (this.response.error) {
|
|
|
|
//TODO: handle this error
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MapEditor.replacePlaceIdsToReal(this.response.added);
|
|
|
|
|
2020-06-10 23:15:02 +02:00
|
|
|
if (mapId === 0) {
|
|
|
|
mapId = this.response.mapId;
|
|
|
|
window.history.replaceState(null, '', '/admin/mapEditor/' + mapId);
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:38:30 +02:00
|
|
|
MapEditor.added = {};
|
|
|
|
MapEditor.edited = {};
|
|
|
|
MapEditor.deleted = {};
|
|
|
|
|
|
|
|
document.getElementById('added').innerHTML = '0';
|
|
|
|
document.getElementById('edited').innerHTML = '0';
|
|
|
|
document.getElementById('deleted').innerHTML = '0';
|
2020-06-06 02:18:12 +02:00
|
|
|
|
|
|
|
document.getElementById('saveButton').disabled = true;
|
2020-06-13 22:39:44 +02:00
|
|
|
}, data);
|
2020-06-05 19:38:30 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
replacePlaceIdsToReal: function (addedPlaces) {
|
|
|
|
for (var i = 0; i < addedPlaces.length; ++i) {
|
|
|
|
var tempId = addedPlaces[i].tempId;
|
|
|
|
var placeId = addedPlaces[i].id;
|
|
|
|
places[tempId].id = placeId;
|
|
|
|
}
|
2020-06-01 21:13:02 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-02 21:51:25 +02:00
|
|
|
var Util = {
|
|
|
|
getHighResData: function () {
|
|
|
|
if (window.devicePixelRatio >= 4) {
|
2020-06-20 02:14:17 +02:00
|
|
|
return { ppi: 320, tileSize: 128, zoomOffset: 1, minZoom: 0, maxZoom: 18 };
|
2020-06-02 21:51:25 +02:00
|
|
|
} else if (window.devicePixelRatio >= 2) {
|
2020-06-20 02:14:17 +02:00
|
|
|
return { ppi: 250, tileSize: 256, zoomOffset: 0, minZoom: 1, maxZoom: 19 };
|
2020-06-02 21:51:25 +02:00
|
|
|
} else {
|
2020-06-20 02:14:17 +02:00
|
|
|
return { ppi: 72, tileSize: 512, zoomOffset: -1, minZoom: 2, maxZoom: 20 };
|
2020-06-02 21:51:25 +02:00
|
|
|
}
|
2021-04-27 10:18:28 +02:00
|
|
|
},
|
|
|
|
|
2021-04-27 17:48:45 +02:00
|
|
|
extractCoordinates: function (coordinatesStr) {
|
|
|
|
var coordinates = { valid: false, latlng: { lat: 0., lng: 0. } };
|
2021-04-27 10:18:28 +02:00
|
|
|
var delimiters = [',', ' ', ';'];
|
|
|
|
|
|
|
|
coordinatesStr = coordinatesStr.trim();
|
2021-04-27 17:48:45 +02:00
|
|
|
if (coordinatesStr.length == 0) {
|
2021-04-27 10:18:28 +02:00
|
|
|
return coordinates;
|
|
|
|
}
|
|
|
|
|
2021-04-27 17:48:45 +02:00
|
|
|
for (var delimiter of delimiters) {
|
|
|
|
if (coordinatesStr.indexOf(delimiter) != -1) {
|
2021-04-27 10:18:28 +02:00
|
|
|
|
|
|
|
var coordinatesArr = coordinatesStr.split(delimiter);
|
|
|
|
coordinates.latlng.lat = parseFloat(coordinatesArr[0]);
|
|
|
|
coordinates.latlng.lng = parseFloat(coordinatesArr[1]);
|
|
|
|
|
2021-04-27 17:48:45 +02:00
|
|
|
if (!isNaN(coordinates.latlng.lat) && !isNaN(coordinates.latlng.lng)) {
|
2021-04-27 10:18:28 +02:00
|
|
|
coordinates.valid = true;
|
|
|
|
return coordinates;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return coordinates;
|
2020-06-02 21:51:25 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
var LMapWrapper = {
|
|
|
|
map: null,
|
|
|
|
markers: null,
|
2021-05-01 12:16:10 +02:00
|
|
|
divId: null,
|
2021-05-02 12:23:37 +02:00
|
|
|
iconCollection: {
|
|
|
|
iconGreen: L.icon({
|
|
|
|
iconUrl: STATIC_ROOT + '/img/markers/marker-green.svg?rev' + REVISION,
|
|
|
|
iconSize: [24, 32],
|
|
|
|
iconAnchor: [12, 32]
|
|
|
|
}),
|
|
|
|
iconRed: L.icon({
|
|
|
|
iconUrl: STATIC_ROOT + '/img/markers/marker-red.svg?rev=' + REVISION,
|
|
|
|
iconSize: [24, 32],
|
|
|
|
iconAnchor: [12, 32]
|
|
|
|
}),
|
|
|
|
iconBlue: L.icon({
|
|
|
|
iconUrl: STATIC_ROOT + '/img/markers/marker-blue.svg?rev=' + REVISION,
|
|
|
|
iconSize: [24, 32],
|
|
|
|
iconAnchor: [12, 32]
|
|
|
|
})
|
|
|
|
},
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
init: function (divId, places) {
|
2021-05-01 12:16:10 +02:00
|
|
|
document.getElementById(divId).style.display = "block";
|
2021-05-02 12:23:37 +02:00
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
if (!LMapWrapper.map) {
|
2021-05-01 12:16:10 +02:00
|
|
|
LMapWrapper.divId = divId;
|
|
|
|
LMapWrapper.map = L.map(LMapWrapper.divId, {
|
2021-05-02 13:29:48 +02:00
|
|
|
center: { lat: 0., lng: 0. },
|
2021-05-02 13:45:34 +02:00
|
|
|
zoom: 2
|
2021-05-01 12:16:10 +02:00
|
|
|
});
|
2020-06-04 19:30:35 +02:00
|
|
|
|
2021-05-01 12:16:10 +02:00
|
|
|
LMapWrapper.map.on('click', function (e) {
|
|
|
|
LMapWrapper.placeMarker(e.latlng);
|
|
|
|
});
|
|
|
|
|
|
|
|
var highResData = Util.getHighResData();
|
2020-06-02 21:51:25 +02:00
|
|
|
|
2021-05-01 12:16:10 +02:00
|
|
|
L.tileLayer(tileUrl, {
|
|
|
|
attribution: tileAttribution,
|
2021-05-08 18:20:54 +02:00
|
|
|
subdomains: tileSubdomains,
|
2021-05-01 12:16:10 +02:00
|
|
|
ppi: highResData.ppi,
|
|
|
|
tileSize: highResData.tileSize,
|
|
|
|
zoomOffset: highResData.zoomOffset,
|
|
|
|
minZoom: highResData.minZoom,
|
|
|
|
maxZoom: highResData.maxZoom
|
|
|
|
}).addTo(LMapWrapper.map);
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2021-05-02 13:29:48 +02:00
|
|
|
if (mapId) {
|
|
|
|
LMapWrapper.map.fitBounds(L.latLngBounds({ lat: mapBounds.south, lng: mapBounds.west }, { lat: mapBounds.north, lng: mapBounds.east }));
|
|
|
|
}
|
2021-05-01 12:16:10 +02:00
|
|
|
}
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
LMapWrapper.loadMarkers(places);
|
2021-05-02 13:13:11 +02:00
|
|
|
|
2021-05-02 14:53:01 +02:00
|
|
|
document.getElementById('streetViewCoverSelector').style.display = 'none';
|
2021-05-02 12:23:37 +02:00
|
|
|
},
|
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
hide: function () {
|
2021-05-01 12:16:10 +02:00
|
|
|
document.getElementById(LMapWrapper.divId).style.display = 'none';
|
|
|
|
},
|
2021-05-02 12:23:37 +02:00
|
|
|
|
2021-05-01 12:16:10 +02:00
|
|
|
loadMarkers: function (places) {
|
2021-05-01 20:28:44 +02:00
|
|
|
if (!LMapWrapper.markers) {
|
2021-05-01 12:16:10 +02:00
|
|
|
LMapWrapper.markers = L.markerClusterGroup({
|
|
|
|
maxClusterRadius: 50
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
LMapWrapper.markers.clearLayers();
|
|
|
|
}
|
2021-05-02 12:23:37 +02:00
|
|
|
|
|
|
|
for (var placeId in places) {
|
|
|
|
if (!places.hasOwnProperty(placeId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var place = places[placeId];
|
|
|
|
|
|
|
|
var marker = L.marker({ lat: place.lat, lng: place.lng }, {
|
|
|
|
icon: place.noPano ? LMapWrapper.iconCollection.iconRed : LMapWrapper.iconCollection.iconGreen,
|
|
|
|
zIndexOffset: 1000
|
2021-05-01 20:13:13 +02:00
|
|
|
})
|
|
|
|
.addTo(LMapWrapper.markers)
|
|
|
|
.on('click', function () {
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.select(this);
|
|
|
|
});
|
|
|
|
|
2021-05-01 20:13:13 +02:00
|
|
|
marker.placeId = placeId;
|
2021-05-02 12:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LMapWrapper.map.addLayer(LMapWrapper.markers);
|
|
|
|
},
|
|
|
|
|
|
|
|
// TODO: check whether marker is already existing on the map for the coordinates
|
|
|
|
// or alternatively block saving for matching coordinates
|
|
|
|
placeMarker: function (latLng) {
|
|
|
|
var marker = L.marker(latLng, {
|
|
|
|
icon: LMapWrapper.iconCollection.iconBlue,
|
|
|
|
zIndexOffset: 2000
|
|
|
|
})
|
2021-05-01 20:13:13 +02:00
|
|
|
.addTo(LMapWrapper.markers)
|
2021-05-02 12:23:37 +02:00
|
|
|
.on('click', function () {
|
|
|
|
MapEditor.select(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
MapEditor.select(marker);
|
|
|
|
},
|
|
|
|
|
|
|
|
panTo: function (latLng) {
|
|
|
|
LMapWrapper.map.panTo(latLng);
|
|
|
|
},
|
2020-06-11 23:23:28 +02:00
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
resize: function () {
|
|
|
|
LMapWrapper.map.invalidateSize(true);
|
2021-05-02 12:23:37 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
changeMarkerIcon: function (marker, icon) {
|
|
|
|
marker.setIcon(icon);
|
|
|
|
marker.setZIndexOffset(2000);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMarker: function (marker) {
|
2021-05-01 20:13:13 +02:00
|
|
|
LMapWrapper.markers.removeLayer(marker);
|
2021-05-02 12:56:25 +02:00
|
|
|
},
|
|
|
|
|
2021-05-02 16:57:47 +02:00
|
|
|
toggleStreetViewCover: function () { },
|
|
|
|
|
|
|
|
getSearchRadius: function (location) {
|
|
|
|
return 100;
|
|
|
|
}
|
2021-05-02 12:23:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var GMapWrapper = {
|
|
|
|
map: null,
|
|
|
|
markers: null,
|
2021-05-01 12:16:10 +02:00
|
|
|
divId: null,
|
2021-05-02 12:56:25 +02:00
|
|
|
streetViewCover: null,
|
|
|
|
streetViewCoverOn: false,
|
2021-05-02 12:23:37 +02:00
|
|
|
iconCollection: {
|
|
|
|
iconGreen: {
|
|
|
|
url: STATIC_ROOT + '/img/markers/marker-green.svg?rev' + REVISION,
|
|
|
|
scaledSize: new google.maps.Size(24, 32), // scaled size
|
|
|
|
origin: new google.maps.Point(0, 0), // origin
|
|
|
|
anchor: new google.maps.Point(12, 32) // anchor
|
|
|
|
},
|
|
|
|
iconRed: {
|
|
|
|
url: STATIC_ROOT + '/img/markers/marker-red.svg?rev' + REVISION,
|
|
|
|
scaledSize: new google.maps.Size(24, 32), // scaled size
|
|
|
|
origin: new google.maps.Point(0, 0), // origin
|
|
|
|
anchor: new google.maps.Point(12, 32) // anchor
|
|
|
|
},
|
|
|
|
iconBlue: {
|
|
|
|
url: STATIC_ROOT + '/img/markers/marker-blue.svg?rev' + REVISION,
|
|
|
|
scaledSize: new google.maps.Size(24, 32), // scaled size
|
|
|
|
origin: new google.maps.Point(0, 0), // origin
|
|
|
|
anchor: new google.maps.Point(12, 32) // anchor
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function (divId, places) {
|
2021-05-01 12:16:10 +02:00
|
|
|
document.getElementById(divId).style.display = "block";
|
2021-05-02 12:23:37 +02:00
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
if (!GMapWrapper.map) {
|
2021-05-01 12:16:10 +02:00
|
|
|
GMapWrapper.divId = divId;
|
|
|
|
GMapWrapper.map = new google.maps.Map(document.getElementById(GMapWrapper.divId), {
|
|
|
|
center: { lat: 0., lng: 0. },
|
|
|
|
zoom: 2,
|
|
|
|
fullscreenControl: false,
|
|
|
|
zoomControl: true,
|
|
|
|
zoomControlOptions: {
|
|
|
|
position: google.maps.ControlPosition.LEFT_BOTTOM
|
|
|
|
},
|
2021-05-02 13:42:46 +02:00
|
|
|
streetViewControl: false,
|
2021-05-01 12:16:10 +02:00
|
|
|
draggableCursor: 'crosshair'
|
|
|
|
});
|
|
|
|
|
2021-05-02 12:56:25 +02:00
|
|
|
GMapWrapper.streetViewCover = new google.maps.StreetViewCoverageLayer();
|
|
|
|
|
2021-05-01 12:16:10 +02:00
|
|
|
GMapWrapper.map.addListener('click', function (mapsMouseEvent) {
|
|
|
|
GMapWrapper.placeMarker({
|
|
|
|
lat: mapsMouseEvent.latLng.lat(),
|
|
|
|
lng: mapsMouseEvent.latLng.lng()
|
|
|
|
});
|
2021-05-02 12:23:37 +02:00
|
|
|
});
|
2021-05-01 12:16:10 +02:00
|
|
|
|
2021-05-02 13:29:48 +02:00
|
|
|
if (mapId) {
|
|
|
|
GMapWrapper.map.fitBounds({ south: mapBounds.south, west: mapBounds.west, north: mapBounds.north, east: mapBounds.east });
|
|
|
|
}
|
2021-05-01 12:16:10 +02:00
|
|
|
}
|
2021-05-02 12:23:37 +02:00
|
|
|
|
|
|
|
GMapWrapper.loadMarkers(places);
|
2021-05-01 12:16:10 +02:00
|
|
|
|
2021-05-02 14:53:01 +02:00
|
|
|
document.getElementById('streetViewCoverSelector').style.display = 'block'
|
2021-05-02 12:23:37 +02:00
|
|
|
},
|
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
hide: function () {
|
2021-05-01 12:16:10 +02:00
|
|
|
document.getElementById(GMapWrapper.divId).style.display = 'none';
|
|
|
|
},
|
2021-05-02 12:23:37 +02:00
|
|
|
|
2021-05-01 12:16:10 +02:00
|
|
|
loadMarkers: function (places) {
|
2021-05-01 20:28:44 +02:00
|
|
|
if (!GMapWrapper.markers) {
|
2021-05-01 12:16:10 +02:00
|
|
|
GMapWrapper.markers = new MarkerClusterer(GMapWrapper.map, [], {
|
|
|
|
imagePath: STATIC_ROOT + '/img/markers/m',
|
|
|
|
imageExtension: 'png?rev' + REVISION
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
GMapWrapper.markers.clearMarkers();
|
|
|
|
}
|
2021-05-01 20:28:44 +02:00
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
for (var placeId in places) {
|
|
|
|
if (!places.hasOwnProperty(placeId)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var place = places[placeId];
|
|
|
|
|
|
|
|
var marker = new google.maps.Marker({
|
|
|
|
position: {
|
|
|
|
lat: place.lat,
|
|
|
|
lng: place.lng
|
|
|
|
},
|
|
|
|
icon: place.noPano ? GMapWrapper.iconCollection.iconRed : GMapWrapper.iconCollection.iconGreen
|
|
|
|
});
|
2020-06-05 00:22:41 +02:00
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
marker.getLatLng = function () { return { lat: this.getPosition().lat(), lng: this.getPosition().lng() } };
|
|
|
|
marker.setLatLng = function (coords) { this.setPosition(coords) };
|
2020-06-05 00:22:41 +02:00
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
marker.addListener('click', function () {
|
|
|
|
MapEditor.select(this);
|
|
|
|
});
|
|
|
|
|
2021-05-01 20:13:13 +02:00
|
|
|
marker.placeId = placeId;
|
2021-05-02 12:23:37 +02:00
|
|
|
|
|
|
|
GMapWrapper.markers.addMarker(marker);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// TODO: check whether marker is already existing on the map for the coordinates
|
|
|
|
// or alternatively block saving for matching coordinates
|
|
|
|
placeMarker: function (latLng) {
|
|
|
|
var marker = new google.maps.Marker({
|
|
|
|
map: GMapWrapper.map,
|
|
|
|
position: latLng,
|
|
|
|
icon: GMapWrapper.iconCollection.iconBlue,
|
|
|
|
});
|
|
|
|
|
|
|
|
marker.getLatLng = function () { return { lat: this.getPosition().lat(), lng: this.getPosition().lng() } };
|
|
|
|
marker.setLatLng = function (coords) { this.setPosition(coords) };
|
|
|
|
|
|
|
|
marker.addListener('click', function () {
|
2020-06-01 21:13:02 +02:00
|
|
|
MapEditor.select(this);
|
|
|
|
});
|
2020-06-02 21:44:01 +02:00
|
|
|
|
2021-05-02 12:23:37 +02:00
|
|
|
GMapWrapper.markers.addMarker(marker);
|
|
|
|
|
|
|
|
MapEditor.select(marker);
|
|
|
|
},
|
|
|
|
|
|
|
|
panTo: function (latLng) {
|
|
|
|
GMapWrapper.map.panTo(latLng);
|
|
|
|
},
|
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
resize: function () {
|
|
|
|
google.maps.event.trigger(GMapWrapper.map, 'resize');
|
2021-05-02 12:23:37 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
changeMarkerIcon: function (marker, icon) {
|
|
|
|
marker.setIcon(icon);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeMarker: function (marker) {
|
|
|
|
GMapWrapper.markers.removeMarker(marker);
|
2021-05-02 12:56:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleStreetViewCover: function () {
|
|
|
|
if (GMapWrapper.streetViewCoverOn) {
|
|
|
|
GMapWrapper.streetViewCover.setMap(null);
|
|
|
|
GMapWrapper.streetViewCoverOn = false;
|
|
|
|
} else {
|
|
|
|
GMapWrapper.streetViewCover.setMap(GMapWrapper.map);
|
|
|
|
GMapWrapper.streetViewCoverOn = true;
|
|
|
|
}
|
2021-05-02 16:57:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getSearchRadius: function (location) {
|
|
|
|
// source: https://www.yorku.ca/mack/CHI01.htm
|
|
|
|
var movementOffset = 4;
|
|
|
|
|
|
|
|
// source: https://groups.google.com/g/google-maps-js-api-v3/c/hDRO4oHVSeM/m/osOYQYXg2oUJ?pli=1
|
|
|
|
var metersPerPixel = 156543.03392 * Math.cos(location.lat * Math.PI / 180) / Math.pow(2, GMapWrapper.map.getZoom());
|
|
|
|
|
|
|
|
var minSearchRadius = 5;
|
|
|
|
|
|
|
|
var searchRadius = Math.max(minSearchRadius, Math.round(movementOffset * metersPerPixel));
|
|
|
|
|
|
|
|
return searchRadius;
|
2021-05-02 12:23:37 +02:00
|
|
|
}
|
|
|
|
};
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2021-05-01 20:31:43 +02:00
|
|
|
// initialize content of #map with google maps
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.map = GMapWrapper;
|
2021-05-01 12:16:10 +02:00
|
|
|
MapEditor.map.init('gmap', places);
|
2020-06-11 23:23:28 +02:00
|
|
|
|
2020-06-01 21:13:02 +02:00
|
|
|
MapEditor.panorama = new google.maps.StreetViewPanorama(document.getElementById('panorama'), {
|
|
|
|
// switch off fullscreenControl because positioning doesn't work
|
|
|
|
fullscreenControl: false,
|
|
|
|
fullscreenControlOptions: {
|
|
|
|
position: google.maps.ControlPosition.LEFT_TOP
|
2020-06-01 22:07:13 +02:00
|
|
|
},
|
|
|
|
motionTracking: false
|
2020-06-01 21:13:02 +02:00
|
|
|
});
|
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
document.getElementById('mapName').onclick = function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2020-06-14 02:31:09 +02:00
|
|
|
MapGuesser.showModal('metadata');
|
2020-06-14 02:53:11 +02:00
|
|
|
document.getElementById('metadataForm').elements.name.select();
|
2020-06-06 02:18:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
document.getElementById('metadataForm').onsubmit = function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
MapEditor.editMetadata();
|
|
|
|
};
|
|
|
|
|
|
|
|
document.getElementById('closeMetadataButton').onclick = function () {
|
2020-06-14 02:31:09 +02:00
|
|
|
MapGuesser.hideModal();
|
2020-06-06 02:18:12 +02:00
|
|
|
};
|
|
|
|
|
2020-06-05 19:38:30 +02:00
|
|
|
document.getElementById('saveButton').onclick = function () {
|
|
|
|
MapEditor.saveMap();
|
|
|
|
};
|
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
document.getElementById('applyButton').onclick = function () {
|
|
|
|
MapEditor.applyPlace();
|
|
|
|
};
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2020-06-06 02:18:12 +02:00
|
|
|
document.getElementById('closeButton').onclick = function () {
|
2020-06-05 00:22:41 +02:00
|
|
|
MapEditor.closePlace();
|
|
|
|
};
|
2020-06-01 21:13:02 +02:00
|
|
|
|
2020-06-05 00:22:41 +02:00
|
|
|
document.getElementById('deleteButton').onclick = function () {
|
|
|
|
MapEditor.deletePlace();
|
2020-06-01 21:13:02 +02:00
|
|
|
};
|
2021-04-27 10:18:28 +02:00
|
|
|
|
|
|
|
document.getElementById('jumpButton').onclick = function (e) {
|
|
|
|
var coordinatesStr = document.getElementById("jumpCoordinates").value;
|
|
|
|
var coordinates = Util.extractCoordinates(coordinatesStr);
|
|
|
|
|
2021-04-27 17:48:45 +02:00
|
|
|
if (coordinates.valid) {
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.map.placeMarker(coordinates.latlng);
|
2021-04-27 10:18:28 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.getElementById('jumpCoordinates').onkeyup = function (e) {
|
|
|
|
var coordinatesStr = document.getElementById("jumpCoordinates").value;
|
|
|
|
var coordinates = Util.extractCoordinates(coordinatesStr);
|
|
|
|
var jumpButton = document.getElementById("jumpButton");
|
|
|
|
|
2021-04-27 17:48:45 +02:00
|
|
|
if (coordinates.valid) {
|
2021-04-27 10:18:28 +02:00
|
|
|
jumpButton.disabled = false;
|
|
|
|
|
2021-04-27 17:48:45 +02:00
|
|
|
if (e.key == 'Enter') {
|
2021-05-02 12:23:37 +02:00
|
|
|
MapEditor.map.placeMarker(coordinates.latlng);
|
2021-04-27 10:18:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
jumpButton.disabled = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
document.getElementById('mapSelector').onclick = function () {
|
2021-05-01 12:16:10 +02:00
|
|
|
MapEditor.closePlace();
|
2021-05-01 20:13:13 +02:00
|
|
|
MapEditor.map.hide();
|
2021-05-01 12:16:10 +02:00
|
|
|
|
2021-05-01 20:28:44 +02:00
|
|
|
if (MapEditor.map === GMapWrapper) {
|
2021-05-01 12:16:10 +02:00
|
|
|
MapEditor.map = LMapWrapper;
|
2021-05-01 20:13:13 +02:00
|
|
|
MapEditor.map.init('lmap', places);
|
2021-05-01 12:16:10 +02:00
|
|
|
} else {
|
|
|
|
MapEditor.map = GMapWrapper;
|
|
|
|
MapEditor.map.init('gmap', places);
|
|
|
|
}
|
2021-05-02 12:56:25 +02:00
|
|
|
}
|
2021-05-01 12:16:10 +02:00
|
|
|
|
2021-05-02 12:56:25 +02:00
|
|
|
document.getElementById('streetViewCoverSelector').onclick = function () {
|
|
|
|
MapEditor.map.toggleStreetViewCover();
|
2021-05-01 12:16:10 +02:00
|
|
|
}
|
|
|
|
|
2020-06-01 21:13:02 +02:00
|
|
|
})();
|