-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathdemo.js
More file actions
141 lines (116 loc) · 4.47 KB
/
demo.js
File metadata and controls
141 lines (116 loc) · 4.47 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
/**
* Example for Indoor Map for JSMapsApi.
*/
// Replace with your HERE platform app api key
const yourApikey = 'ZKBUeAgkzH4JWhg93AA7cIE_kZotbMGhVI0_UYC0COY';
// Replace with your indoor map platform collection hrn
const indoorMapHrn = 'hrn:here:data::org651595200:indoormap-ed6d5667-cfe0-4748-bbf5-88b00e7e3b21-collection';
// 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)
const venueId = 'indoormap-00000000-0000-4000-a000-000000027158';
/**
* Load and add indoor data on the map.
*
* @param {H.Map} map A HERE Map instance
*/
function addVenueToMap(map) {
// Get an instance of the Indoor Maps service using a valid apikey for Indoor Maps
const venuesService = platform.getVenuesService({ apikey: yourApikey, hrn: indoorMapHrn });
// Indoor Maps service provides a loadVenue method
venuesService.loadVenue(venueId).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
const venueLayer = new H.map.layer.TileLayer(venuesProvider);
map.addLayer(venueLayer);
// Set center of the map view to the center of the venue
map.setCenter(venue.getCenter());
// Create a level control
const levelControl = new H.venues.ui.LevelControl(venue);
ui.addControl('level-control', levelControl);
// Create a drawing control:
const drawingControl = new H.venues.ui.DrawingControl(venue);
ui.addControl('drawing-control', drawingControl);
// Enable to restrict map movement within indoor map bounds
restrictMap(map, venue);
// Rotate map
rotateMap(map, 90);
});
}
/**
* 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);
// Indoor Maps provider interacts with a tile layer to visualize and control the Indoor Map
const venuesProvider = new H.venues.Provider();
// Step 5: add the Indoor Map
addVenueToMap(map);
/**
* Rotate the map
*
* @param {H.Map} map A HERE Map instance within the application
* @param {number} angle in degrees
*/
function rotateMap(map, angle) {
map.getViewModel().setLookAtData({
tilt: 0,
heading: angle
});
}
/**
* Restricts a moveable map to a given rectangle.
*
* @param {H.Map} map A HERE Map instance within the application
*/
function restrictMap(map, venue) {
var bounds = venue.getBoundingBox(); // to get BBox for the indoor map
map.getViewModel().addEventListener('sync', function() {
var center = map.getCenter();
if (!bounds.containsPoint(center)) {
if (center.lat > bounds.getTop()) {
center.lat = bounds.getTop();
} else if (center.lat < bounds.getBottom()) {
center.lat = bounds.getBottom();
}
if (center.lng < bounds.getLeft()) {
center.lng = bounds.getLeft();
} else if (center.lng > bounds.getRight()) {
center.lng = bounds.getRight();
}
map.setCenter(center);
}
});
//Debug code to visualize where your restriction is
map.addObject(new H.map.Rect(bounds, {
style: {
fillColor: 'rgba(55, 85, 170, 0.1)',
strokeColor: 'rgba(55, 85, 170, 0.3)',
lineWidth: 2
}
}
));
}