viewof carte_scolaire_map = {
const container = yield html`<div style="height:800px;">`;
const map = (container.value = new maplibregl.Map({
boxZoom: true,
pitch: 0,
bearing: 0,
maplibreLogo: true,
container,
center: [2.3374205901589185, 48.8581402090239],
zoom: 12,
style: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json",
scrollZoom: true
}));
let hoveredStateId = null;
map.addControl(new maplibregl.NavigationControl());
map.on("load", function () {
map.addSource('point',{
type: 'vector',
tiles:["https://www.comeetie.fr/tileserver-php/tileserver.php?/inseedata20152017allregcircle.json?/inseedata20152017allregcircle/{z}/{x}/{y}.pbf"],
promoteId:{"inseedata20152017allregcircle": "id"},
maxzoom:11,
})
map.addSource('carreaux',{
type: 'vector',
tiles:["https://www.comeetie.fr/tileserver-php/tileserver.php?/inseedata20152017allreg.json?/inseedata20152017allreg/{z}/{x}/{y}.pbf"],
promoteId:{"inseedata20152017allreg": "id"},
maxzoom:11,
})
map.addSource("carte_scolaire", {
type: "geojson",
data:carte_scolaire,
promoteId:"code_rne"
});
map.addLayer({
id: "carte_sco",
type: "fill",
source: "carte_scolaire",
paint: {
"fill-color": "#bbbbbb",
"fill-opacity": [
'case',
['boolean', ['feature-state', 'hover'], false],
0.5,
0.1
]
}
});
map.addLayer({
id: "carte_sco_contours",
type: "line",
source: "carte_scolaire",
layout: {
"line-join": "round",
"line-cap": "round"
},
paint: {
"line-color": "#555555",
"line-width": 1
}
});
map.addLayer({
"id": "ind_snv_2017_circle",
"type": "circle",
"source": "point",
"source-layer": "inseedata20152017allregcircle",
"paint": {
"circle-radius":['*',['^',['min',['*',['/',['to-number',['get',`ind_2017`]],['get', 'area']],1000000],1000],0.5],0.1897367],
"circle-color": [
"step",
[
"/",
[
"to-number",
[
"get",
"ind_snv_2017"
]
],
[
"to-number",
[
"get",
"ind_2017"
]
]
],
"#b2182b",
18423.043328651685,
"#d6604d",
19750.698245614036,
"#f4a582",
20646.927083333332,
"#fddbc7",
21654.5,
"#d1e5f0",
22755.545636792456,
"#92c5de",
24297.12156862745,
"#4393c3",
26355.516666666666,
"#2166ac"
],
'circle-opacity': ['case',['boolean', ['feature-state', 'hover'], false],0.05,1]
},
"layout": {
"circle-sort-key":['*',['get',`ind_2017`],-1],
"visibility": "visible"
}
});
map.on('click', 'carte_sco', (e) => {
const coordinates = e.lngLat
const description = e.features[0].properties.code_rne;
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new maplibregl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the places layer.
map.on('mouseenter', 'carte_sco', () => {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'carte_sco', () => {
map.getCanvas().style.cursor = '';
});
map.on('mousemove', 'carte_sco', (e) => {
if (e.features.length > 0) {
if (hoveredStateId) {
map.setFeatureState(
{source: 'carte_scolaire', id: hoveredStateId},
{hover: false}
);
}
hoveredStateId = e.features[0].id;
map.setFeatureState(
{source: 'carte_scolaire', id: hoveredStateId},
{hover: true}
);
}
});
// When the mouse leaves the state-fill layer, update the feature state of the
// previously hovered feature.
map.on('mouseleave', 'carte_sco', () => {
if (hoveredStateId) {
map.setFeatureState(
{source: 'carte_scolaire', id: hoveredStateId},
{hover: false}
);
}
hoveredStateId = null;
});
});
}