forked from furstenheim/Leaflet.VectorGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-points.html
139 lines (122 loc) · 4.16 KB
/
demo-points.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
<!DOCTYPE html>
<html>
<head>
<title>Leaflet.VectorGrid Points Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
</head>
<body style='margin:0'>
<div id="map" style="width: 100vw; height: 100vh"></div>
<script type="text/javascript" src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<script type="text/javascript" src="https://unpkg.com/leaflet.vectorgrid@1.2.0"></script>
<!-- <script type="text/javascript" src="../dist/Leaflet.VectorGrid.bundled.js"></script> -->
<script>
var map = L.map('map');
// var cartodbAttribution = '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>';
//
// var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
// attribution: cartodbAttribution,
// opacity: 0.5
// }).addTo(map);
// var mapboxUrl = 'https://{s}.tiles.mapbox.com/v4/mapbox.mapbox-streets-v6/{z}/{x}/{y}.vector.pbf?access_token=pk.eyJ1IjoiaXZhbnNhbmNoZXoiLCJhIjoiY2l6ZTJmd3FnMDA0dzMzbzFtaW10cXh2MSJ9.VsWCS9-EAX4_4W1K-nXnsA';
// var mapboxAttribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="https://www.mapbox.com/about/maps/">MapBox</a>'
var openmaptilesUrl = "https://free-{s}.tilehosting.com/data/v3/{z}/{x}/{y}.pbf.pict?key={key}";
var openmaptilesAttribution = '<a href="https://openmaptiles.org/">© OpenMapTiles</a>, <a href="http://www.openstreetmap.org/copyright">© OpenStreetMap</a> contributors';
var openmaptilesKey = 'VrAl6k9W8JkD4G5584Sz'; // API key only valid for leaflet.github.io
var vectorTileOptions = {
rendererFactory: L.canvas.tile,
attribution: openmaptilesAttribution,
key: openmaptilesKey,
subdomains: '0123', // 01234 for openmaptiles, abcd for mapbox
maxNativeZoom: 14,
vectorTileLayerStyles: {
'poi': function(properties, zoom) {
return {
weight: 2,
color: 'red',
opacity: 1,
fillColor: 'yellow',
fill: true,
radius: 6,
fillOpacity: 0.7
}
},
'housenumber': function(properties, zoom) {
return {
weight: 2,
color: 'purple',
opacity: 1,
fillColor: 'green',
fill: true,
radius: 4,
fillOpacity: 0.3
}
},
park: [],
place: [],
water: [],
waterway: [],
boundary: [],
country_label: [],
marine_label: [],
state_label: [],
place_label: [],
waterway_label: [],
water_name: [],
landcover: [],
landuse: [],
landuse_overlay: [],
road: [],
transportation: [],
waterway: [],
aeroway: [],
tunnel: [],
bridge: [],
barrier_line: [],
building: [],
road_label: [],
road_name: [],
transportation_name: [],
housenum_label: [],
mountain_peak: [],
},
interactive: true, // Make sure that this VectorGrid fires mouse/pointer events
getFeatureId: function(f) {
return f.properties.osm_id;
}
};
L.tileLayer('http://tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map);
var highlight;
var clearHighlight = function() {
if (highlight) {
pbfLayer.resetFeatureStyle(highlight);
}
highlight = null;
};
var pbfLayer = L.vectorGrid.protobuf(openmaptilesUrl, vectorTileOptions)
.on('click', function(e) { // The .on method attaches an event handler
L.popup()
.setContent(e.layer.properties.name || e.layer.properties.type)
// .setContent(JSON.stringify(e.layer))
.setLatLng(e.latlng)
.openOn(map);
clearHighlight();
highlight = e.layer.properties.osm_id;
pbfLayer.setFeatureStyle(highlight, {
weight: 2,
color: 'red',
opacity: 1,
fillColor: 'red',
fill: true,
radius: 6,
fillOpacity: 1
})
L.DomEvent.stop(e);
})
.addTo(map);
map.on('click', clearHighlight);
map.setView([40.9994639, -74.163208], 14);
</script>
</body>
</html>