-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguide.js
More file actions
84 lines (72 loc) · 2.95 KB
/
guide.js
File metadata and controls
84 lines (72 loc) · 2.95 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
var map = L.map("map").setView([22.9074872, 79.0730667], 5);
let TileUrl = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
tileAttribute =
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
// add tiles to L object
const tile_layer = L.tileLayer(TileUrl, tileAttribute);
// add tile_layer to map
tile_layer.addTo(map);
// function to add shops to the left side from stores.js
const add_shops = function () {
const ul = document.querySelector(".lists");
storeList.forEach((stores) => {
// creating elements for each outlet
const li = document.createElement("li");
const div = document.createElement("div"); // list k andar dalne wala div
const a = document.createElement("a"); // div k andar dalne wala anchor tag
a.addEventListener("click", () => {
flyToshop(stores);
});
const p = document.createElement("p"); // div k andar dalne wala paragraph
div.classList.add("divv"); // link the div we created to div in html named heading
// creating variable containing data for each element
const outlet_no = stores.properties.name;
const address = stores.properties.address;
a.innerText = outlet_no;
p.innerText = address;
a.href = "#";
div.appendChild(a); // append a that contains the outlet number into div
div.appendChild(p); // append p that contains address into div
li.appendChild(div); // append div into list
ul.appendChild(li); // adding all lists to ul of our html named lists class
});
};
add_shops(); // calling add shop to add shops on the left side of screen
// add content to popup can be called when bindpopup
function makeContent(shop) {
return `
<div>
<h4>${shop.properties.name}</h4>
<p>${shop.properties.address}</p>
<div class="ph-no">
<a href= "tel:${shop.properties.phone}">${shop.properties.phone}</a>
</div> `;
}
// add popup to the marker function -> used below in line 60
function onEachFeature(Feature, layer) {
layer.bindPopup(makeContent(Feature), { closeButton: false });
}
// adding popup to each stores -> read about geoJSON
const shopLayer = L.geoJSON(storeList, {
onEachFeature: onEachFeature,
pointToLayer: function (Feature, latlng) {
return L.marker(latlng);
},
});
shopLayer.addTo(map);
// to fly to the market with certain zoom and animation when we click on outlet number on left side
function flyToshop(store) {
map.flyTo(
[store.geometry.coordinates[1], store.geometry.coordinates[0]],
14,
{ duration: 3 }
);
setTimeout(() => {
// to delay the opening of popup
// ot open popup when we click on a tag on line 20 we have added event listener for it already
L.popup({ closeButton: false, offset: L.point(0, -8) })
.setLatLng([store.geometry.coordinates[1], store.geometry.coordinates[0]])
.setContent(makeContent(store))
.openOn(map);
}, 3000);
}