|
|
@@ -1,4 +1,4 @@
|
|
|
-var app, map;
|
|
|
+var app, map, placesMarkerLayer, currentPositionMarker;
|
|
|
|
|
|
var DEFAULT_ZOOM = 15;
|
|
|
var DEFAULT_MARKER_ICON = L.icon({
|
|
|
@@ -6,6 +6,14 @@ var DEFAULT_MARKER_ICON = L.icon({
|
|
|
iconSize: [80, 80]
|
|
|
});
|
|
|
|
|
|
+var CURRENT_POSITION_ICON = new L.DivIcon({
|
|
|
+ className: 'current-location-icon-container',
|
|
|
+ iconSize: [10, 10],
|
|
|
+ tooltipAnchor: [0, 50],
|
|
|
+ html: '<div class="current-location-icon"></div>'
|
|
|
+});
|
|
|
+
|
|
|
+
|
|
|
function setupMap() {
|
|
|
map = new L.map('map', { zoomControl: false, attributionControl: false });
|
|
|
map.setView([ 52.520008, 13.404954 ], 15);
|
|
|
@@ -19,6 +27,8 @@ function setupMap() {
|
|
|
accessToken: 'pk.eyJ1IjoibmVidWxvbiIsImEiOiI3NmNkODc5ZDMyNjcxMWM2M2UyODEyMjdkM2YyMjVlOSJ9.Cpz0-WRwBwE-DNdNfGDu_w'
|
|
|
}).addTo(map);
|
|
|
|
|
|
+ placesMarkerLayer = new L.FeatureGroup();
|
|
|
+
|
|
|
// set map position either based on url or default
|
|
|
var u = new URL(window.location);
|
|
|
var lon = u.searchParams.get('lon');
|
|
|
@@ -29,6 +39,9 @@ function setupMap() {
|
|
|
map.flyTo(L.latLng(lat, lon), zoom || DEFAULT_ZOOM);
|
|
|
} else {
|
|
|
navigator.geolocation.getCurrentPosition(function (pos) {
|
|
|
+ currentPositionMarker = L.marker(L.latLng(pos.coords.latitude, pos.coords.longitude), { icon: CURRENT_POSITION_ICON });
|
|
|
+ currentPositionMarker.addTo(map);
|
|
|
+
|
|
|
map.flyTo(L.latLng(pos.coords.latitude, pos.coords.longitude), DEFAULT_ZOOM);
|
|
|
});
|
|
|
}
|
|
|
@@ -41,6 +54,13 @@ function setupMap() {
|
|
|
u.searchParams.set('zoom', map.getZoom());
|
|
|
|
|
|
history.replaceState({}, window.document.title, u);
|
|
|
+
|
|
|
+ app.refreshPlaces();
|
|
|
+ });
|
|
|
+
|
|
|
+ map.on('zoomend', function () {
|
|
|
+ if (map.getZoom() < 17) map.removeLayer(placesMarkerLayer);
|
|
|
+ else map.addLayer(placesMarkerLayer);
|
|
|
});
|
|
|
|
|
|
var mapillaryKey = 'SmRiZXFSN3RJYVpKdGd2V3BQZ0dMdzoxZjY3YjA3MmU2OWU2ODll';
|
|
|
@@ -72,6 +92,17 @@ function setupMap() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ // watch for position updates
|
|
|
+ navigator.geolocation.watchPosition(function (pos) {
|
|
|
+ if (!currentPositionMarker) {
|
|
|
+ currentPositionMarker = L.marker(L.latLng(pos.coords.latitude, pos.coords.longitude), { icon: CURRENT_POSITION_ICON });
|
|
|
+ currentPositionMarker.addTo(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ currentPositionMarker.setLatLng(L.latLng(pos.coords.latitude, pos.coords.longitude));
|
|
|
+ }, function (error) {
|
|
|
+ console.error('Error watching position:', error);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
app = new Vue({
|
|
|
@@ -81,12 +112,56 @@ app = new Vue({
|
|
|
querySearchString: '',
|
|
|
querySearchResults: [],
|
|
|
searchMarker: {},
|
|
|
+ placesMarker: {},
|
|
|
markerDetailsOpen: false,
|
|
|
markerDetails: {
|
|
|
businessDetails: null
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ refreshPlaces: function () {
|
|
|
+ var that = this;
|
|
|
+
|
|
|
+ // only refresh places on low zoom
|
|
|
+ if (map.getZoom() < 17) return;
|
|
|
+
|
|
|
+ var params = {
|
|
|
+ format: 'json',
|
|
|
+ limit: 100,
|
|
|
+ addressdetails: 1,
|
|
|
+ bounded: 1,
|
|
|
+ viewbox: map.getBounds().toBBoxString(),
|
|
|
+ q: '[pub]'
|
|
|
+ };
|
|
|
+
|
|
|
+ axios.get('https://nominatim.openstreetmap.org/search.php', {
|
|
|
+ params: params
|
|
|
+ }).then(function (response) {
|
|
|
+ response.data.forEach(function (item) {
|
|
|
+ if (that.placesMarker[item.place_id]) return;
|
|
|
+
|
|
|
+ var m = L.marker(L.latLng(item.lat, item.lon), {
|
|
|
+ icon: new L.DivIcon({
|
|
|
+ className: 'my-div-icon',
|
|
|
+ iconSize: [20, 20],
|
|
|
+ tooltipAnchor: [0, 50],
|
|
|
+ html: '<i class="fa fa-glass-martini poi-icon"></i>'
|
|
|
+ })
|
|
|
+ });
|
|
|
+ m.bindTooltip(item.display_name, { direction: 'bottom', offset: [0, 20] });
|
|
|
+ m.on('click', function (e) {
|
|
|
+ // that.openPlaceDetails(item);
|
|
|
+ // that.activateSearchMarker(item);
|
|
|
+ });
|
|
|
+
|
|
|
+ placesMarkerLayer.addLayer(m);
|
|
|
+
|
|
|
+ that.placesMarker[item.place_id] = m;
|
|
|
+ });
|
|
|
+ }).catch(function (error) {
|
|
|
+ console.error(error);
|
|
|
+ });
|
|
|
+ },
|
|
|
openPlaceDetails: function (item) {
|
|
|
var that = this;
|
|
|
|