-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathdemo.js
More file actions
147 lines (123 loc) · 5.67 KB
/
demo.js
File metadata and controls
147 lines (123 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Example for Indoor Map for JSMapsApi.
*/
// Replace with your indoor map platform collection hrn
var indoorMapHrn = 'hrn:here:data::org651595200:indoormap-ed6d5667-cfe0-4748-bbf5-88b00e7e3b21-collection';
var venuesProvider = null
var venuesService = null
// Specify the venue ID for your map. Examples of the map ID mentioned below.
// For legacy maps, you can continue to use the numeric value.
// Examples:
// indoormap-00000000-0000-4000-a000-000000007348 for Zurich Airport (legacy id 7348)
// indoormap-00000000-0000-4000-a000-000000027158 for Tiefgarage Riem Arcaden APCOA Parking garage (legacy id 27158)
// indoormap-00000000-0000-4000-a000-000000022766 for Mall of Berlin (legacy id 22766)
var venueId = 'indoormap-00000000-0000-4000-a000-000000022766';
// Set to false if base map is not needed to be displayed.
var showBaseMap = true;
// Optional, list of label text preferences to override.
var labelTextPreferenceOverride = [
H.venues.Service.LABEL_TEXT_PREFERENCE_OVERRIDE.OCCUPANT_NAMES,
H.venues.Service.LABEL_TEXT_PREFERENCE_OVERRIDE.SPACE_NAME
]
/**
* Load and add indoor data on the map.
*
* @param {H.Map} map A HERE Map instance
* @param {H.service.Platform} platform A HERE Platform instance
*/
function addVenueToMap(map, platform) {
// Indoor Maps provider interacts with a tile layer to visualize and control the Indoor Map
venuesProvider = new H.venues.Provider();
// Get an instance of the Indoor Maps service using a valid apikey for Indoor Maps
// In your own code, replace variable "yourToken" with your own token to access indoor routing.
venuesService = platform.getVenuesService({ token: "yourToken", hrn: indoorMapHrn });
// Indoor Maps service provides a loadVenue method. Optionally, overriding the label preferences
venuesService.loadVenue(venueId, { labelTextPreferenceOverride }).then((venue) => {
// add Indoor Maps data to the Indoor Maps provider
venuesProvider.addVenue(venue);
venuesProvider.setActiveVenue(venue);
// create a tile layer for the Indoor Maps provider
var venueLayer = new H.map.layer.TileLayer(venuesProvider);
if (showBaseMap) {
// Add venueLayer to the base layer
map.addLayer(venueLayer);
} else {
// If base map is not needed, set the venueLayer as base layer
map.setBaseLayer(venueLayer);
}
// Set center of the map view to the center of the venue
map.setCenter(venue.getCenter());
// Create a level control
var levelControl = new H.venues.ui.LevelControl(venue);
ui.addControl('level-control', levelControl);
// Create a drawing control:
var drawingControl = new H.venues.ui.DrawingControl(venue);
ui.addControl('drawing-control', drawingControl);
});
}
/**
* calculate route from a to b and load it on venue
* @param {H.Map} map A HERE Map instance
* A full list of available request parameters can be found in the Indoor Routing API documentation.
* see: https://www.here.com/docs/bundle/indoor-routing-api-v1-api-reference/page/index.html
*/
async function calculateIndoorRouteFromAtoB(map) {
// Instantiate (and display) a map:
var origin = { lat: 47.45146718297871, lng: 8.56116163852909, levelId: "level-9050", venueId: "indoormap-00000000-0000-4000-a000-000000007348" };
var destination = { lat: 47.45264049318705, lng: 8.562764022046945, levelId: "level-9050", venueId: "indoormap-00000000-0000-4000-a000-000000007348" };
// Create the parameters for the indoor routing request:
var routingParameters = {
routingMode: "fast",
transportMode: "pedestrian",
// The start point of the route:
origin: `${origin.lat},${origin.lng},${origin.levelId},${origin.venueId}`,
// The end point of the route:
destination: `${destination.lat},${destination.lng},${destination.levelId},${destination.venueId}`,
};
try{
var res = await venuesService.calculateRoute(routingParameters);
if (res?.routes && res.routes.length > 0) {
// Create route objects using route response data
var route = new H.venues.Route(res.routes[0]);
// Link route map objects with venue levels for automatic visibility updates:
var indoorObjects = route.getIndoorObjects();
for (let venueId in indoorObjects) {
for (let levelIndex in indoorObjects[venueId]) {
var venue = venuesProvider.getVenue(venueId);
var objectGroup = indoorObjects[venueId][levelIndex];
map.addObject(objectGroup);
venue.setMapObjects(objectGroup.getObjects(), levelIndex);
}
}
}
}catch(error){
console.log(error.message)
}
}
/**
* Boilerplate map initialization code starts below:
*/
// Step 1: initialize communication with the platform
// In your own code, replace variable window.apikey with your own apikey
var platform = new H.service.Platform({
apikey: window.apikey
});
var defaultLayers = platform.createDefaultLayers();
// Step 2: initialize a map
var map = new H.Map(document.getElementById('map'), defaultLayers.vector.normal.map, {
zoom: 18,
center: { lat: 47.452353, lng: 8.562455 },
pixelRatio: window.devicePixelRatio || 1
});
// add a resize listener to make sure that the map occupies the whole container
window.addEventListener('resize', () => map.getViewPort().resize());
// Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
// Step 4: create the default UI component, for displaying bubbles
var ui = H.ui.UI.createDefault(map, defaultLayers);
// Step 5: add the Indoor Map
addVenueToMap(map, platform);
// Step 6: add route to indoor map
calculateIndoorRouteFromAtoB(map)