Skip to content

Commit b9e8e0e

Browse files
authored
Merge pull request #107 from heremaps/heremaps/venue-routing
New indoor routing in a venue example
2 parents 3003674 + 402627b commit b9e8e0e

File tree

6 files changed

+176
-1
lines changed

6 files changed

+176
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All of the following examples use **version 3.1** of the API
2222
* [Display KML Data](https://heremaps.github.io/maps-api-for-javascript-examples/display-kml-on-map/demo.html) - Parse a KML file and display the data on a map
2323
* [Display GeoJSON Data](https://heremaps.github.io/maps-api-for-javascript-examples/display-geojson-on-map/demo.html) - Parse a GeoJSON file and display the data on a map
2424
* [Display Venues Data](https://heremaps.github.io/maps-api-for-javascript-examples/venues-on-map/demo.html) - Display Here Venues on a map
25+
* [Display Indoor Routing in Venue](https://heremaps.github.io/maps-api-for-javascript-examples/venues-routing/demo.html) - Add routing to Venue
2526
* [Draggable Marker](https://heremaps.github.io/maps-api-for-javascript-examples/draggable-marker/demo.html) - Display a moveable marker on a map
2627
* [Draggable geo shapes](https://heremaps.github.io/maps-api-for-javascript-examples/draggable-shapes/demo.html) - Display moveable geometric shapes on a map
2728
* [Extruded geo shapes](https://heremaps.github.io/maps-api-for-javascript-examples/extruded-objects/demo.html) - 3D extrusion of the geometric shapes
@@ -63,4 +64,3 @@ All of the following examples use **version 3.1** of the API
6364
* [Truck routing road restrictions](https://heremaps.github.io/maps-api-for-javascript-examples/truck-routing-road-restrictions/demo.html) Show a various truck routes with the truck related road restrictions highlighted on the map
6465
* [Zoom into Bounds](https://heremaps.github.io/maps-api-for-javascript-examples/custom-zooming-into-bounds/demo.html) - Zoom into bounds limiting maximum level
6566
* [Zooming to a Set of Markers](https://heremaps.github.io/maps-api-for-javascript-examples/zoom-to-set-of-markers/demo.html) - Alter the viewport to ensure a group of objects are visible
66-

meta.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@
113113
"shortDescription": "Use Here Venues services to load and visualize an indoor data",
114114
"published": true
115115
},
116+
{
117+
"uid": "venues-routing",
118+
"title": "Add routing to Venue",
119+
"shortDescription": "Use Here Venues services to visualize floor plans and route data between indoor spaces",
120+
"published": true
121+
},
116122
{
117123
"uid": "transit-mapsjs-iml",
118124
"title": "Interactive Map Layer",

venues-routing/demo.css

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+
}

venues-routing/demo.details

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Routing inside a Venues map
3+
description: Use Here Venues services to load a map a calculate a route between indoor spaces
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+
...

venues-routing/demo.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 Here Venues API ot load and visualize data on the map">
7+
<title>Add Indoor Routing to Venue</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+
</head>
18+
<body>
19+
<h1>Render a route inside a venue map</h1>
20+
<p>
21+
Using the Venues module facilitates access to provided indoor maps including full JSON models and routing between
22+
indoor points. The Venues APIs also provides information about indoor spaces, buildings, level geometry and points
23+
of interest.
24+
</p>
25+
26+
<p>
27+
More information about the use of Venues API can be found <a href="https://developer.here.com/documentation/maps/dev_guide/topics/venues.html" target="_blank">here</a>.
28+
</p>
29+
30+
<p>
31+
This example shows a map of <b>Zurich Airport</b> and a route between 2 points within the venue, one inside the building, the other outside.
32+
</p>
33+
34+
<div id="map">
35+
<!-- Map -->
36+
</div>
37+
38+
<h3>Code</h3>
39+
<p>
40+
The example shows loading of an indoor map and route calculation using <code>H.venues.Service</code>, then rendering the map
41+
with the use of <code>H.venues.Provider</code>.
42+
</p>
43+
<script type="text/javascript" src='demo.js'></script>
44+
</body>
45+
</html>

venues-routing/demo.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Load and add venue data on the map.
3+
*
4+
* @param {H.Map} map A HERE Map instance
5+
*/
6+
function addVenueToMap(map) {
7+
// Venues service provides a loadVenue method
8+
venuesService.loadVenue(7348).then((venue) => {
9+
// add venue data to venues provider
10+
venuesProvider.addVenue(venue);
11+
venuesProvider.setActiveVenue(venue);
12+
13+
// create a tile layer for the venues provider
14+
map.addLayer(new H.map.layer.TileLayer(venuesProvider));
15+
16+
// optionally select a different drawing/level
17+
venue.setActiveDrawing(7880);
18+
19+
// create level control
20+
const levelControl = new H.venues.ui.LevelControl(venue);
21+
ui.addControl('level-control', levelControl);
22+
23+
// create drawing control:
24+
const drawingControl = new H.venues.ui.DrawingControl(venue);
25+
ui.addControl('drawing-control', drawingControl);
26+
});
27+
}
28+
29+
/**
30+
* Calculate a route and add result to map.
31+
*
32+
* @param {H.map} map
33+
*/
34+
function addRouteToMap(map) {
35+
venuesService.calculateRoute({
36+
origin: { coordinates: [47.450022, 8.563396]},
37+
destination: { coordinates: [47.451259,8.560136], venueId: 7348, levelId: 9049 },
38+
transportMode: 'pedestrian',
39+
avoid: { features: 'elevator' }
40+
}).then((result) => {
41+
// Get objects for the calculated route
42+
const route = new H.venues.Route(result.routes[0]);
43+
44+
const indoorObjects = route.getIndoorObjects();
45+
// Link route map objects with venue levels for automatic visibility updates:
46+
for (let venueId in indoorObjects) {
47+
for (let levelIndex in indoorObjects[venueId]) {
48+
const venue = venuesProvider.getVenue(venueId);
49+
const objectGroup = indoorObjects[venueId][levelIndex];
50+
map.addObject(objectGroup);
51+
venue.setMapObjects(objectGroup.getObjects(), levelIndex);
52+
}
53+
}
54+
// Get H.map.Group that contains map objects representing outdoor segments:
55+
const outdoorObjects = route.getOutdoorObjects();
56+
map.addObject(outdoorObjects);
57+
});
58+
}
59+
60+
/**
61+
* Boilerplate map initialization code starts below:
62+
*/
63+
64+
// Step 1: initialize communication with the platform
65+
// In your own code, replace variable window.apikey with your own apikey
66+
var platform = new H.service.Platform({
67+
apikey: window.apikey
68+
});
69+
var defaultLayers = platform.createDefaultLayers();
70+
71+
// Step 2: initialize a map
72+
var map = new H.Map(document.getElementById('map'), defaultLayers.vector.normal.map, {
73+
zoom: 16,
74+
center: { lat: 47.452353, lng: 8.562455 },
75+
pixelRatio: window.devicePixelRatio || 1
76+
});
77+
78+
// add a resize listener to make sure that the map occupies the whole container
79+
window.addEventListener('resize', () => map.getViewPort().resize());
80+
81+
// Step 3: make the map interactive
82+
// MapEvents enables the event system
83+
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
84+
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
85+
86+
// Step 4: create the default UI component, for displaying bubbles
87+
var ui = H.ui.UI.createDefault(map, defaultLayers);
88+
89+
90+
// Step 5: load venue data
91+
92+
// Get instance of venues service using valid apikey for venues
93+
var venuesService = platform.getVenuesService({ apikey: 'L7yi9YzsZUJMSMavFOYIL7yqWoUcTicYqYNxMOkox84' });
94+
95+
// Venues provider interacts with tile layer to visualize and control the venue map
96+
var venuesProvider = new H.venues.Provider();
97+
98+
// Load venue
99+
addVenueToMap(map);
100+
101+
// Step 6: calculate a route
102+
addRouteToMap(map);

0 commit comments

Comments
 (0)