67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
// Náhled obvodu v detailu — stejný podklad a rámeček jako na celé mapě.
|
|
(function () {
|
|
var el = document.getElementById('obvod-nahled');
|
|
if (!el || typeof L === 'undefined') {
|
|
return;
|
|
}
|
|
|
|
var obvodId = el.getAttribute('data-obvod');
|
|
var geojsonUrl = el.getAttribute('data-geojson');
|
|
if (!obvodId || !geojsonUrl) {
|
|
return;
|
|
}
|
|
|
|
var API_KEY = 'Uw8gm6JPZpnT3GfNnh8adARpQI-WBGy6QaY9g6VhD74';
|
|
var mapyCZ = L.tileLayer('https://api.mapy.cz/v1/maptiles/basic/256/{z}/{x}/{y}?apikey=' + API_KEY, {
|
|
minZoom: 0,
|
|
maxZoom: 19,
|
|
attribution: '<a href="https://api.mapy.cz/copyright" target="_blank">© Seznam.cz a.s. a další</a>',
|
|
});
|
|
|
|
var map = L.map(el, {
|
|
center: [50.853501146, 14.8425],
|
|
zoom: 14,
|
|
layers: [mapyCZ],
|
|
scrollWheelZoom: false,
|
|
});
|
|
|
|
var LogoControl = L.Control.extend({
|
|
options: { position: 'bottomleft' },
|
|
onAdd: function () {
|
|
var container = L.DomUtil.create('div');
|
|
var link = L.DomUtil.create('a', '', container);
|
|
link.setAttribute('href', 'http://mapy.cz/');
|
|
link.setAttribute('target', '_blank');
|
|
link.innerHTML = '<img src="https://api.mapy.cz/img/api/logo.svg" alt="Mapy.cz" />';
|
|
L.DomEvent.disableClickPropagation(link);
|
|
return container;
|
|
},
|
|
});
|
|
new LogoControl().addTo(map);
|
|
|
|
function style() {
|
|
return {
|
|
fillColor: '#FD8D3C',
|
|
weight: 2,
|
|
opacity: 1,
|
|
color: 'blue',
|
|
dashArray: '3',
|
|
fillOpacity: 0.05,
|
|
};
|
|
}
|
|
|
|
$.getJSON(geojsonUrl, function (data) {
|
|
var layer = L.geoJSON(data, {
|
|
style: style,
|
|
filter: function (feature) {
|
|
return feature.properties && String(feature.properties.number) === String(obvodId);
|
|
},
|
|
}).addTo(map);
|
|
|
|
if (layer.getLayers().length) {
|
|
map.fitBounds(layer.getBounds(), { padding: [16, 16] });
|
|
}
|
|
map.invalidateSize();
|
|
});
|
|
})();
|