MAPG-103 make possible to select a new place on map

This commit is contained in:
Bence Pőcze 2020-06-04 19:30:35 +02:00
parent 1915b252c6
commit 138ff3fe6a

View File

@ -32,6 +32,46 @@
MapEditor.panorama.setPano(panoId); MapEditor.panorama.setPano(panoId);
}, },
loadPanoForNewPlace: function (panoLocationData) {
if (!panoLocationData) {
MapEditor.selectedMarker.noPano = true;
document.getElementById('noPano').style.visibility = 'visible';
return;
}
var latLng = panoLocationData.latLng
MapEditor.selectedMarker.setLatLng({ lat: latLng.lat(), lng: latLng.lng() });
MapEditor.panorama.setVisible(true);
MapEditor.panorama.setPov({ heading: 0, pitch: 0 });
MapEditor.panorama.setZoom(0);
MapEditor.panorama.setPano(panoLocationData.pano);
},
requestPanoData: function (location, canBeIndoor) {
var sv = new google.maps.StreetViewService();
sv.getPanorama({
location: location,
preference: google.maps.StreetViewPreference.NEAREST,
source: canBeIndoor ? google.maps.StreetViewSource.DEFAULT : google.maps.StreetViewSource.OUTDOOR
}, function (data, status) {
var panoLocationData = status === google.maps.StreetViewStatus.OK ? data.location : null;
if (panoLocationData === null && !canBeIndoor) {
MapEditor.requestPanoData(location, true);
return;
}
document.getElementById('loading').style.visibility = 'hidden';
MapEditor.selectedMarker.setOpacity(1.0);
MapEditor.loadPanoForNewPlace(panoLocationData);
});
},
select: function (marker) { select: function (marker) {
document.getElementById('loading').style.visibility = 'visible'; document.getElementById('loading').style.visibility = 'visible';
@ -44,15 +84,21 @@
MapEditor.resetSelected(); MapEditor.resetSelected();
MapEditor.selectedMarker = marker; MapEditor.selectedMarker = marker;
marker.setIcon(IconCollection.iconBlue); if (marker.placeId) {
marker.setZIndexOffset(2000); marker.setIcon(IconCollection.iconBlue);
marker.setZIndexOffset(2000);
}
MapEditor.map.invalidateSize(true); MapEditor.map.invalidateSize(true);
MapEditor.map.panTo(marker.getLatLng()); MapEditor.map.panTo(marker.getLatLng());
MapEditor.panorama.setVisible(false); MapEditor.panorama.setVisible(false);
MapEditor.getPlace(marker.placeId, marker); if (marker.placeId) {
MapEditor.getPlace(marker.placeId, marker);
} else {
MapEditor.requestPanoData(marker.getLatLng());
}
}, },
resetSelected: function () { resetSelected: function () {
@ -60,8 +106,12 @@
return; return;
} }
MapEditor.selectedMarker.setIcon(MapEditor.selectedMarker.noPano ? IconCollection.iconRed : IconCollection.iconGreen); if (MapEditor.selectedMarker.placeId) {
MapEditor.selectedMarker.setZIndexOffset(1000); MapEditor.selectedMarker.setIcon(MapEditor.selectedMarker.noPano ? IconCollection.iconRed : IconCollection.iconGreen);
MapEditor.selectedMarker.setZIndexOffset(1000);
} else {
MapEditor.map.removeLayer(MapEditor.selectedMarker);
}
} }
}; };
@ -100,6 +150,17 @@
zoomControl: false zoomControl: false
}); });
MapEditor.map.on('click', function (e) {
var marker = L.marker(e.latlng, {
icon: IconCollection.iconBlue,
zIndexOffset: 2000,
opacity: 0.0
})
.addTo(MapEditor.map);
MapEditor.select(marker);
});
var highResData = Util.getHighResData(); var highResData = Util.getHighResData();
L.tileLayer(tileUrl, { L.tileLayer(tileUrl, {