-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgis_query.js
More file actions
98 lines (94 loc) · 3.04 KB
/
Copy pathgis_query.js
File metadata and controls
98 lines (94 loc) · 3.04 KB
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
function showAll() {
maybeClearLayers();
nwTrees = L.geoJson(allTreeData, {
onEachFeature,
});
clusters = L.markerClusterGroup({
spiderfyOnMaxZoom: false,
disableClusteringAtZoom: 18,
});
clusters.addLayer(nwTrees);
map.addLayer(clusters);
}
// TODO: Needs refactoring now that I'm not using carto.
function closestTree() {
if (map.hasLayer(closestTrees)) {
map.removeLayer(closestTrees);
}
// if (map.hasLayer(cluster)) {
// map.removeLayer(cluster);
// };
let sqlQueryClosestTrees;
if ($('#common_name_list').val() == '') {
sqlQueryClosestTrees = `SELECT * FROM trees_east ORDER BY the_geom <-> ST_SetSRID(ST_MakePoint(${myLocation.lng},${myLocation.lat}), 4326) LIMIT 5`;
} else {
sqlQueryClosestTrees = `SELECT * FROM trees_east WHERE common_name = ${$('#common_name_list').val()}ORDER BY the_geom <-> ST_SetSRID(ST_MakePoint(${myLocation.lng},${myLocation.lat}), 4326) LIMIT 5`;
}
$.getJSON(`https://${cartoDBUserName}.carto.com/api/v2/sql?format=GeoJSON&q=${sqlQueryClosestTrees}`, (data) => {
closestTrees = L.geoJson(data, {
pointToLayer(feature, latlng) {
const smallIcon = new L.Icon({
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-violet.png',
});
return L.marker(latlng, { icon: smallIcon });
},
onEachFeature,
}).addTo(map);
});
}
function selectTreesMatchingCommonName(common_name) {
maybeClearLayers();
matchingTrees = allTreeData.filter((item) => item.properties.FULL_NAME === common_name);
nwTrees = L.geoJson(matchingTrees, {
onEachFeature,
});
clusters = L.markerClusterGroup({
spiderfyOnMaxZoom: false,
disableClusteringAtZoom: 18,
});
clusters.addLayer(nwTrees);
map.addLayer(clusters);
nwTrees.addTo(map);
}
function selectTreesMatchingGenus(genus) {
maybeClearLayers();
matchingTrees = allTreeData.filter((item) => item.properties.GENUS === genus);
nwTrees = L.geoJson(matchingTrees, {
onEachFeature,
});
clusters = L.markerClusterGroup({
spiderfyOnMaxZoom: false,
disableClusteringAtZoom: 18,
});
clusters.addLayer(nwTrees);
map.addLayer(clusters);
nwTrees.addTo(map);
}
function showUnknownTrees(common_name) {
if (map.hasLayer(unknownTrees)) {
map.removeLayer(unknownTrees);
}
$.getJSON(`https://${cartoDBUserName}.carto.com/api/v2/sql?format=GeoJSON&q=${queryUnknownTrees}`, (data) => {
unknownTrees = L.geoJson(data, {
pointToLayer(feature, latlng) {
const smallIcon = new L.Icon({
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
iconUrl: 'https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-gold.png',
});
return L.marker(latlng, { icon: smallIcon });
},
onEachFeature,
});
clusters = L.markerClusterGroup({
spiderfyOnMaxZoom: false,
disableClusteringAtZoom: 18,
});
clusters.addLayer(unknownTrees);
map.addLayer(clusters);
});
}