wrld.js

Placing objects on buildings

Query the altitude of a building in order to position a marker.

<!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.795641, -122.404173],
            zoom: 18
        });

        var locations = [   [37.795159, -122.404336],
                            [37.795173, -122.404229]];

        function onInitialStreamingComplete() {
            addMarkerAboveBuilding(L.latLng(locations[0]), "Point A");
            addMarkerAboveBuilding(L.latLng(locations[1]), "Point B");
        };

        function addMarkerAboveBuilding(location, title) {
            var intersection = map.buildings.findBuildingAtLatLng(location);
            if (intersection.found) {
                L.marker(location, {
                        elevation: intersection.point.alt,
                        title: title
                   }).addTo(map);
            }
        };

        map.on("initialstreamingcomplete", onInitialStreamingComplete);
    </script>
  </div>
  </body>
</html>
v0.1.1452