-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
112 lines (104 loc) · 2.42 KB
/
main.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
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
import maplibregl from "maplibre-gl";
const apiKey ="YOUR_API_KEY"
const basemapEnum = "ArcGIS:Community";
const map = new maplibregl.Map({
container: "map",
style: `https://basemaps-api.arcgis.com/arcgis/rest/services/styles/${basemapEnum}?type=style&token=${apiKey}`,
center: [-122.675, 45.5051], // starting position [lng, lat]
zoom: 12,
});
const layers = [
{
id: "treefair",
type: "circle",
source: "pdx",
"source-layer": "PDX Trees",
filter: ["==", "_symbol", 0],
minzoom: 9,
layout: {},
paint: {
"circle-color": "#38A800",
"circle-radius": {
stops: [
[2, 10],
[5, 8],
[10, 3],
],
},
},
},
{
id: "treegood",
type: "circle",
source: "pdx",
"source-layer": "PDX Trees",
filter: ["==", "_symbol", 1],
minzoom: 9,
layout: {},
paint: {
"circle-color": "#267300",
"circle-radius": 3,
},
},
{
id: "treepoor",
type: "circle",
source: "pdx",
"source-layer": "PDX Trees",
filter: ["==", "_symbol", 2],
minzoom: 9,
layout: {},
paint: {
"circle-color": "#E6E600",
"circle-radius": 3,
},
},
{
id: "treedead",
type: "circle",
source: "pdx",
"source-layer": "PDX Trees",
filter: ["==", "_symbol", 3],
minzoom: 9,
layout: {},
paint: {
"circle-color": "#ED5151",
"circle-radius": 3,
},
},
];
const popup = new maplibregl.Popup({
closeButton: false,
closeOnClick: false,
});
map.once("load", () => {
map.addSource("pdx", {
type: "vector",
tiles: [
"https://vectortileservices8.arcgis.com/87xMVlxSyDt491tZ/arcgis/rest/services/treevtl_demo/VectorTileServer/tile/{z}/{y}/{x}.pbf",
],
});
layers.forEach((layer) => {
map.addLayer(layer);
map.on("mouseover", layer.id, (e) => {
map.getCanvas().style.cursor = "pointer";
const feature = e.features[0];
console.log(feature.properties);
popup
.setLngLat(e.lngLat)
.setHTML(
`<b>Common Name: </b>${
feature.properties.Common
}<br/><b>Condition: </b>${feature.properties.Condition.toLowerCase()}`
)
.addTo(map);
});
map.on("mouseenter", layer.id, () => {
map.getCanvas().style.cursor = "pointer";
});
map.on("mouseleave", layer.id, (e) => {
map.getCanvas().style.cursor = "";
popup.remove();
});
});
});