Listing Buildings and Floors

This sample shows how to get detailed information about a venue, including its buildings and floors. These commands can be used in normal or headless mode.

Organizing your code

The Getting Started section details various SDK installation options depending on your requirements. The sample code below is based on a base use case of a plain html page and the ES6 module format.

Getting data

The code below shows how to get info like the venue name, latest map version as well as info on the different floors and buildings in the venue:

<!DOCTYPE html>
<html lang="en">

	<head>
		<script type="module">

			import LMInit from 'https://maps.locuslabs.com/sdk/LocusMapsSDK.js'

			const config = {
				venueId: 'lax',
				accountId: 'A11F4Y6SZRXH4X',
				headless: true
			}

			window.LMInit = LMInit
			LMInit.setLogging(true)
			LMInit.newMap(null, config)
				.then(m => { 
        		
        			window.map = m;

        			m.getVenueData().then(venueData => {
					
						console.log("Venue name", venueData.name)
						console.log("Venue/map version:", venueData.venueList["lax"].assetVersion);
						// Many more properties are available - inspect the "venueData" object for more info
					});

					m.getStructures().then(structures => {
					
						for (var structure of structures) {
							
							const buildingDesc = "Building name: " + structure.name + " ID: " +structure.id;
							console.log(buildingDesc);
							
							const levels = structure.levels;
							Object.keys(levels).forEach(function(key) {
								
								const level = levels[key];
   							 	const levelDesc = "Level name: " +level.name +" (" +level.details +")" +" ID: "+level.id +" Ordinal: " +level.ordinal;
   							 	console.log(levelDesc);
							});
						}
					});
        		 })
				.catch(e => console.error('Error initializing map: ', e))

		</script>
	</head>
</html>

Try it out

See a live preview (inspect the logs) or visit the fiddle.

Below is an extract of the data that will be returned in the console If you run the code above:

Building name: East Campus ID: lax-east
Level name: Ground (Ground Transportation / Parking) ID: lax-east-ground Ordinal: 3 

Building name: Regional Terminal ID: lax-regional
Level name: Level 2 (Departures) ID: lax-regional-departures Ordinal: 2 

Building name: Terminals 4-8 ID: lax-south
Level name: Level 5 (Connector) ID: lax-south-5 Ordinal: 5
Level name: Level 1 (Baggage Claim) ID: lax-south-baggageclaim Ordinal: 1
Level name: Level 3 (Departures) ID: lax-south-departures Ordinal: 3
Level name: Level 4 (Lounges / Restaurants) ID: lax-south-lounges Ordinal: 4
Level name: Level 2 (Ticketing / Check in) ID: lax-south-ticketing Ordinal: 2

πŸ“˜

Other Venue Data

Use the "getVenueData" command to obtain more meta info about the venue as a whole, including things like address, gps location, defaults, category etc.