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
|
|
@ -11,8 +11,9 @@ import { withTracker } from 'meteor/react-meteor-data';
|
|||
import { Tracker } from 'meteor/tracker';
|
||||
import { Helmet } from 'react-helmet-async';
|
||||
import { Trans, withTranslation } from 'react-i18next';
|
||||
import { Map } from 'react-leaflet';
|
||||
import Control from 'react-leaflet-control';
|
||||
import { MapContainer } from 'react-leaflet';
|
||||
import MapControl from '/imports/ui/components/Maps/MapControl';
|
||||
import { MapReady, MapEvents } from '/imports/ui/components/Maps/MapBridge';
|
||||
import LoadingBar from '/imports/ui/components/Loading/LoadingBar';
|
||||
import _ from 'lodash';
|
||||
import store from 'store';
|
||||
|
|
@ -76,6 +77,24 @@ class FiresMap extends React.Component {
|
|||
this.onViewportChanged = this.onViewportChanged.bind(this);
|
||||
this.onMoveEnd = this.onMoveEnd.bind(this);
|
||||
this.onMoveStart = this.onMoveStart.bind(this);
|
||||
this.handleMoveEnd = this.handleMoveEnd.bind(this);
|
||||
this.handleMapReady = this.handleMapReady.bind(this);
|
||||
}
|
||||
|
||||
// v4: combined moveend/zoomend handler fed by <MapEvents> — clears the
|
||||
// moving flag and reports the new viewport (was the v1 onMoveend +
|
||||
// onViewportChanged props on <Map>).
|
||||
handleMoveEnd() {
|
||||
this.onMoveEnd();
|
||||
if (!this.map) return;
|
||||
const c = this.map.getCenter();
|
||||
this.onViewportChanged({ center: [c.lat, c.lng], zoom: this.map.getZoom() });
|
||||
}
|
||||
|
||||
// v4: MapReady hands us the ready Leaflet map (replaces ref/.leafletElement)
|
||||
handleMapReady(map) {
|
||||
this.map = map;
|
||||
this.handleLeafletLoad(map);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
|
@ -110,7 +129,7 @@ class FiresMap extends React.Component {
|
|||
}
|
||||
|
||||
getMap() {
|
||||
return this.fireMap.leafletElement;
|
||||
return this.map;
|
||||
}
|
||||
|
||||
setShowSubsUnion(showSubsUnion) {
|
||||
|
|
@ -124,7 +143,7 @@ class FiresMap extends React.Component {
|
|||
|
||||
handleViewportChange(viewport) {
|
||||
console.log(`Viewport changed: ${JSON.stringify(viewport)}`);
|
||||
if (this.fireMap) {
|
||||
if (this.map) {
|
||||
const bounds = this.getMap().getBounds();
|
||||
// console.log(bounds);
|
||||
mapSize.set([bounds.getNorthEast(), bounds.getSouthWest()]);
|
||||
|
|
@ -143,6 +162,8 @@ class FiresMap extends React.Component {
|
|||
|
||||
centerOnUserLocation(viewport) {
|
||||
this.setState({ viewport: { center: viewport.center, zoom: 10 } });
|
||||
// v4 map is uncontrolled: move it imperatively
|
||||
if (this.map) this.map.setView(viewport.center, 10);
|
||||
}
|
||||
|
||||
useMarkers(use) {
|
||||
|
|
@ -161,8 +182,8 @@ class FiresMap extends React.Component {
|
|||
}
|
||||
|
||||
handleLeafletLoad(map) {
|
||||
if (map && map.leafletElement && !this.state.moving) {
|
||||
const lmap = map.leafletElement;
|
||||
if (map && !this.state.moving) {
|
||||
const lmap = map;
|
||||
try {
|
||||
const bounds = lmap.getBounds();
|
||||
mapSize.set([bounds.getNorthEast(), bounds.getSouthWest()]);
|
||||
|
|
@ -266,24 +287,13 @@ class FiresMap extends React.Component {
|
|||
<LoadingBar progress={this.props.loading ? 0.9 : 1} />
|
||||
: ''}
|
||||
{/* https://github.com/CliffCloud/Leaflet.Sleep */}
|
||||
<Map
|
||||
ref={(map) => {
|
||||
this.fireMap = map;
|
||||
this.handleLeafletLoad(map);
|
||||
}}
|
||||
<MapContainer
|
||||
className="firesmap-leaflet-container"
|
||||
animate
|
||||
minZoom={5}
|
||||
center={this.state.viewport.center}
|
||||
zoom={this.state.viewport.zoom}
|
||||
preferCanvas
|
||||
viewport={this.state.viewport}
|
||||
onViewportChanged={this.onViewportChanged}
|
||||
sleep={isHome() && !isChrome}
|
||||
onMoveend={this.onMoveEnd}
|
||||
onMovestart={this.onMoveStart}
|
||||
onZoomend={this.onMoveEnd}
|
||||
onZoomstart={this.onMoveStart}
|
||||
sleepTime={10750}
|
||||
wakeTime={750}
|
||||
sleepNote
|
||||
|
|
@ -292,6 +302,14 @@ class FiresMap extends React.Component {
|
|||
wakeMessageTouch={this.props.t('Pulsa para activar')}
|
||||
sleepOpacity={0.6}
|
||||
>
|
||||
<MapReady onReady={this.handleMapReady} />
|
||||
<MapEvents handlers={{
|
||||
movestart: this.onMoveStart,
|
||||
zoomstart: this.onMoveStart,
|
||||
moveend: this.handleMoveEnd,
|
||||
zoomend: this.handleMoveEnd
|
||||
}}
|
||||
/>
|
||||
{/* http://wiki.openstreetmap.org/wiki/Tile_servers */}
|
||||
{!this.props.loading &&
|
||||
<Fragment>
|
||||
|
|
@ -349,13 +367,13 @@ class FiresMap extends React.Component {
|
|||
/>
|
||||
</Fragment> }
|
||||
<DefMapLayers gray />
|
||||
<Control position="topright" >
|
||||
<MapControl position="topright" >
|
||||
<ButtonGroup>
|
||||
<CenterInMyPosition onClick={viewport => this.centerOnUserLocation(viewport)} onlyIcon {... this.props} />
|
||||
</ButtonGroup>
|
||||
</Control>
|
||||
</MapControl>
|
||||
<FullScreenMap />
|
||||
</Map>
|
||||
</MapContainer>
|
||||
<Row>
|
||||
<Col xs={12} sm={12} md={12} lg={12}>
|
||||
<p className="firesmap-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