Git Product home page Git Product logo

Comments (6)

Irfy avatar Irfy commented on June 4, 2024

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.

mmomtchev avatar mmomtchev commented on June 4, 2024

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.

mmomtchev avatar mmomtchev commented on June 4, 2024

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.

Irfy avatar Irfy commented on June 4, 2024

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.

Irfy avatar Irfy commented on June 4, 2024
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.

Irfy avatar Irfy commented on June 4, 2024

Now works as intended, thanks for the fix!

from rlayers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.