-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
153 lines (131 loc) · 3.73 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SHCD searchable map</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<link rel="stylesheet" href="node_modules/leaflet-search/dist/leaflet-search.min.css" />
<link rel="stylesheet" href="node_modules/leaflet-search/dist/leaflet-search.mobile.min.css" />
<script src="node_modules/leaflet-search/dist/leaflet-search.min.js"></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 900px;
width: 100%;
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
<div id='map'></div>
<script src="sw.geojson.js"></script>
<script src="se.geojson.js"></script>
<script src="nw.geojson.js"></script>
<script src="wc.geojson.js"></script>
<script src="ec.geojson.js"></script>
<script>
const map = L.map('map', {
crs: L.CRS.Simple,
});
const geojsonOpts = {
pointToLayer: function(feature, latlng) {
var title = `
${feature.properties.name}
${feature.properties.amenity.join(", ")}
${feature.properties.residents.join(", ")}
`;
return L.marker(latlng, {
title: feature.properties.name,
//searchKey: title,
icon: L.divIcon({
className: `${feature.properties.district} region`,
iconSize: L.point(16, 16),
html: feature.properties.key, // User visible label
})
}).bindPopup(feature.properties.html);
}
};
// 6458x5030
const bounds = [[0, 0], [503, 645]];
const image = L.imageOverlay('map.png', bounds).addTo(map);
// Get all amenity types
// var amenities = [];
// SW.features.forEach(function(feature){
// feature.properties.amenity.forEach(function(amenity){
// if (amenities.indexOf(amenity) === -1) {
// amenities.push(amenity);
// }
// });
// });
// SE.features.forEach(function(feature){
// feature.properties.amenity.forEach(function(amenity){
// if (amenities.indexOf(amenity) === -1) {
// amenities.push(amenity);
// }
// });
// });
var poiLayers = L.layerGroup([
L.geoJson(SW, geojsonOpts),
L.geoJson(SE, geojsonOpts),
L.geoJson(NW, geojsonOpts),
L.geoJson(WC, geojsonOpts),
L.geoJson(EC, geojsonOpts),
])
.addTo(map);
L.control.search({
layer: poiLayers,
initial: false,
//propertyName: 'searchKey',
buildTip: function(text, val) {
var key = val.layer.feature.properties.name;
var type = val.layer.feature.properties.amenity.join(', ');
console.log(text, val);
return `<a href="#" class="${type}"><b>${key}</b> ${type}</a>`;
},
filterData: function(text, records) {
var x = Object.assign({}, ...
Object.entries(records)
.filter(([k,v]) => {
return (
v.layer.feature.properties.search.toLowerCase().indexOf(text.toLowerCase()) > -1
)
})
.map(([k,v]) => ({[k]:v}))
);
console.log(x);
return x;
}
})
.addTo(map);
var i = 1;
map.on('click', function(ev){
var latlng = map.mouseEventToLatLng(ev.originalEvent);
console.log(`${i}: [${latlng.lat}, ${latlng.lng}]`);
i++;
});
map.fitBounds(bounds);
</script>
<style>
.region {
border: 1px solid black;
background: white;
text-align: center;
border-radius: 25%;
}
.NW { background: #ffa; }
.SE { background: #faf; }
.SW { background: #aff; }
.NE { background: #cfc; }
.EC { background: #fcc; }
.WC { background: #ccf; }
</style>
</body>
</html>