-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
96 lines (83 loc) · 2.8 KB
/
app.js
File metadata and controls
96 lines (83 loc) · 2.8 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
import {Deck} from '@deck.gl/core';
import {GeoJsonLayer, ArcLayer} from '@deck.gl/layers';
import "@here/maps-api-for-javascript/bin/mapsjs.bundle.harp.js";
// Common
const lookAtData = {
latitude: 51.47,
longitude: 0.45,
zoom: 3,
// bearing: 0,
pitch: 45
};
/** ************************************************ HERE Maps API for JavaScript ************************************************ */
function updateMapCamera(map, lookAtData) {
map.getViewModel().setLookAtData({
position: {lat: lookAtData.latitude, lng: lookAtData.longitude},
zoom: lookAtData.zoom + 1,
heading: lookAtData.bearing - 180,
tilt: lookAtData.pitch
})
}
const apikey = 'YOUR_API_KEY';
const engineType = H.map.render.RenderEngine.EngineType.HARP;
const pixelRatio = window.devicePixelRatio || 1;
const center = {lat: lookAtData.latitude, lng: lookAtData.longitude};
const zoom = lookAtData.zoom;
const platform = new H.service.Platform({ apikey });
const maptypes = platform.createDefaultLayers({
tileSize: pixelRatio === 1 ? 256 : 512,
ppi: pixelRatio === 1 ? undefined : 320,
engineType
});
const map = new H.Map(
document.getElementById('container'),
maptypes.vector.normal.mapnight,
{
zoom,
center,
engineType,
pixelRatio
}
);
new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
window.addEventListener('resize', () => map.getViewPort().resize());
/** ************************************************ DECK.GL ************************************************ */
// source: Natural Earth http://www.naturalearthdata.com/ via geojson.xyz
const AIR_PORTS =
'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson';
export const deck = new Deck({
initialViewState: lookAtData,
controller: true,
// Synchronize both cameras
onViewStateChange: ({viewState}) => updateMapCamera(map, viewState),
onResize: ({width, height}) => map.getViewPort().resize(),
layers: [
new GeoJsonLayer({
id: 'airports',
data: AIR_PORTS,
// Styles
filled: true,
pointRadiusMinPixels: 2,
pointRadiusScale: 2000,
getPointRadius: f => 11 - f.properties.scalerank,
getFillColor: [200, 0, 80, 180],
// Interactive props
pickable: true,
autoHighlight: true,
onClick: info =>
// eslint-disable-next-line
info.object && alert(`${info.object.properties.name} (${info.object.properties.abbrev})`)
}),
new ArcLayer({
id: 'arcs',
data: AIR_PORTS,
dataTransform: d => d.features.filter(f => f.properties.scalerank < 4),
// Styles
getSourcePosition: f => [-0.4531566, 51.4709959], // London
getTargetPosition: f => f.geometry.coordinates,
getSourceColor: [0, 128, 200],
getTargetColor: [200, 0, 80],
getWidth: 1
})
]
});