-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
81 lines (69 loc) · 2.19 KB
/
app.js
File metadata and controls
81 lines (69 loc) · 2.19 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
const map = L.map("map").setView([20.5937, 78.9629], 5);
const tileUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
const attribution =
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>contributors, Coded by Nitin with 💗';
const tiles = L.tileLayer(tileUrl, { attribution });
tiles.addTo(map);
// Adding custom icon
const icon = L.icon({
iconUrl: "icon.png",
iconSize: [50, 50],
});
const generateList = () => {
const ul = document.querySelector(".list");
indianStatesAndUTs.forEach((state) => {
const li = document.createElement("li");
const div = document.createElement("div");
const a = document.createElement("a");
a.addEventListener("click", () => {
flyTOState(state);
});
const p = document.createElement("p");
div.appendChild(a);
div.appendChild(p);
li.appendChild(div);
ul.appendChild(li);
div.classList.add("state-list");
a.innerText = state.properties.name;
a.href = "#";
p.innerText = `Capital: ${state.properties.capital}`;
});
};
generateList();
function makePopupContent(state) {
return `
<div>
<h3>${ state.properties.name}</h3>
<p>Capital: ${state.properties.capital}</p>
<p>Speciality: ${state.properties.speciality}</p>
<p>Language: ${state.properties.language}</p>
<p class="detail">${state.properties.details}</p>
</div>
`;
}
function onEachFeature(feature, layer) {
layer.bindPopup(makePopupContent(feature), {
closeButton: false,
offset: L.point(0, -8),
});
}
const statesLayer = L.geoJSON(indianStatesAndUTs, {
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, { icon });
},
});
statesLayer.addTo(map);
function flyTOState(state) {
map.flyTo(
[state.geometry.coordinates[1], state.geometry.coordinates[0]],
12,
{ duration: 3 }
);
setTimeout(() => {
L.popup({ closeButton: false, offset: L.point(0, -8) })
.setLatLng([state.geometry.coordinates[1], state.geometry.coordinates[0]])
.setContent(makePopupContent(state))
.openOn(map);
}, 3000);
}