forked from robertleeplummerjr/Leaflet.glify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
153 lines (140 loc) · 3.7 KB
/
example.ts
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
144
145
146
147
148
149
150
151
152
153
import * as L from 'leaflet';
import { FeatureCollection } from 'geojson';
import glify from './src/index';
const map = L.map('map')
.setView([50.00, 14.44], 7);
L.tileLayer('http://{s}.sm.mapstack.stamen.com/(toner-background,$fff[difference],$fff[@23],$fff[hsl-saturation@20],toner-lines[destination-in])/{z}/{x}/{y}.png')
.addTo(map);
Promise.all([
wget<number[][]>('data/86T.json'),
wget<FeatureCollection>('data/CZDistricts.json'),
wget<FeatureCollection>('data/rivers.json')
])
.then(([points, districts, rivers]) => {
glify.shapes({
map: map,
click: (e, feature): void => {
L.popup()
.setLatLng(e.latlng)
.setContent('You clicked on ' + feature.properties.NAZKR_ENG)
.openOn(map);
console.log(feature);
console.log(e);
},
data: districts,
border: true,
});
glify.lines({
map: map,
latitudeKey: 1,
longitudeKey: 0,
weight: 5,
click: (e, feature) => {
L.popup()
.setLatLng(e.latlng)
.setContent('You clicked on ' + feature.properties.name)
.openOn(map);
console.log(feature);
console.log(e);
},
data: rivers
});
glify.points({
map: map,
size: function(i) {
return (Math.random() * 17) + 3;
},
click: (e, point, xy) => {
//set up a standalone popup (use a popup as a layer)
L.popup()
.setLatLng(point)
.setContent('You clicked the point at longitude:' + point[glify.longitudeKey] + ', latitude:' + point[glify.latitudeKey])
.openOn(map);
console.log(point);
},
data: points
});
glify.points({
map,
size: (i) => {
return 20;
},
color: () => {
return {
r: 1,
g: 0,
b: 0,
};
},
click: (e, point) => {
//set up a standalone popup (use a popup as a layer)
L.popup()
.setLatLng(point)
.setContent('You clicked the point at longitude:' + point[glify.longitudeKey] + ', latitude:' + point[glify.latitudeKey])
.openOn(map);
console.log(point);
},
data: [[50.10164799,14.5]]
});
glify.points({
map,
size: (i) => {
return 20;
},
color: () => {
return {
r: 0,
g: 0,
b: 1,
};
},
click: (e, feature) => {
//set up a standalone popup (use a popup as a layer)
L.popup()
.setLatLng(feature.geometry.coordinates)
.setContent('You clicked on:' + feature.properties.name)
.openOn(map);
console.log(feature);
},
data: { //geojson
'type': 'FeatureCollection',
'features':[
{
'type':'Feature',
'geometry': {
'type': 'Point',
'coordinates': [90, 135]
},
'properties': {
'name': 'North Pole',
'color': 'red'
}
},
{
'type':'Feature',
'geometry': {
'type': 'Point',
'coordinates': [90, 45]
},
'properties': {
'name': 'South Pole',
'color': 'blue'
}
}
],
}
});
});
function wget<T>(url): Promise<T> {
return new Promise<T>((resolve, reject) => {
const request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = () => {
if (request.status < 200 && request.status > 400) {
return reject(new Error('failure'));
}
resolve(JSON.parse(request.responseText) as T);
};
request.send();
});
}