forked from GIScience/Leaflet.Heightgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
69 lines (59 loc) · 1.7 KB
/
example.js
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
const onRoute = event => {
hg.mapMousemoveHandler(event, {showMapMarker:false})
}
const outRoute = event => {
hg.mapMouseoutHandler(2000)
}
const changeData = setNumber => {
let dataSet = setNumber === '1' ? geojson1 : setNumber === '2' ? geojson2 : setNumber === '3' ? geojson3 : []
displayGroup.clearLayers()
if (dataSet.length !== 0) {
let newLayer = L.geoJson(dataSet)
newLayer.on({
'mousemove': onRoute,
'mouseout': outRoute,
})
let newBounds = newLayer.getBounds()
displayGroup.addLayer(newLayer)
map.fitBounds(newBounds)
}
hg.addData(dataSet)
}
const map = new L.Map('map')
const url = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attr = "Map data © <a href=\"https://openstreetmap.org\">OpenStreetMap</a> contributors"
const openstreetmap = L.tileLayer(url, {
id: "openstreetmap",
attribution: attr
})
const displayGroup = new L.LayerGroup()
displayGroup.addTo(map)
const bounds = new L.LatLngBounds(new L.LatLng(47.323989, 8.108683), new L.LatLng(46.96485, 8.029803))
const hg = L.control.heightgraph({
mappings: colorMappings,
graphStyle: {
opacity: 0.8,
'fill-opacity': 0.5,
'stroke-width': '2px'
},
translation: {
distance: "My custom distance"
},
expandCallback(expand) {
console.log("Expand: "+expand)
},
expandControls: true,
highlightStyle: {
color: "purple"
}
})
hg.addTo(map)
hg.addData(geojson1)
L.geoJson(geojson1)
.on({
'mousemove': onRoute,
'mouseout': outRoute,
})
.addTo(displayGroup)
map.addLayer(openstreetmap).fitBounds(bounds)
hg.resize({width:1000,height:300})