Displaying the name of an indoor map
Show the name of an indoor map in a Leaflet popup. Click one of the blue markers to enter an indoor map. Close the popup bubble to exit the building.
<!DOCTYPE HTML>
<html>
<head>
<script src="https://unpkg.com/wrld.js@1.x.x"></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 = Wrld.map("map", "your_api_key_here", {
center: [37.782014, -122.404748],
zoom: 17,
indoorsEnabled: true
});
function onIndoorMapEntered(event) {
var latLng = map.getCenter();
var indoorMapId = event.indoorMap.getIndoorMapId();
var buildingName = event.indoorMap.getIndoorMapName();
var popupOptions = {
indoorMapId: indoorMapId,
indoorMapFloorIndex: 0,
autoClose: false,
closeOnClick: false
};
var popup = Wrld.popup(popupOptions)
.setLatLng(latLng)
.addTo(map)
.setContent(buildingName);
map.on("popupclose", function() { map.indoors.exit(); });
}
map.indoors.on("indoormapenter", onIndoorMapEntered);
</script>
</div>
</body>
</html>