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.
This commit is contained in:
parent
e61a3a9bcb
commit
bc778bfd97
18 changed files with 276 additions and 220 deletions
|
|
@ -10,7 +10,8 @@ import { Row, Col, Alert, Form } from 'react-bootstrap';
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { Bert } from 'meteor/themeteorchef:bert';
|
||||
import { Helmet } from 'react-helmet-async';
|
||||
import { Map, GeoJSON } from 'react-leaflet';
|
||||
import { MapContainer, GeoJSON } from 'react-leaflet';
|
||||
import { MapReady } from '/imports/ui/components/Maps/MapBridge';
|
||||
import { rectangleAround } from 'map-common-utils';
|
||||
import DefMapLayers from '/imports/ui/components/Maps/DefMapLayers';
|
||||
import NotFound from '/imports/ui/pages/NotFound/NotFound';
|
||||
|
|
@ -75,9 +76,15 @@ class Fire extends React.Component {
|
|||
});
|
||||
}
|
||||
|
||||
handleLeafletMapLoad(map) {
|
||||
if (map && map.leafletElement) {
|
||||
const lmap = map.leafletElement;
|
||||
// v4: MapReady hands us the ready Leaflet map directly (no ref/.leafletElement)
|
||||
handleMapReady(lmap) {
|
||||
this.fireMap = lmap;
|
||||
this.handleLeafletMapLoad(lmap);
|
||||
if (this.circle) lmap.fitBounds(this.circle.getBounds());
|
||||
}
|
||||
|
||||
handleLeafletMapLoad(lmap) {
|
||||
if (lmap) {
|
||||
const bounds = lmap.getBounds();
|
||||
const ne = bounds.getNorthEast();
|
||||
const sw = bounds.getSouthWest();
|
||||
|
|
@ -103,8 +110,9 @@ class Fire extends React.Component {
|
|||
}
|
||||
|
||||
handleLeafletCircleLoad(circle) {
|
||||
if (this.fireMap && this.fireMap.leafletElement && circle && circle.leafletElement) {
|
||||
this.fireMap.leafletElement.fitBounds(circle.leafletElement.getBounds());
|
||||
// v4: circle is the Leaflet GeoJSON layer; this.fireMap is the Leaflet map
|
||||
if (this.fireMap && circle) {
|
||||
this.fireMap.fitBounds(circle.getBounds());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,27 +142,17 @@ class Fire extends React.Component {
|
|||
{!loading &&
|
||||
<Fragment>
|
||||
<h4 className="page-header">{this.title}</h4>
|
||||
<Map
|
||||
ref={(map) => {
|
||||
this.fireMap = map;
|
||||
this.handleLeafletMapLoad(map);
|
||||
}}
|
||||
animate
|
||||
sleep={false}
|
||||
<MapContainer
|
||||
center={[fire.lat, fire.lon]}
|
||||
className="fire-leaflet-container"
|
||||
zoom={13}
|
||||
>
|
||||
<Fragment>
|
||||
<GeoJSON
|
||||
ref={(circle) => { this.circle = circle; this.handleLeafletCircleLoad(circle); }}
|
||||
data={rect}
|
||||
color="red"
|
||||
stroke
|
||||
width="1"
|
||||
fillOpacity="0.0"
|
||||
/>
|
||||
</Fragment>
|
||||
<MapReady onReady={map => this.handleMapReady(map)} />
|
||||
<GeoJSON
|
||||
ref={(circle) => { this.circle = circle; this.handleLeafletCircleLoad(circle); }}
|
||||
data={rect}
|
||||
style={{ color: 'red', stroke: true, weight: 1, fillOpacity: 0 }}
|
||||
/>
|
||||
<FireList
|
||||
t={t}
|
||||
history={this.props.history}
|
||||
|
|
@ -179,7 +177,7 @@ class Fire extends React.Component {
|
|||
/>
|
||||
<DefMapLayers satellite />
|
||||
<FullScreenMap />
|
||||
</Map>
|
||||
</MapContainer>
|
||||
<p>{t('Coordenadas:')} {fire.lat}, {fire.lon}</p>
|
||||
{(fire.type === 'modis' || fire.type === 'viirs') &&
|
||||
<Fragment>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue