-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnections.html
143 lines (115 loc) · 4.53 KB
/
connections.html
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
142
143
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<meta name="description" content="Canvas Flowmap Layer with LeafletJS." />
<title>Canvas Flowmap Layer with LeafletJS</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<!-- first load LeafletJS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<!-- load Esri Leaflet because we want to use an Esri basemap -->
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"></script>
<!-- load animation tweening lib requirement for CanvasFlowMapLayer -->
<script src="https://unpkg.com/@tweenjs/[email protected]/dist/tween.umd.js"></script>
<!-- then load CanvasFlowMapLayer -->
<script src="CanvasFlowmapLayer.js"></script>
<!-- also load 3rd-party CSV parsing libary just for this demo -->
<script src="https://unpkg.com/[email protected]/papaparse.min.js"></script>
<script>
var mbAttr = 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
mbUrl = 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw';
var grayscale = L.tileLayer(mbUrl, {id: 'mapbox/light-v9', tileSize: 512, zoomOffset: -1, attribution: mbAttr}),
streets = L.tileLayer(mbUrl, {id: 'mapbox/streets-v11', tileSize: 512, zoomOffset: -1, attribution: mbAttr});
var map = L.map('map', {
center: [0,0],
zoom: 0,
layers: [grayscale]
});
var baseMaps = {
"<span style='color: gray'>Grayscale</span>": grayscale,
"Streets": streets
};
L.control.layers(baseMaps).addTo(map);
if (L.Browser.mobile) {
map.setView([15, -21.95], 2);
} else {
map.setView([0, 0], 2);
}
//L.esri.basemapLayer('DarkGray').addTo(map);
Papa.parse('https://raw.githubusercontent.com/Mergpijp/scout_leaflet/master/csv/Flowmap_Cities_one_to_many.csv', {
download: true,
header: true,
dynamicTyping: true,
skipEmptyLines: true,
complete: function(results) {
var geoJsonFeatureCollection = {
type: 'FeatureCollection',
features: results.data.map(function(datum) {
return {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [datum.s_lon, datum.s_lat]
},
properties: datum
}
})
};
var oneToManyFlowmapLayer = L.canvasFlowmapLayer(geoJsonFeatureCollection, {
originAndDestinationFieldIds: {
originUniqueIdField: 's_city_id',
originGeometry: {
x: 's_lon',
y: 's_lat'
},
destinationUniqueIdField: 'e_city_id',
destinationGeometry: {
x: 'e_lon',
y: 'e_lat'
}
},
pathDisplayMode: 'selection',
animationStarted: true,
animationEasingFamily: 'Cubic',
animationEasingType: 'In',
animationDuration: 2000
}).addTo(map);
// since this demo is using the optional "pathDisplayMode" as "selection",
// it is up to the developer to wire up a click or mouseover listener
// and then call the "selectFeaturesForPathDisplay()" method to inform the layer
// which Bezier paths need to be drawn
oneToManyFlowmapLayer.on('click', function(e) {
if (e.sharedOriginFeatures.length) {
oneToManyFlowmapLayer.selectFeaturesForPathDisplay(e.sharedOriginFeatures, 'SELECTION_NEW');
}
if (e.sharedDestinationFeatures.length) {
oneToManyFlowmapLayer.selectFeaturesForPathDisplay(e.sharedDestinationFeatures, 'SELECTION_NEW');
}
});
// immediately select an origin point for Bezier path display,
// instead of waiting for the first user click event to fire
oneToManyFlowmapLayer.selectFeaturesForPathDisplayById('s_city_id', 562, true, 'SELECTION_NEW');
}
});
</script>
</body>
</html>