Skip to content

Commit 766d1ce

Browse files
committed
INDR-2054: added new indoor routing example to render routes on a indoor/venue map
1 parent 7d10366 commit 766d1ce

File tree

4 files changed

+250
-0
lines changed

4 files changed

+250
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#map {
2+
width: 95%;
3+
height: 450px;
4+
background: grey;
5+
}
6+
7+
#panel {
8+
width: 100%;
9+
height: 400px;
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Displaying an Indoor Map
3+
description: Use Here Indoor Maps service to load and visualize an indoor map
4+
resources:
5+
- https://heremaps.github.io/maps-api-for-javascript-examples/test-credentials.js
6+
normalize_css: no
7+
dtd: html 5
8+
wrap: d
9+
panel_html: 0
10+
panel_js: 0
11+
panel_css: 0
12+
...
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
5+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
6+
<meta name="description" content="Use the HERE Indoor Maps API to load and visualize an indoor map">
7+
<title>Indoor Map with Driving Route from A to B</title>
8+
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
9+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
10+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
11+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
12+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
13+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-venues.js"></script>
14+
<link rel="stylesheet" type="text/css" href="../template.css" />
15+
<link rel="stylesheet" type="text/css" href="demo.css" />
16+
<script type="text/javascript" src='../test-credentials.js'></script>
17+
<style type="text/css">
18+
.log {
19+
position: absolute;
20+
top: 5px;
21+
left: 5px;
22+
height: 150px;
23+
width: 250px;
24+
overflow: scroll;
25+
background: white;
26+
margin: 0;
27+
padding: 0;
28+
list-style: none;
29+
font-size: 12px;
30+
}
31+
.log-entry {
32+
padding: 5px;
33+
border-bottom: 1px solid #d0d9e9;
34+
}
35+
.log-entry:nth-child(odd) {
36+
background-color: #e1e7f1;
37+
}
38+
</style>
39+
</head>
40+
<body>
41+
<h1>Show an Indoor Map</h1>
42+
<p>
43+
The Indoor Maps module facilitates access to your private indoor maps including full JSON models. The HERE Indoor Maps API also provides information about indoor spaces, buildings, level geometry and points of interest.
44+
</p>
45+
46+
<p>
47+
More information on the use of the HERE Indoor Maps API is available <a href="https://www.here.com/docs/bundle/maps-api-for-javascript-developer-guide/page/topics/indoor-maps.html" target="_blank">here</a>.
48+
</p>
49+
50+
<p>
51+
This example shows an Indoor Map of the <b>Zurich Airport</b>.
52+
This example also works with Tiefgarage Riem Arcaden APCOA parking garage and Mall of Berlin
53+
</p>
54+
55+
<div id="map"></div>
56+
<h3>Code</h3>
57+
<p>
58+
The example shows loading the Indoor Map using <code>H.venues.Service2</code> and renders the indoor map using an instance of <code>H.venues.Provider</code>.<br>
59+
The example also shows how to:
60+
<ul>
61+
<li>get the list of indoor maps from the given HRN using <code>H.venues.Service2.getMapInfoList()</code></li>
62+
<li>disable the base map while loading a indoor map using <code>H.Map.setBaseLayer(layer)</code></li>
63+
<li>switch to an indoor map level other than the default using <code>H.venues.Venue.setActiveLevelIndex(levelIndex)</code></li>
64+
<li>override default indoor map label text preferences using <code>H.venues.Service2.LABEL_TEXT_PREFERENCE_OVERRIDE</code></li>
65+
</ul>
66+
</p>
67+
<p>
68+
For complete descriptions of the parameters shown in this example, see the <a href=https://www.here.com/docs/bundle/maps-api-for-javascript-api-reference/page/H.venues.html target="_blank">API Reference</a>.
69+
</p>
70+
<script type="text/javascript" src='demo.js'></script>
71+
</body>
72+
</html>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/**
2+
* Example for Indoor Map for JSMapsApi.
3+
*/
4+
5+
// Replace with your HERE platform app api key
6+
const yourApikey = 'ZKBUeAgkzH4JWhg93AA7cIE_kZotbMGhVI0_UYC0COY';
7+
8+
// Replace with your indoor map platform collection hrn
9+
const indoorMapHrn = 'hrn:here:data::org651595200:indoormap-ed6d5667-cfe0-4748-bbf5-88b00e7e3b21-collection';
10+
11+
const venuesProvider = null
12+
const venuesService = null
13+
// Specify the venue ID for your map. Examples of the map ID mentioned below.
14+
// For legacy maps, you can continue to use the numeric value.
15+
// Examples:
16+
// indoormap-00000000-0000-4000-a000-000000007348 for Zurich Airport (legacy id 7348)
17+
// indoormap-00000000-0000-4000-a000-000000027158 for Tiefgarage Riem Arcaden APCOA Parking garage (legacy id 27158)
18+
// indoormap-00000000-0000-4000-a000-000000022766 for Mall of Berlin (legacy id 22766)
19+
const venueId = 'indoormap-00000000-0000-4000-a000-000000007348';
20+
21+
// Set to false if base map is not needed to be displayed.
22+
const showBaseMap = true;
23+
24+
// Optional, list of label text preferences to override.
25+
const labelTextPreferenceOverride = [
26+
H.venues.Service2.LABEL_TEXT_PREFERENCE_OVERRIDE.OCCUPANT_NAMES,
27+
H.venues.Service2.LABEL_TEXT_PREFERENCE_OVERRIDE.SPACE_NAME
28+
]
29+
30+
/**
31+
* Load and add indoor data on the map.
32+
*
33+
* @param {H.Map} map A HERE Map instance
34+
* @param {H.service.Platform} platform A HERE Platform instance
35+
*/
36+
function addVenueToMap(map, platform) {
37+
// Indoor Maps provider interacts with a tile layer to visualize and control the Indoor Map
38+
venuesProvider = new H.venues.Provider();
39+
40+
// Get an instance of the Indoor Maps service using a valid apikey for Indoor Maps
41+
venuesService = platform.getVenuesService({ apikey: yourApikey, hrn: indoorMapHrn }, 2);
42+
43+
// Use venuesService.getMapInfoList to retrieve the list of Indoor maps from the given HRN
44+
venuesService.getMapInfoList().then(mapInfoList => {
45+
mapInfoList.forEach(mapInfo => {
46+
console.log("Indoor map id: " + mapInfo.mapId + ", map name: " + mapInfo.mapName);
47+
});
48+
});
49+
50+
// Indoor Maps service provides a loadVenue method. Optionally, overriding the label preferences
51+
venuesService.loadVenue(venueId, { labelTextPreferenceOverride }).then((venue) => {
52+
// add Indoor Maps data to the Indoor Maps provider
53+
venuesProvider.addVenue(venue);
54+
venuesProvider.setActiveVenue(venue);
55+
56+
// create a tile layer for the Indoor Maps provider
57+
const venueLayer = new H.map.layer.TileLayer(venuesProvider);
58+
if (showBaseMap) {
59+
// Add venueLayer to the base layer
60+
map.addLayer(venueLayer);
61+
} else {
62+
// If base map is not needed, set the venueLayer as base layer
63+
map.setBaseLayer(venueLayer);
64+
}
65+
66+
// Set center of the map view to the center of the venue
67+
map.setCenter(venue.getCenter());
68+
69+
// Create a level control
70+
const levelControl = new H.venues.ui.LevelControl(venue);
71+
ui.addControl('level-control', levelControl);
72+
73+
// Create a drawing control:
74+
const drawingControl = new H.venues.ui.DrawingControl(venue);
75+
ui.addControl('drawing-control', drawingControl);
76+
});
77+
}
78+
79+
/**
80+
* calculate route from a to b and load it on venue
81+
* @param {H.Map} map A HERE Map instance
82+
83+
* A full list of available request parameters can be found in the Indoor Routing API documentation.
84+
* see: https://www.here.com/docs/bundle/indoor-routing-api-v1-api-reference/page/index.html
85+
*/
86+
async function calculateIndoorRouteFromAtoB(map) {
87+
88+
// Instantiate (and display) a map:
89+
const origin = { lat: 47.45146718297871, lng: 8.56116163852909, levelId: "level-9050", venueId: "indoormap-00000000-0000-4000-a000-000000007348" };
90+
const destination = { lat: 47.45264049318705, lng: 8.562764022046945, levelId: "level-9050", venueId: "indoormap-00000000-0000-4000-a000-000000007348" };
91+
92+
// Create the parameters for the indoor routing request:
93+
const routingParameters = {
94+
routingMode: "fast",
95+
transportMode: "pedestrian",
96+
// The start point of the route:
97+
origin: `${origin.lat},${origin.lng},${origin.levelId},${origin.venueId}`,
98+
// The end point of the route:
99+
destination: `${destination.lat},${destination.lng},${destination.levelId},${destination.venueId}`,
100+
};
101+
try{
102+
const res = await venuesService.calculateRoute(routingParameters);
103+
if (res?.routes && res.routes.length > 0) {
104+
// Create route objects using route response data
105+
const route = new H.venues.Route2(res.routes[0]);
106+
// Link route map objects with venue levels for automatic visibility updates:
107+
const indoorObjects = route.getIndoorObjects();
108+
109+
for (let venueId in indoorObjects) {
110+
for (let levelIndex in indoorObjects[venueId]) {
111+
const venue = venuesProvider.getVenue(venueId);
112+
const objectGroup = indoorObjects[venueId][levelIndex];
113+
map.addObject(objectGroup);
114+
venue.setMapObjects(objectGroup.getObjects(), levelIndex);
115+
}
116+
}
117+
}
118+
}catch(error){
119+
console.log(error.message)
120+
}
121+
}
122+
123+
/**
124+
* Boilerplate map initialization code starts below:
125+
*/
126+
127+
// Step 1: initialize communication with the platform
128+
// In your own code, replace variable window.apikey with your own apikey
129+
var platform = new H.service.Platform({
130+
apikey: yourApikey
131+
});
132+
var defaultLayers = platform.createDefaultLayers();
133+
134+
// Step 2: initialize a map
135+
var map = new H.Map(document.getElementById('map'), defaultLayers.vector.normal.map, {
136+
zoom: 18,
137+
center: { lat: 47.452353, lng: 8.562455 },
138+
pixelRatio: window.devicePixelRatio || 1
139+
});
140+
141+
// add a resize listener to make sure that the map occupies the whole container
142+
window.addEventListener('resize', () => map.getViewPort().resize());
143+
144+
// Step 3: make the map interactive
145+
// MapEvents enables the event system
146+
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
147+
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
148+
149+
// Step 4: create the default UI component, for displaying bubbles
150+
var ui = H.ui.UI.createDefault(map, defaultLayers);
151+
152+
// Step 5: add the Indoor Map
153+
addVenueToMap(map, platform);
154+
155+
// Step 6: add route to indoor map
156+
calculateIndoorRouteFromAtoB(map)

0 commit comments

Comments
 (0)