-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
147 lines (121 loc) · 6.78 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Validador INE</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha384-sHL9NAb7lN7rfvG5lfHpm643Xkcjzp4jFvuavGOndn6pjVqS6ny56CAt3nsEVT4H" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.css" integrity="sha384-pmjIAcz2bAn0xukfxADbZIb3t8oRT9Sv0rvO+BR5Csr6Dhqq+nZs59P0pPKQJkEV" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css" integrity="sha384-wgw+aLYNQ7dlhK47ZPK7FRACiq7ROZwgFNg0m04avm4CaXS+Z9Y7nMu8yNjBKYC+" crossorigin="anonymous">
<style type="text/css">
body {
margin: 0;
padding: 0;
}
#map {
width: 100vw;
height: 100vh;
}
.leaflet-popup-content table td:first-child {
font-weight: 600;
}
.leaflet-popup-content div {
display: flex;
justify-content: space-evenly;
}
.leaflet-remaining-items em{
font-size: 1rem;
font-weight: 600;
}
.leaflet-github{
display: grid;
place-items: center;
padding: 4px;
box-sizing: border-box;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha384-cxOPjt7s7Iz04uaHJceBmS+qpjv2JkIHNVcuOrM+YHwZOmJGBXI00mdUXEq65HTH" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/dist/leaflet.markercluster.js" integrity="sha384-eXVCORTRlv4FUUgS/xmOyr66XBVraen8ATNLMESp92FKXLAMiKkerixTiBvXriZr" crossorigin="anonymous"></script>
<script type="module">
const map = L.map('map', {
center: [40.463667, -3.74922],
zoom: 6
});
const osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(map);
const ign = L.tileLayer.wms('http://www.ign.es/wms-inspire/mapa-raster', {
layers: 'mtn_rasterizado',
format: 'image/png',
transparent: true,
attribution: 'Mapa ráster <a href="https://www.ign.es">Instituto Geográfico Nacional</a>'
});
const baseLayers = {
"IGN": ign,
"OpenStreetMap": osm
};
const layerControl = L.control.layers(baseLayers).addTo(map);
const community = L.control({ position: 'topleft' });
community.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'leaflet-control-zoom leaflet-bar');
const url = "https://community.openstreetmap.org/t/proyecto-colaborativo-referencias-ine/7405"
this._div.innerHTML = `<a class="leaflet-control-zoom-in" href="${url}" target="_blank" rel="noopener noreferrer">i</a>`;
return this._div;
}
community.addTo(map);
const github = L.control({ position: 'topleft' });
github.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'leaflet-control-zoom leaflet-bar');
const url = "https://github.com/OSM-es/validador-ine"
this._div.innerHTML = `<a class="leaflet-github" href="${url}" target="_blank" rel="noopener noreferrer"><svg viewBox="0 0 16 16">
<path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path>
</svg></a>`;
return this._div;
}
github.addTo(map);
Promise.all([
fetch("./ES.geojson").then(response => response.json()),
fetch("./ES.leftover.geojson").then(response => response.json())
])
.then(function ([missingData, leftoverData]) {
const [missing, leftover] = [L.markerClusterGroup(), L.markerClusterGroup()];
missing.addLayer(L.geoJson(missingData, {
onEachFeature: function (feature, layer) {
const { lat, lng } = layer.getLatLng()
const buffer = layer.getLatLng().toBounds(1000)
const editorId = `https://www.openstreetmap.org/edit?editor=id#map=19/${lat}/${lng}`
const editorJosm = `http://127.0.0.1:8111/load_and_zoom?left=${buffer.getWest()}&bottom=${buffer.getSouth()}&right=${buffer.getEast()}&top=${buffer.getNorth()}`
const links = `<div><a href="${editorId}" target="_blank" rel="noopener">iD</a><a href="${editorJosm}" target="remote">JOSM</a></div>`
const { name, ...props } = feature.properties
const table = `<table><caption>${name}</caption>${Object.entries(props).sort().map(([k, v]) => `<tr><td>${k}</td><td>${v}</td></tr>`).join("")}</table>`
layer.bindPopup(`${table}${links}`);
}
}));
leftover.addLayer(L.geoJson(leftoverData, {
onEachFeature: function (feature, layer) {
const { lat, lng } = layer.getLatLng()
const { id, type, "ref:ine": ine } = feature.properties
const buffer = layer.getLatLng().toBounds(100)
const editorId = `https://www.openstreetmap.org/edit?${type}=${id}#map=19/${lat}/${lng}`
const editorJosm = `http://127.0.0.1:8111/load_and_zoom?select=${type}${id}&left=${buffer.getWest()}&bottom=${buffer.getSouth()}&right=${buffer.getEast()}&top=${buffer.getNorth()}`
const links = `<div><a href="${editorId}" target="_blank" rel="noopener">iD</a><a href="${editorJosm}" target="remote">JOSM</a></div>`
const msg = `<p>La referencia <code>${ine}</code> es errónea, o ha dejado de existir. Puedes comprobarlo <a href="https://www.ine.es/nomen2/index.do" target="_blank" rel="noopener">aquí</a>.<br>Usa los siguientes enlaces para eliminarla</p>`
layer.bindPopup(`${msg}${links}`);
}
}));
layerControl.addOverlay(missing, "Faltantes");
layerControl.addOverlay(leftover, "Sobrantes");
map.addLayer(missing);
map.fitBounds(missing.getBounds());
const remaining = L.control({ position: 'bottomleft' });
remaining.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'leaflet-remaining-items');
this._div.innerHTML = `<span>Total faltantes: <em>${missing.getLayers().length}</em></span> <span>Total sobrantes: <em>${leftover.getLayers().length}</em></span>`;
return this._div;
}
remaining.addTo(map);
});
</script>
</body>
</html>