Explorar o código

Use nominatim directly

Johannes Zellner %!s(int64=6) %!d(string=hai) anos
pai
achega
1929e90cf0
Modificáronse 3 ficheiros con 108 adicións e 39 borrados
  1. 27 2
      public/index.css
  2. 9 3
      public/index.html
  3. 72 34
      public/index.js

+ 27 - 2
public/index.css

@@ -96,7 +96,7 @@ html, body {
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
-    padding: 5px 10px;
+    padding: 10px;
 }
 
 .query-search-result-item:hover {
@@ -244,4 +244,29 @@ html, body {
 .overpass-layer-icon {
     font-size: 14px !important;
     color: #6d6d6d;
-}
+}
+
+.context-menu {
+    position: absolute;
+    z-index: 1000;
+    visibility: hidden;
+    background: white;
+    box-shadow: 0 2px 3px rgba(0,0,0,0.06);
+    border-radius: 2px;
+    border: solid white 0px;
+    padding: 4px 0;
+}
+
+.context-menu.visible {
+    visibility: visible;
+}
+
+.context-menu > .menu-item {
+    padding: 5px 10px;
+    cursor: pointer;
+}
+
+.context-menu > .menu-item:hover {
+    background-color: #1e88e4;
+    color: white;
+}

+ 9 - 3
public/index.html

@@ -28,6 +28,14 @@
 
 <div id="app">
   <div id="map" class="map"></div>
+
+  <div class="context-menu" id="contextMenu">
+    <div class="menu-item" onclick="getWhatsThere()">Whats there?</div>
+    <div class="menu-item" onclick="getWhatsThere()">Item 1</div>
+    <div class="menu-item" onclick="getWhatsThere()">Item 2</div>
+    <div class="menu-item" onclick="getWhatsThere()">Item 3</div>
+  </div>
+
   <div class="side-panel map-overlay" :class="{ 'open': sidePanelOpen }">
     <div class="query-search-input-placeholder">
       <el-tooltip class="item" effect="dark" content="Close" placement="bottom-start">
@@ -38,9 +46,7 @@
       <div class="query-search-result-container-inner">
         <div v-show="sidePanelBusy" style="text-align: center; margin-top: 50px;"><i class="fas fa-3x fa-circle-notch fa-spin"></i></div>
         <div v-for="item in querySearchResults" class="query-search-result-item" @click="activateSearchItem(item)">
-          <h4><i class="fas" :class="[ item.icon ]"></i> {{ item.name }}</h4>
-          <p v-if="item.class === 'city'">{{ item.address.postcode }} {{ item.address.country }}</p>
-          <p v-else>{{ item.address.road || item.address.pedestrian }} {{ item.address.house_number }}, {{ item.address.city || item.address.town || item.address.village }} ({{ item.address.city_district }} {{ item.address.postcode }} {{ item.address.country }})</p>
+          <i class="fas" :class="[ item.icon ]"></i> {{ item.display_name }}
         </div>
       </div>
     </div>

+ 72 - 34
public/index.js

@@ -149,34 +149,19 @@ function setupMap() {
         else map.addLayer(placesMarkerLayer);
     });
 
-    // var mapillaryKey = 'SmRiZXFSN3RJYVpKdGd2V3BQZ0dMdzoxZjY3YjA3MmU2OWU2ODll';
-    // map.on('contextmenu ', function (event) {
-    //     console.log(event);
-
-    //     var popup = L.popup({ closeButton: false })
-    //         .setLatLng(event.latlng)
-    //         .setContent('<p>Loading address</p>')
-    //         .openOn(map);
-
-    //     var params = {
-    //         client_id: mapillaryKey,
-    //         closeto: event.latlng.lng + ',' + event.latlng.lat,
-    //         pano: false
-    //     };
-
-    //     axios.get('https://a.mapillary.com/v3/images', {
-    //         params: params
-    //     }).then(function (response) {
-    //         // console.log(response.data);
-    //         if (response.data.features.length === 0) {
-    //             popup.setContent('<p>Nothing found</p>');
-    //         } else {
-    //             popup.setContent('<div class="whats-here" style="background-image: url(https://d1cuyjsrcm0gby.cloudfront.net/' + response.data.features[0].properties.key + '/thumb-640.jpg"></div>');
-    //         }
-    //     }).catch(function (error) {
-    //         console.error(error);
-    //     });
-    // });
+    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) {
@@ -217,7 +202,7 @@ app = new Vue({
             var that = this;
 
             var params = {
-                name: item.name,
+                name: item.display_name,
                 lat: item.lat,
                 lon: item.lon,
                 class: item.class
@@ -246,7 +231,7 @@ app = new Vue({
                     icon: DEFAULT_MARKER_ICON,
                     opacity: 0.5
                 });
-                m.bindTooltip(item.name, { direction: 'bottom' });
+                m.bindTooltip(item.display_name, { direction: 'bottom' });
                 m.on('click', function (e) {
                     that.openPlaceDetails(item);
                     that.activateSearchMarker(item);
@@ -286,15 +271,43 @@ app = new Vue({
             this.sidePanelBusy = true;
 
             var params = {
-                search: this.querySearchString,
-                lat: map.getCenter().lat,
-                lon: map.getCenter().lng
+                q: this.querySearchString,
+                addressdetails: 1,
+                extratags: 1,
+                format: 'json'
             };
 
-            axios.get('/api/places', {
+            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);
@@ -302,6 +315,31 @@ app = new Vue({
                 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;