Code examples

Inventory of spaces and assets

In this demo we generate a html table from querying spaces and assets from a floor

Loading space data

const url = `https://api.archilogic.com/v1/space/?floorId=${floorId}&token=${token}`
const geoJson = await fetch(url).then((res) => res.json())

By iterating through the resources we can collect the information for each space.
Of main interest are the properties section of the Space object and the resource relations to count the assets in the space. To group spaces of the same type you can group them by the usage or program.

geoJson.features.forEach(ft => {
  const spaceData = ft.properties
  const { usage, program } = spaceData
  const assetCount = ft.resourceRelations?.assets?.length || 0
})

Loading asset data

The same way we get the information on all assets in the floor

const url = `https://api.archilogic.com/v1/asset/?floorId=${floorId}&token=${token}`
const geoJson = await fetch(url).then((res) => res.json())

The properties section of the Asset object contains the name, manufacturer, categories and dimensions of the asset. To group asset of the same type group them via the productId.

geoJson.features.forEach(ft => {
  const assetData = ft.properties
  const productId = assetData.productId
})

Demo with code

Open in codesandbox Embedded iframe below:

Draw geo-referenced floor plan on a map

In this demo we use Leaflet.js to draw a floor plan and outlines of spaces in GeoJSON format on the map that were loaded from the REST API.

If a plan is not geo-referenced its origin will be latitude, longitude: 0, 0.

Load the SVG

POST request to load the geo-referenced svg floor plan

const url = `https://api.archilogic.com/v1/floor/${floorId}/2d-image?token=${token}`
const { imageUrl, latLngBounds } = await fetch(url, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' }
}).then((res) => res.json())

Leaflet.js can directly use those values to draw the floor plan svg on the map

L.imageOverlay(imageUrl, latLngBounds).addTo(map)
// zoom to the floor plan
map.fitBounds(latLngBounds)

Load the geoJSON geometry

GET request to load the contours of the spaces by querying via floorId this gives us the resource data in GeoJSON format

const url = `https://api.archilogic.com/v1/space?floorId=${floorId}&token=${token}`
const geoJson = await fetch(url).then((res) => res.json())

Leaflet.js allows you to draw that directly on the map

L.geoJSON(geoJson, options).addTo(map)

Demo with code

Open in codesandbox Screenshot below: