pull/1/head
tomasz t 2021-11-26 20:05:09 +01:00
rodzic 2f0ff69a92
commit 345179b67c
5 zmienionych plików z 165 dodań i 0 usunięć

BIN
src/aed_240px.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 3.2 KiB

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -0,0 +1,66 @@
import requests
import json
def geojson_point_feature(lat: float, lon: float, properties: dict) -> dict:
return {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [lon, lat]
},
"properties": properties,
}
overpass_api_url = 'https://lz4.overpass-api.de/api/interpreter'
overpass_query = '''
[out:json][timeout:90];
// area(3600049715) = Polska
area(3600049715)->.searchArea;
// gather results
(
// query part for: emergency=defibrillator
node[emergency=defibrillator](area.searchArea);
);
// print results
out body;
>;
out skel qt;'''
tags_to_keep = {
'emergency',
'defibrillator:location',
'defibrillator:location:pl',
'access',
'indoor',
'description',
'description:pl',
'phone',
'note',
'note:pl',
}
response = requests.post(url=overpass_api_url, data={'data': overpass_query})
response.raise_for_status()
elements = response.json().get('elements')
geojson = {
"type": "FeatureCollection",
"features": [],
}
for element in elements:
osm_id = element['id']
longitude = element['lon']
latitude = element['lat']
tags = {
key: value for key, value in element['tags'].items() if key in tags_to_keep
}
tags['osm_id'] = osm_id
geojson['features'].append(
geojson_point_feature(lat=latitude, lon=longitude, properties=tags)
)
with open(file='aed_poland.geojson', mode='w', encoding='utf-8') as f:
json.dump(geojson, f, allow_nan=False)

19
src/index.html 100644
Wyświetl plik

@ -0,0 +1,19 @@
<html>
<head>
<title>AED - mapa defibrylatorów</title>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@1.15.2/dist/maplibre-gl.css" rel="stylesheet" />
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script src="./map.js"></script>
</body>
</html>

79
src/map.js 100644
Wyświetl plik

@ -0,0 +1,79 @@
var map = new maplibregl.Map({
'container': 'map', // container id
'center': [20, 52], // starting position [lng, lat]
'zoom': 6, // starting zoom
'hash': 'map',
'style': {
'version': 8,
"glyphs": "http://fonts.openmaptiles.org/{fontstack}/{range}.pbf",
'sources': {
'raster-tiles': {
'type': 'raster',
'tiles': [
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png',
'https://c.tile.openstreetmap.org/{z}/{x}/{y}.png'
],
'tileSize': 256,
'attribution':
'map © <a target="_top" rel="noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors.',
},
},
'layers': [
{
'id': 'background',
'type': 'raster',
'source': 'raster-tiles',
'minzoom': 0,
'maxzoom': 22,
},
]
},
});
map.on('load', () => {
map.loadImage('./aed_240px.png', (error, image) => {
if (error) throw error;
map.addImage('aed-icon', image, { 'sdf': false });
map.addSource('aed-locations', {
'type': 'geojson',
'data': './aed_poland.geojson',
'cluster': true,
});
map.addLayer({
'id': 'unclustered',
'type': 'symbol',
'source': 'aed-locations',
'layout': {
'icon-image': ['image', 'aed-icon'],
'icon-size': 0.2,
},
'filter': ['!', ['has', 'point_count']],
});
map.addLayer({
'id': 'clustered-circle',
'type': 'circle',
'source': 'aed-locations',
'paint': {
'circle-color': '#09FF09',
'circle-radius': 40,
},
'filter': ['has', 'point_count'],
});
map.addLayer({
'id': 'clustered-label',
'type': 'symbol',
'source': 'aed-locations',
'layout': {
'text-field': '{point_count_abbreviated}',
'text-font': ['Open Sans Bold'],
'text-size': 18,
},
'paint': {
'text-halo-width': 2,
'text-halo-color': 'white',
},
'filter': ['has', 'point_count'],
});
});
});