wrld.js

Convert coordinates from layer point to a latLng

Click on map to view the pixel position in the map layer and to convert it to a latlng.

<!DOCTYPE HTML>
<html>
  <head>
    <script src="https://cdn-webgl.wrld3d.com/wrldjs/dist/latest/wrld.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet.css" rel="stylesheet" />
  </head>
  
  <body>
  <div style="position: relative">
    <div id="map" style="height: 400px"></div>
    <script>
      var map = L.Wrld.map("map", "your_api_key_here", {
        center: [37.7858, -122.401],
        zoom: 15,
        indoorsEnabled: true,
        displayEntranceMarkers: false
      });
      map.on("click", function(e) {
        pixelPosition = e.layerPoint;
        latLng = map.layerPointToLatLng(pixelPosition);
        alert("Pixel position = "+pixelPosition + "\nLatLng = "+latLng);
      });
    </script>
  </div>
  </body>
</html>
v0.1.1452