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