Comments (6)
REvent.tsx
:
componentDidUpdate(prevProps: Readonly<P>, prev: Readonly<unknown>, snap: unknown): void {
if (this.props !== prevProps) {
debug('willRefresh', this, prevProps, this.props);
this.refresh(prevProps);
}
}
Would a 1-level deep props comparison here help?
The code that exhibits the problematic WMTS refresh looks like this:
export default () => {
const [pinCoords, setPinCoords] = React.useState(initialPinCoord);
...
return (
...
<RMap className="..." ...>
<RLayerWMTS url="[fixed URL, never changes]" layer="..." />
<RLayerVector>
<RFeature feature={pinFeature}>...</RFeature>
</RLayerVector>
<RInteraction.RTranslate
features={new Collection([pinFeature])} // same feature as in the preceding vector layer
onTranslateEnd={React.useCallback((e: TranslateEvent) => {
setPinCoords(e.coordinate); // this causes the unwanted full WMTS layer refresh
}, [])}
/>
</RMap>
from rlayers.
I agree, but this isn't related to this PR, from what I see, it has always been like this since the WMTS layer appeared. Very few people use it, so I am not surprised. I can't simply skip the refresh because this is the base class for all layers. I will add a smarter prop change detection.
from rlayers.
What properties change in your case? The onSourceRedy
function? You can probably work around with useCallback
until I release a fix.
Everything else besides the callback really warrants a rerfesh.
from rlayers.
I agree, but this isn't related to this PR, from what I see, it has always been like this since the WMTS layer appeared. Very few people use it, so I am not surprised. I can't simply skip the refresh because this is the base class for all layers. I will add a smarter prop change detection.
The dysfunctional refresh is not related to the PR -- but that's just the first problem. The second problem where the source gets overwritten after it has been passed up is related to the PR -- the PR introduces a bug.
What properties change in your case?
That's the thing -- nothing directly related to the WMTS layer changes. The change is on state variable that isn't even used anywhere. That is enough to trigger a full map reload. I'm pasting the fully reproducible minimal code below.
from rlayers.
import React from "react";
import { fromLonLat, toLonLat } from "ol/proj";
import { Point } from "ol/geom";
import { Feature } from "ol";
import { Coordinate } from "ol/coordinate";
import "ol/ol.css";
import pin from "./pin.svg";
import {
RMap,
ROSM,
RInteraction,
RLayerVector,
RStyle,
RFeature,
RLayerWMTS,
} from "rlayers";
export const coords: Coordinate = [2.352, 48.861];
const coordsToString = (coords: any) => `${coords[1].toFixed(3)}:${coords[0].toFixed(3)}`;
export default function Interactions(): JSX.Element {
const [msg, setMsg] = React.useState("");
const [feature] = React.useState(new Feature({ geometry: new Point(fromLonLat(coords)) }));
return (
<React.Fragment>
<RMap
height="90vh"
className="example-map"
initial={{ center: fromLonLat(coords), zoom: 11 }}
>
{/*<ROSM />*/}
<RLayerWMTS
url="https://wxs.ign.fr/essentiels/geoportail/wmts?SERVICE=WMTS&REQUEST=GetCapabilities"
layer="GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2" />
<RLayerVector>
<RStyle.RStyle>
<RStyle.RIcon src={pin} />
</RStyle.RStyle>
<RFeature feature={feature}/>
</RLayerVector>
<RInteraction.RTranslate
onTranslating={React.useCallback((e: any) => {
const f = e.features.item(0);
const coords = toLonLat((f.getGeometry() as Point).getFirstCoordinate());
setMsg(`You placed the pin at ${coordsToString(coords)}`);
}, [])}
/>
</RMap>
{/*<div*/}
{/* className="mx-0 mt-0 mb-3 p-1 w-100 jumbotron shadow shadow"*/}
{/* dangerouslySetInnerHTML={{ __html: msg }}*/}
{/*/>*/}
</React.Fragment>
);
}
This is based loosely on your "Move & Select" example. I have intentionally commented out the div that uses the message which is being updated while moving the pin to demonstrate how nothing effectively changes, but the map is still fully reloaded. If you switch out the WMTS layer with ROSM, the problem disappears. Equivalently, if you manually remove the content of the RLayerWMTS.refresh
method (as mentioned, I'm automating this with patch-package
), the problem disappears. I don't see any way to work around this, except with monkey-patching the code with patch-package
.
from rlayers.
Now works as intended, thanks for the fix!
from rlayers.
Related Issues (20)
- Visible property is not handled in the RLayerWMTS component
- New feature: collapsible and collapsed props for RControl.RCustom
- How to get geometry from Interaction draw HOT 5
- getGeometry.getCoordinates has no parameters HOT 1
- Missing crossOrigin property in the RLayerTileWMS component HOT 2
- Gesture overlay and handling HOT 3
- Performance issues with RDraw HOT 4
- Support for tailwindcss? HOT 3
- Uncaught DOMException when removing an `ROverlay` HOT 1
- Change RCircle radius when zoom changes HOT 1
- How to add KML as layer vector HOT 1
- Remove last point event RDraw
- Typescript error cannot use Component as a JSX Component HOT 4
- persist map context HOT 1
- Snaping in interaction HOT 1
- How do I configure tileSize? HOT 1
- format problem in WMS WMTS HOT 4
- npm ERR! Could not resolve dependency: ol@"^8.0.0" and [email protected] HOT 1
- rlayers not supported for OpenLayers 8.0.0 HOT 4
- Is it possible to dinamically add/remove layer from RMAP? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rlayers.