<div id='map' style='width: 800px; height: 800px;'></div>
<script>
// See above make a request to
// https://api.tic.io/datasets/properties/se/{uuid} (replace uuid with the property id)
// in your server controller / backend
const dataFromRequest = {};
// Then copy and paste the code below
const areas = dataFromRequest.omraden;
const byggnader = dataFromRequest.byggnader;
var map = new maplibregl.Map({
container: "map",
style: "https://tiles2.tic.io/style/super-map-style2",
center: [19.8756, 63.5569], // starting position [lng, lat]
zoom: 4, // starting zoom
attributionControl: false
});
let bounds = [];
map.on('load', async () => {
const coordinates = [];
const geojsonOmraden = {
type: 'geojson',
data: {
"type": 'FeatureCollection',
"features": []
}
};
_.forEach(omraden, function(omrade) {
geojsonOmraden.data.features.push({
type: 'Feature',
properties: {
omradesnummer: omrade.omradesnummer
},
geometry: {
type: 'Polygon',
coordinates: [omrade.omradeYta]
}
});
_.forEach(omrade.omradeYta, i => coordinates.push(i));
});
map.addSource('omraden', geojsonOmraden);
map.addLayer({
'id': 'omraden',
'type': 'fill',
'source': 'omraden',
'paint': {
'fill-color': '#90E0EF',
'fill-opacity': 0.7
},
'filter': ['==', '$type', 'Polygon']
});
const geojsonByggnadsdelar = {
type: 'geojson',
data: {
"type": 'FeatureCollection',
"features": []
}
};
_.forEach(byggnader, function(byggnad) {
_.forEach(byggnad.delar, function(del) {
geojsonByggnadsdelar.data.features.push({
type: 'Feature',
properties: {
byggnadHusnummer: byggnad.byggnadHusnummer
},
geometry: {
type: 'Polygon',
coordinates: [del.byggnadsdelYta]
}
});
});
});
map.addSource('byggnadsdelar', geojsonByggnadsdelar);
map.addLayer({
'id': 'byggnadsdelar',
'type': 'fill',
'source': 'byggnadsdelar',
'paint': {
'fill-color': '#FDC86C',
'fill-opacity': 0.8,
'fill-outline-color': '#F9A107'
},
'filter': ['==', '$type', 'Polygon']
});
map.addLayer({
'id': 'byggnadsdelartext',
'type': 'symbol',
'source': 'byggnadsdelar',
"layout": {
"text-field": [
"concat",
"Husnr: ",
["get", "byggnadHusnummer"],
],
"text-font": ["Open Sans SemiBold"],
"text-size": {
"stops": [
[2, 10],
[4, 12],
[6, 12],
[12, 12],
[16, 16]
]
},
"visibility": "visible"
},
"paint": {
"text-color": "#000",
"text-halo-blur": 1,
"text-halo-color": "rgba(255, 255, 255, 1)",
"text-halo-width": 1
},
'filter': ['==', '$type', 'Polygon']
});
map.addLayer({
'id': 'omradesnummertext',
'type': 'symbol',
'source': 'omraden',
"layout": {
"text-field": [
"concat",
"Omrnr: ",
["get", "omradesnummer"],
],
"text-font": ["Open Sans SemiBold"],
"text-size": {
"stops": [
[2, 10],
[4, 12],
[6, 12],
[12, 12],
[16, 16]
]
},
"visibility": "visible"
},
"paint": {
"text-color": "#000",
"text-halo-blur": 1,
"text-halo-color": "rgba(255, 255, 255, 1)",
"text-halo-width": 1
},
'filter': ['==', '$type', 'Polygon']
});
const bounds = coordinates.reduce((bounds, coord) => {
return bounds.extend(coord);
}, new maplibregl.LngLatBounds(coordinates[0], coordinates[0]));
map.fitBounds(bounds, {
padding: 120,
duration: 0
});
});
</script>