From 872cea51a26408f52defe4f8a29beeea2e156045 Mon Sep 17 00:00:00 2001 From: Bharata Srinivasa Date: Wed, 20 Jul 2016 18:21:47 +0530 Subject: [PATCH] Added popup on click feature Removed direction api --- index.html | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 00e90f9..e95dd99 100644 --- a/index.html +++ b/index.html @@ -31,18 +31,27 @@ hash: true }) +map.on('click', function(e) { + var features = map.queryRenderedFeatures(e.point, { filter: ["has", "name"]}); + if (features.length) { + var feature = features[0]; + new mapboxgl.Popup({ closeOnClick: true }) + .setLngLat(e.lngLat) + .setHTML('

' + feature.properties.name + '

') + .addTo(map); + } +}); + var popup = new mapboxgl.Popup({closeOnClick: false}) - .setLngLat([76.94,13.32]) - .setHTML('

Welcome to Gubbi!

Close this message to continue.

') - .addTo(map); + .setLngLat([76.94, 13.32]) + .setHTML('

Welcome to Gubbi!

Close this message to continue.

') + .addTo(map); map.addControl(new mapboxgl.Geocoder()); -map.addControl(new mapboxgl.Directions()); +// map.addControl(new mapboxgl.Directions()); map.addControl(new mapboxgl.Geolocate({ position: 'bottom-right'})); map.addControl(new mapboxgl.Navigation({ position: 'top-right' })); - -