todos-contra-el-fuego-web/imports/ui/components/Maps/SubsUnion/SubsUnion.js
vjrj bc778bfd97 deps: react-leaflet 1.8 -> 4.2 (+ leaflet 1.9) — the last legacy react-* lib
Ground-up hooks rewrite of the app's core map. Removes the final batch of
React-19-blocking warnings (legacy context on Map/LayersControl/TileLayer/
Marker/CircleMarker/Circle/Tooltip + ReactDOM.render from the old controls).

Core: <Map> -> <MapContainer>; .leafletElement refs (6 files) -> the map/
layer instances directly, via a <MapReady> child (useMap) + plain refs on
Marker/Circle/GeoJSON; controlled viewport (onViewportChanged + state.center/
zoom) -> <MapEvents> (useMapEvents moveend/zoomend) + imperative setView;
onClick -> eventHandlers={{click}}; Path styling -> pathOptions/style;
subsUnion takes the L.Map directly.

The 4 v1-only plugins reimplemented (new in-repo helpers under Maps/):
- react-leaflet-control -> MapControl (L.Control + createPortal)
- react-leaflet-google  -> GoogleMutantLayer (createLayerComponent +
  leaflet.gridlayer.googlemutant; Google Maps API already loaded by Gkeys)
- react-leaflet-fullscreen -> createControlComponent + leaflet.fullscreen
- leaflet-sleep / leaflet-graphicscale kept as vanilla (work on leaflet 1.9)

Browser-verified: /fires (tiles, OSM+Google layer switch, custom control,
fullscreen, graphic scale, pan/zoom -> re-fetch, no NaN), fire detail
(GeoJSON rect + fitBounds), home (3 maps coexist; SelectionMap draggable
marker -> updatePosition + distance circle). Console now shows 0 React
warnings on home/fires. REST smoke byte-identical.
2026-07-21 18:45:15 +02:00

55 lines
1.7 KiB
JavaScript

/* eslint-disable react/jsx-indent-props */
/* eslint-disable import/no-absolute-path */
/* eslint-disable import/no-absolute-path */
import L from 'leaflet';
import calcUnion from '/imports/ui/components/Maps/SubsUnion/Unify';
const subsUnion = (union, options) => {
const color = options.color || '#145A32';
const fillColor = options.fillColor || 'green';
const opacity = options.options || 0.1;
const interactive = options.interactive || false;
if (options.subs) {
// v4: options.map is the Leaflet map instance directly (no .leafletElement)
const lmap = options.map;
if (union) {
lmap.removeLayer(union);
}
union = null;
if (options.show) {
if (options.fromServer) {
// http://leafletjs.com/reference-1.3.0.html#geojson
// We get the json from server side
union = L.geoJson(JSON.parse(options.subs));
union.setStyle({
color, fillColor, fillOpacity: opacity, interactive
});
union.addTo(lmap);
union.bringToBack();
if (options.fit && options.bounds) {
// console.log(options.bounds);
const bounds = JSON.parse(options.bounds);
lmap.fitBounds(L.latLngBounds(bounds._northEast, bounds._southWest));
}
} else if (options.subs.length > 0) {
const result = calcUnion(L, options.subs, sub => sub, true);
const unionJson = result[0];
const bounds = result[1];
union = L.geoJson(unionJson);
union.setStyle({
color, fillColor, fillOpacity: opacity, interactive
});
union.addTo(lmap);
if (options.fit) {
lmap.fitBounds(bounds);
}
}
}
}
return union;
};
export default subsUnion;