| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- var app, map, placesMarkerLayer, currentPositionMarker;
- var DEFAULT_ZOOM = 15;
- var DEFAULT_MARKER_ICON = L.icon({
- iconUrl: 'pin.svg',
- 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>'
- });
- var overpassFrontend = new OverpassFrontend('//overpass-api.de/api/interpreter', {
- timeGap: 10,
- effortPerRequest: 100
- });
- function setupMap() {
- map = new L.map('map', { zoomControl: false, attributionControl: false });
- map.setView([ 52.520008, 13.404954 ], 15);
- L.control.scale({ position: 'bottomright', imperial: false }).addTo(map);
- // L.control.zoom({ position: 'topright' }).addTo(map);
- mapboxLayer = L.tileLayer('https://api.mapbox.com/styles/v1/nebulon/{id}/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoibmVidWxvbiIsImEiOiI3NmNkODc5ZDMyNjcxMWM2M2UyODEyMjdkM2YyMjVlOSJ9.Cpz0-WRwBwE-DNdNfGDu_w', {
- attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
- maxZoom: 20,
- id: 'cjpmm73gq0fbg2speu42o2y8a',
- accessToken: 'pk.eyJ1IjoibmVidWxvbiIsImEiOiI3NmNkODc5ZDMyNjcxMWM2M2UyODEyMjdkM2YyMjVlOSJ9.Cpz0-WRwBwE-DNdNfGDu_w'
- });
- satelliteLayer = L.tileLayer('http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{
- maxZoom: 20,
- subdomains:['mt0','mt1','mt2','mt3']
- });
- var baseLayers = {
- 'Map': mapboxLayer,
- 'Satellite': satelliteLayer
- };
- L.control.layers(baseLayers, {}).addTo(map);
- // set the default layers
- map.addLayer(mapboxLayer);
- var amenityTypes = 'restaurant|cafe|bar|pub|pharmacy|toilets';
- var amenityLayer = new OverpassLayer({
- query: '(node[amenity~"^(' + amenityTypes + ')$"];way[amenity~"^(' + amenityTypes + ')$"];relation[amenity~"^(' + amenityTypes + ')$"];);',
- minZoom: 18,
- updateAssets: function (domNode, objectData, layer) {
- domNode.onclick = function (event) {
- event.stopPropagation();
- app.openPoi(objectData.twigData);
- };
- },
- feature: {
- body: '',
- style: {
- width: 0,
- fill: false
- },
- markerSign: '<span>{{ tags.name }}</span>',
- markerSymbol: '{% if tags.amenity=="restaurant" %}<i class="fas fa-utensils"></i>' +
- '{% elseif tags.amenity=="cafe" %}<i class="fas fa-coffee"></i>' +
- '{% elseif tags.amenity=="bar" %}<i class="fas fa-glass-cheers"></i>' +
- '{% elseif tags.amenity=="pub" %}<i class="fas fa-beer"></i>' +
- '{% elseif tags.amenity=="pharmacy" %}<i class="fas fa-prescription-bottle-alt"></i>' +
- '{% elseif tags.amenity=="toilets" %}<i class="fas fa-toilet-paper"></i>' +
- '{% endif %}'
- }
- });
- amenityLayer.addTo(map);
- var publicTransportLayer = new OverpassLayer({
- query: '(node[public_transport="stop_position"];node[public_transport="station"];);',
- minZoom: 18,
- updateAssets: function (domNode, objectData, layer) {
- domNode.onclick = function (event) {
- event.stopPropagation();
- app.openPoi(objectData.twigData);
- };
- },
- feature: {
- body: '',
- style: {
- width: 0,
- fill: false
- },
- // markerSign: '<span>{{ tags.name }}</span>',
- markerSymbol: '{% if tags.subway=="yes" %}<img src="ubahn.svg" width="32" height="32"/>' +
- '{% elseif tags.bus=="yes" %}<img src="bus.svg" width="32" height="32"/>' +
- '{% elseif tags.light_rail=="yes" %}<img src="sbahn.svg" width="32" height="32"/>' +
- '{% elseif tags.tram=="yes" %}<img src="tram.svg" width="32" height="32"/>' +
- '{% endif %}'
- }
- });
- publicTransportLayer.addTo(map);
- L.easyPrint({
- title: 'Export tis map!',
- position: 'topright',
- sizeModes: ['A4Portrait', 'A4Landscape'],
- exportOnly: true
- }).addTo(map);
- L.control.measure({
- position: 'topright',
- primaryLengthUnit: 'meters',
- primaryAreaUnit: 'sqmeters',
- activeColor: '#555555',
- completedColor: '#000000'
- }).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');
- var lat = u.searchParams.get('lat');
- var zoom = u.searchParams.get('zoom');
- if (lon && lat) {
- 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);
- });
- }
- // Update the url bar to match position
- map.on('moveend', function (event) {
- var u = new URL(window.location);
- u.searchParams.set('lon', map.getCenter().lng);
- u.searchParams.set('lat', map.getCenter().lat);
- u.searchParams.set('zoom', map.getZoom());
- history.replaceState({}, window.document.title, u);
- });
- map.on('zoomend', function () {
- if (map.getZoom() < 17) map.removeLayer(placesMarkerLayer);
- else map.addLayer(placesMarkerLayer);
- });
- map.on('contextmenu ', function (event) {
- var menu = document.getElementById('contextMenu');
- function contextMenuDismissHandler() {
- menu.classList.remove('visible');
- document.removeEventListener('click', contextMenuDismissHandler);
- }
- document.addEventListener('click', contextMenuDismissHandler);
- menu.classList.add('visible');
- menu.style.left = event.originalEvent.clientX + 'px';
- menu.style.top = event.originalEvent.clientY + 'px';
- });
- // 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({
- el: '#app',
- data: {
- sidePanelOpen: false,
- sidePanelBusy: false,
- querySearchString: '',
- querySearchResults: [],
- searchMarker: {},
- placesMarker: {},
- markerDetailsOpen: false,
- markerDetails: {
- businessDetails: null
- },
- poiDetails: {}
- },
- methods: {
- openPoi: function (item) {
- console.log(item.tags)
- this.poiDetails = item;
- this.sidePanelOpen = true;
- this.markerDetailsOpen = true;
- },
- openPlaceDetails: function (item) {
- var that = this;
- var params = {
- name: item.display_name,
- lat: item.lat,
- lon: item.lon,
- class: item.class
- };
- axios.get('/api/places/details', {
- params: params
- }).then(function (response) {
- that.sidePanelOpen = true;
- that.markerDetailsOpen = true;
- that.markerDetails = item;
- that.markerDetails.businessDetails = response.data;
- }).catch(function (error) {
- console.error(error);
- that.markerDetailsOpen = true;
- that.markerDetails = item;
- });
- },
- addSearchMarker: function (items) {
- var that = this;
- that.clearSearchMarker();
- items.forEach(function (item) {
- var m = L.marker(L.latLng(item.lat, item.lon), {
- icon: DEFAULT_MARKER_ICON,
- opacity: 0.5
- });
- m.bindTooltip(item.display_name, { direction: 'bottom' });
- m.on('click', function (e) {
- that.openPlaceDetails(item);
- that.activateSearchMarker(item);
- });
- m.addTo(map);
- that.searchMarker[item.id] = m;
- });
- },
- clearSearchMarker: function () {
- var that = this;
- Object.keys(this.searchMarker).forEach(function (placeId) {
- that.searchMarker[placeId].remove();
- });
- this.searchMarker = {};
- },
- activateSearchMarker: function (item) {
- var that = this;
- Object.keys(this.searchMarker).forEach(function (id) {
- that.searchMarker[id].setOpacity(id === item.id ? 1 : 0.6);
- });
- },
- activateSearchItem: function (item) {
- map.flyTo(L.latLng(item.lat, item.lon), DEFAULT_ZOOM);
- this.activateSearchMarker(item);
- },
- searchPlaces: function () {
- var that = this;
- this.querySearchResults = [];
- this.markerDetailsOpen = false;
- this.sidePanelOpen = true;
- this.sidePanelBusy = true;
- var params = {
- q: this.querySearchString,
- addressdetails: 1,
- extratags: 1,
- format: 'json'
- };
- axios.get('https://nominatim.openstreetmap.org/search', {
- params: params
- }).then(function (response) {
- console.log(response.data)
- that.querySearchResults = response.data;
- that.querySearchResults.forEach(function (d) {
- // icons
- d.icon = 'fa-address-card';
- if (d.type === 'fast_food' || d.type === 'restaurant') d.icon = 'fa-utensils';
- if (d.type === 'doctors') d.icon = 'fa-user-md';
- if (d.type === 'beach') d.icon = 'fa-umbrella-beach';
- if (d.type === 'dentist') d.icon = 'fa-tooth';
- if (d.type === 'car') d.icon = 'fa-car';
- if (d.type === 'playground') d.icon = 'fa-child';
- if (d.type === 'recreation_ground') d.icon = 'fa-running';
- if (d.type === 'sports_centre' || d.type === 'pitch') d.icon = 'fa-futbol';
- if (d.type === 'bicycle-rental') d.icon = 'fa-bicycle';
- if (d.type === 'school') d.icon = 'fa-graduation-cap';
- if (d.type === 'post_box' || d.type === 'post_office') d.icon = 'fa-envelope-square';
- if (d.type === 'canal' || d.type === 'river' || d.type === 'water') d.icon = 'fa-water';
- if (d.type === 'station' || d.type === 'stop' || d.type === 'bus_stop') d.icon = 'fa-subway';
- if (d.type === 'attraction') d.icon = 'fa-monument';
- if (d.type === 'city' || d.type === 'village' || d.type === 'town' || d.type === 'hamlet') d.icon = 'fa-city';
- if (d.type === 'administrative' || d.class === 'office') d.icon = 'fa-building';
- if (d.type === 'pub' || d.type === 'bar') d.icon = 'fa-beer';
- if (d.type === 'nightclub') d.icon = 'fa-glass-cheers';
- if (d.type === 'hotel' || d.type === 'hostel') d.icon = 'fa-bed';
- if (d.type === 'supermarket' || d.type === 'retail') d.icon = 'fa-shopping-cart';
- if (d.class === 'highway') d.icon = 'fa-road';
- });
- that.sidePanelBusy = false;
- that.addSearchMarker(that.querySearchResults);
- }).catch(function (error) {
- console.error(error);
- });
- }
- // searchPlaces: function () {
- // var that = this;
- // this.querySearchResults = [];
- // this.markerDetailsOpen = false;
- // this.sidePanelOpen = true;
- // this.sidePanelBusy = true;
- // var params = {
- // search: this.querySearchString,
- // lat: map.getCenter().lat,
- // lon: map.getCenter().lng
- // };
- // axios.get('/api/places', {
- // params: params
- // }).then(function (response) {
- // that.querySearchResults = response.data;
- // that.sidePanelBusy = false;
- // that.addSearchMarker(that.querySearchResults);
- // }).catch(function (error) {
- // console.error(error);
- // });
- // }
- },
- created: function () {
- var that = this;
- Vue.nextTick(function () {
- setupMap();
- document.getElementById('querySearchInput').focus();
- });
- }
- });
|