Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <title>Get coordinates of the mouse pointer</title>
  6. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  7. <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.43.0/mapbox-gl.js'></script>
  8. <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.43.0/mapbox-gl.css' rel='stylesheet' />
  9. <style>
  10. body { margin:0; padding:0; }
  11. #map { position:absolute; top:0; bottom:0; width:100%; }
  12. </style>
  13. </head>
  14. <body>
  15.  
  16. <style type='text/css'>
  17. #info {
  18. display: block;
  19. position: relative;
  20. margin: 0px auto;
  21. width: 50%;
  22. padding: 10px;
  23. border: none;
  24. border-radius: 3px;
  25. font-size: 12px;
  26. text-align: center;
  27. color: #222;
  28. background: #fff;
  29. }
  30. </style>
  31. <div id='map'></div>
  32. <pre id='info'></pre>
  33. <script>
  34. mapboxgl.accessToken = 'pk.eyJ1Ijoia2FtZW1vcyIsImEiOiJjamJseHB4ZGIzNzV5MzNyNjJkanEzcjdlIn0.799r9GCkmUnwkw96jkeWWA';
  35. var map = new mapboxgl.Map({
  36. container: 'map', // container id
  37. style: 'mapbox://styles/mapbox/streets-v9',
  38. center: [-74.50, 40], // starting position
  39. zoom: 9 // starting zoom
  40. });
  41. var a;
  42. map.on('mousemove', function (e) {
  43. document.getElementById('info').innerHTML =
  44. // e.point is the x, y coordinates of the mousemove event relative
  45. // to the top-left corner of the map
  46. JSON.stringify(e.point) + '<br />' +
  47. // e.lngLat is the longitude, latitude geographical position of the event
  48. JSON.stringify(e.lngLat);
  49. console.log(e.lngLat);
  50. console.log(map.queryRenderedFeatures(e.point));
  51. });
  52. featureLayer.on('ready', function (e) {
  53. map.fitBounds(e.target.getBounds());
  54. e.target.eachLayer(function (layer) {
  55. // Do your thing
  56. console.log(layer);
  57. });
  58. });
  59. </script>
  60.  
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement