mmomtchev/rlayers

RLayerWMTS fetches the wmts file twice

Closed this issue · 4 comments

rrelmy commented

The RLayerWMTS always fetches the WMTS file twice when added to a map.

This is also visible in the Reprojection example which uses a wmts layer.

rrelmy commented

As a workaround and to implement global caching I reimplemnted RLayerWMTSCached class, unfortunately I had to duplicate the createSource() method.

protected createSource(): Promise<SourceWMTS> {

My workaround:

export default class RLayerWMTSCached extends RLayerWMTS {
  protected fetchSource(url: string) {
    if (!(url in CACHED_WMTS)) {
      CACHED_WMTS[url] = fetch(url).then((r) => r.text());
    }

    return CACHED_WMTS[url];
  }

  protected createSource(): Promise<SourceWMTS> {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    return this.fetchSource(this.props.url)
      .then((text) => {
        const caps: unknown = this.parser.read(text);
// … duplicated code

It would be nice to have a separate method like fetchSource(url: string) that could be used to override the fetching with custom logic.

Are you sure this happens in production mode? React refreshes the component in dev mode on purpose - to make sure that everything works correctly.

rrelmy commented

@mmomtchev Yes, in the dev mode is fetches the WMTS four times.
I verified it with our own application, the same happens on the rlayers examples (I assume these are not running in dev-mode either)

In case you haven't seen my profile, I am currently living on social welfare because an ex-employer is extorting me with the help of the French police and the French judiciary over a series of false judicial proceedings, including some very serious allegations, in order to cover up his intimate personal problem. In order to further intimidate me, people are simultaneously posting on my projects. Yours is one. You don't happen to know anything about this affair?