Merge pull request #7067 from tchak/fix-map-reader
fix(carto): render GeoJSON layers after map style changes
This commit is contained in:
commit
ddc0876dc5
1 changed files with 57 additions and 45 deletions
|
@ -144,7 +144,8 @@ function LineStringLayer({
|
||||||
const sourceId = String(feature.properties?.id);
|
const sourceId = String(feature.properties?.id);
|
||||||
const layerId = `${sourceId}-layer`;
|
const layerId = `${sourceId}-layer`;
|
||||||
|
|
||||||
useEffect(() => {
|
const render = () => {
|
||||||
|
if (!map.getSource(sourceId)) {
|
||||||
map
|
map
|
||||||
.addSource(sourceId, {
|
.addSource(sourceId, {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
|
@ -156,8 +157,11 @@ function LineStringLayer({
|
||||||
type: 'line',
|
type: 'line',
|
||||||
paint: lineStringSelectionLine
|
paint: lineStringSelectionLine
|
||||||
});
|
});
|
||||||
}, [map, layerId, sourceId, feature]);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(render, [map, layerId, sourceId, feature]);
|
||||||
|
useMapEvent('styledata', render);
|
||||||
useMapEvent('mouseenter', onMouseEnter, layerId);
|
useMapEvent('mouseenter', onMouseEnter, layerId);
|
||||||
useMapEvent('mouseleave', onMouseLeave, layerId);
|
useMapEvent('mouseleave', onMouseLeave, layerId);
|
||||||
|
|
||||||
|
@ -177,7 +181,8 @@ function PointLayer({
|
||||||
const sourceId = String(feature.properties?.id);
|
const sourceId = String(feature.properties?.id);
|
||||||
const layerId = `${sourceId}-layer`;
|
const layerId = `${sourceId}-layer`;
|
||||||
|
|
||||||
useEffect(() => {
|
const render = () => {
|
||||||
|
if (!map.getSource(sourceId)) {
|
||||||
map
|
map
|
||||||
.addSource(sourceId, {
|
.addSource(sourceId, {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
|
@ -189,8 +194,11 @@ function PointLayer({
|
||||||
type: 'circle',
|
type: 'circle',
|
||||||
paint: pointSelectionCircle
|
paint: pointSelectionCircle
|
||||||
});
|
});
|
||||||
}, [map, layerId, sourceId, feature]);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(render, [map, layerId, sourceId, feature]);
|
||||||
|
useMapEvent('styledata', render);
|
||||||
useMapEvent('mouseenter', onMouseEnter, layerId);
|
useMapEvent('mouseenter', onMouseEnter, layerId);
|
||||||
useMapEvent('mouseleave', onMouseLeave, layerId);
|
useMapEvent('mouseleave', onMouseLeave, layerId);
|
||||||
|
|
||||||
|
@ -211,7 +219,8 @@ function PolygonLayer({
|
||||||
const layerId = `${sourceId}-layer`;
|
const layerId = `${sourceId}-layer`;
|
||||||
const lineLayerId = `${sourceId}-line-layer`;
|
const lineLayerId = `${sourceId}-line-layer`;
|
||||||
|
|
||||||
useEffect(() => {
|
const render = () => {
|
||||||
|
if (!map.getSource(sourceId)) {
|
||||||
map
|
map
|
||||||
.addSource(sourceId, {
|
.addSource(sourceId, {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
|
@ -229,8 +238,11 @@ function PolygonLayer({
|
||||||
type: 'fill',
|
type: 'fill',
|
||||||
paint: polygonSelectionFill
|
paint: polygonSelectionFill
|
||||||
});
|
});
|
||||||
}, [map, layerId, lineLayerId, sourceId, feature]);
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(render, [map, layerId, lineLayerId, sourceId, feature]);
|
||||||
|
useMapEvent('styledata', render);
|
||||||
useMapEvent('mouseenter', onMouseEnter, layerId);
|
useMapEvent('mouseenter', onMouseEnter, layerId);
|
||||||
useMapEvent('mouseleave', onMouseLeave, layerId);
|
useMapEvent('mouseleave', onMouseLeave, layerId);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue