1document.addEventListener('DOMContentLoaded', function () { 2 // Define the map container element 3 const mapContainers = document.querySelectorAll('.drive-pilot-map-container'); 4 const maps = []; 5 6 const renderDrivePilotMap = function(mapContainer) { 7 const mapAttributes = mapContainer ? mapContainer.attributes : []; 8 const attributes = {}; 9 10 for (var i = 0; i < mapAttributes.length; i++) { 11 const { name, value } = mapAttributes[i]; 12 attributes[name] = value; 13 } 14 15 if (Object.keys(attributes).length === 0) { 16 return false; 17 } 18 19 // Replace YOUR_API_KEY with your actual API key from HERE - create and add your own apiKey from platform 20 const apiKey = attributes['data-apikey']; 21 22 // Initialize the platform object with the API key 23 const platform = new H.service.Platform({ 24 apikey: apiKey 25 }); 26 27 // Create a default layers object for the map 28 const defaultLayers = platform.createDefaultLayers(); 29 30 // Create the map object using the container element and default layers 31 const map = new H.Map( 32 mapContainer, 33 defaultLayers.vector.normal.map, 34 { 35 zoom: attributes['data-zoom'], 36 center: { 37 lat: attributes['data-centerlatitude'], 38 lng: attributes['data-centerlongitude'] 39 } 40 } 41 ); 42 43 // Enable the default UI components for the map 44 const ui = H.ui.UI.createDefault(map, defaultLayers); 45 46 var myMapSettingsControl = new H.ui.MapSettingsControl({ 47 alignment: "right-bottom", 48 baseLayers: [ 49 {label: "Vector", layer: defaultLayers.vector.normal.map}, 50 {label: "Normal", layer: defaultLayers.raster.normal.map}, // another view, remove line if you do not like this view 51 {label: "Satellite", layer: defaultLayers.raster.satellite.map}, 52 ] 53 }); 54 55 ui.removeControl('mapsettings'); 56 const scalebarControl = ui.removeControl('scalebar'); 57 const zoomControl = ui.removeControl('zoom'); 58 ui.addControl('mapsettings', myMapSettingsControl); 59 ui.addControl('zoom', zoomControl); 60 ui.addControl('scalebar', scalebarControl); 61 62 // Enable behavior for map zooming and panning 63 const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map)); 64 65 const geoJsonFile = attributes['data-geojsonpath'] 66 67 var reader = new H.data.geojson.Reader(geoJsonFile, { 68 // This function is called each time parser detects a new map object 69 style: function (mapObject) { 70 // Parsed geo objects could be styled using setStyle method 71 if (mapObject instanceof H.map.Polyline) { 72 mapObject.setStyle({ 73 strokeColor: attributes['data-drivepilotroute'], 74 lineWidth: attributes['data-linewidth'] 75 }); 76 } 77 }, 78 disableLegacyMode: true 79 }); 80 81 // Start parsing the file 82 reader.parse(); 83 84 // Add layer which shows GeoJSON data on the map 85 map.addLayer(reader.getLayer()); 86 maps.push(map); 87 }; 88 89 mapContainers.forEach(function(item) { 90 renderDrivePilotMap(item); 91 }); 92 93 window.addEventListener('resize', function () { 94 maps.forEach(map => { 95 map.getViewPort().resize(); 96 }); 97 }); 98}); 99 100
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.