-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.html
176 lines (165 loc) · 5.08 KB
/
map.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaflet Map Example</title>
<!-- Include Leaflet CSS and JS from CDN -->
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" />
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<style>
/* Set the size of the map container */
body, html {
height: 100%;
margin: 0;
}
#map {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<!-- Map container -->
<div id="map"></div>
<script>
// Initialize the map
var mymap = L.map('map').setView([28.472308, 77.488061], 14);
// Add a tile layer (using OpenStreetMap tiles)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(mymap);
// Sample GeoJSON data representing roads and incident locations in Delhi
var geojsonFeature = {
"type": "FeatureCollection",
"features": [
// LineString features
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[77.473416, 28.473747],
[77.480747, 28.478242],
[77.481576, 28.478297],
[77.485405, 28.474289],
[77.490669, 28.468511],
[77.490286, 28.468225],
[77.489272, 28.469297]
// Add more coordinates as needed
]
},
"properties": {
"color": "red"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[77.487240, 28.473209], // Coords A
[77.488061, 28.472308], // Intermediate point
[77.488944, 28.47133] // Coords B
]
},
"properties": {
"color": "green"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[77.487842,28.468307],
[77.489272, 28.469297],
[77.486085, 28.472716],
[77.479108, 28.468737]
]
},
"properties": {
"color": "green"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [77.488535, 28.474022]
},
"properties": {
"marker-color": "blue",
"marker-symbol": "incident",
"title": "Murder",
"description": "Murder"
}
}
//point 2
,{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [77.489335, 28.474439]
},
"properties": {
"marker-color": "blue",
"marker-symbol": "incident",
"title": "Theft",
"description": "At midnight"
}
}
,{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [77.488324, 28.472501]
},
"properties": {
"marker-color": "blue",
"marker-symbol": "incident",
"title": "Brawl",
"description": "At GL Bajaj"
}
}
,{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [77.489014, 28.468774]
},
"properties": {
"marker-color": "blue",
"marker-symbol": "incident",
"title": "Tech Tekens Wins",
"description": "At ITS College"
}
}
]
};
// Define a function to set the style based on the "color" property
function style(feature) {
return {
color: feature.properties.color,
weight: 5,
opacity: 0.7
};
}
// Add GeoJSON layer with custom style
L.geoJSON(geojsonFeature, {
style: style,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: L.divIcon({
className: 'custom-marker',
html: '<i class="fas fa-exclamation-circle"></i>',
iconSize: [30, 30],
iconAnchor: [10, 10],
})
}).bindPopup("<b>" + feature.properties.title + "</b><br>" + feature.properties.description);
}
}).addTo(mymap);
</script>
</body>
</html>