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
|
|
@ -8,14 +8,15 @@ import { Button, ButtonGroup, Row, Col } from 'react-bootstrap';
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { withTracker } from 'meteor/react-meteor-data';
|
||||
import { Trans, withTranslation } from 'react-i18next';
|
||||
import { Map } from 'react-leaflet';
|
||||
import { MapContainer } from 'react-leaflet';
|
||||
import { Helmet } from 'react-helmet-async';
|
||||
import L from 'leaflet';
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
import 'leaflet-graphicscale/dist/Leaflet.GraphicScale.min.css';
|
||||
import 'leaflet-graphicscale/dist/Leaflet.GraphicScale.min.js';
|
||||
import 'leaflet-sleep/Leaflet.Sleep.js';
|
||||
import Control from 'react-leaflet-control';
|
||||
import MapControl from '/imports/ui/components/Maps/MapControl';
|
||||
import { MapReady } from '/imports/ui/components/Maps/MapBridge';
|
||||
import CenterInMyPosition from '/imports/ui/components/CenterInMyPosition/CenterInMyPosition';
|
||||
import subsUnion from '/imports/ui/components/Maps/SubsUnion/SubsUnion';
|
||||
import DefMapLayers from '/imports/ui/components/Maps/DefMapLayers';
|
||||
|
|
@ -39,16 +40,18 @@ class SubscriptionsMap extends React.Component {
|
|||
},
|
||||
init: true
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.subscriptionsMap) {
|
||||
this.addScale();
|
||||
}
|
||||
this.handleMapReady = this.handleMapReady.bind(this);
|
||||
}
|
||||
|
||||
getMap() {
|
||||
return this.subscriptionsMap.leafletElement;
|
||||
return this.map;
|
||||
}
|
||||
|
||||
// v4: <MapReady> hands us the ready Leaflet map (no ref/.leafletElement)
|
||||
handleMapReady(map) {
|
||||
this.map = map;
|
||||
this.addScale();
|
||||
this.handleLeafletLoad(map);
|
||||
}
|
||||
|
||||
addScale() {
|
||||
|
|
@ -77,8 +80,9 @@ class SubscriptionsMap extends React.Component {
|
|||
}
|
||||
|
||||
centerOnUserLocation(viewport) {
|
||||
console.log(`viewport: ${JSON.stringify(viewport)}`);
|
||||
this.setState({ init: false, viewport });
|
||||
// v4 map is uncontrolled: move it imperatively
|
||||
if (this.map) this.map.setView(viewport.center, viewport.zoom);
|
||||
}
|
||||
|
||||
gotoParticipe() {
|
||||
|
|
@ -112,15 +116,10 @@ class SubscriptionsMap extends React.Component {
|
|||
<Trans>En verde, las zonas vigiladas por nuestros usuari@s actualmente</Trans> (*)
|
||||
</Row>
|
||||
</Col>
|
||||
<Map
|
||||
ref={(map) => {
|
||||
this.subscriptionsMap = map;
|
||||
this.handleLeafletLoad(map);
|
||||
}}
|
||||
<MapContainer
|
||||
zoom={this.state.viewport.zoom}
|
||||
center={this.state.viewport.center}
|
||||
className="subscriptionsmap-leaflet-container"
|
||||
animate
|
||||
sleep={window.location.pathname === '/' && !isChrome}
|
||||
sleepTime={10750}
|
||||
wakeTime={750}
|
||||
|
|
@ -130,8 +129,9 @@ class SubscriptionsMap extends React.Component {
|
|||
wakeMessageTouch={this.props.t('Pulsa para activar')}
|
||||
sleepOpacity={0.6}
|
||||
>
|
||||
<MapReady onReady={this.handleMapReady} />
|
||||
<DefMapLayers gray />
|
||||
<Control position="topright" >
|
||||
<MapControl position="topright" >
|
||||
<ButtonGroup>
|
||||
<CenterInMyPosition onClick={viewport => this.centerOnUserLocation(viewport)} onlyIcon {... this.props} />
|
||||
<Button
|
||||
|
|
@ -141,9 +141,9 @@ class SubscriptionsMap extends React.Component {
|
|||
{this.props.t('Participa')}
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</Control>
|
||||
</MapControl>
|
||||
<FullScreenMap />
|
||||
</Map>
|
||||
</MapContainer>
|
||||
<Row>
|
||||
<Col xs={12} sm={12} md={12} lg={12}>
|
||||
<p className="subscriptionsmap-footnote"><span style={{ paddingRight: '5px' }}>(*)</span><Trans i18nKey="mapPrivacy" parent="span"><em>Para preservar la privacidad de nuestros usuarios/as, los datos reflejados están aleatoriamente alterados y son solo orientativos.</em></Trans></p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue