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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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