socib / Leaflet.TimeDimension

Add time dimension capabilities on a Leaflet map.
MIT License
435 stars 139 forks source link

Fix obtaining times from GetCapabilities request #148

Closed victorzinho closed 4 years ago

victorzinho commented 6 years ago

There is a problem when getting time dimensions from a layer that doesn't have time instances when there's a different one in the server that has them. For example, with this GetCapabilities document:

<WMT_MS_Capabilities>
  ...
  <Capability>
    ...
    <Layer>
      ...
      <Layer queryable="1" opaque="0">
        <Name>no_timestamps</Name>
        ...
      </Layer>
      <Layer queryable="1" opaque="0">
        <Name>with_timestamps</Name>
        ...
        <Dimension name="time" units="ISO8601"/>
        <Extent name="time" default="0/9999">1984-12-31T22:00:00.000Z,1985-12-31T22:00:00.000Z</Extent>
      </Layer>
    </Layer>
  </Capability>
</WMT_MS_Capabilities>

if I use the no_timestamps layer with the plugin and try to obtain the time instances from the document, it doesn't find it in the layer and checks the parent with querySelectorAll, which searches the whole tree returning the time instances for the layer with_timestamps.

My fix searches only immediate children with Array.from(layer.children).filter(...) so we only have time instances if they really belong to the layer.

t-book commented 6 years ago

@bielfrontera Do you have time to review this PR?

bielfrontera commented 5 years ago

Hi @t-book and @victorzinho, thanks for your PR and apologies for the delayed response (I'm back to this project after a temporary leave).

Could you search an alternative to Array.from? It does not work in Internet Explorer and I'd want to maintain the support to this browser until Leaflet does.

And I will merge the changes in the source files and discard the changes in dist files (they are modified with the release of a new version).

bielfrontera commented 4 years ago

Could you search an alternative to Array.from? It does not work in Internet Explorer and I'd want to maintain the support to this browser until Leaflet does.

I've merged the PR but removing the Array.from and using an alternative to get the correct node (see cc21f7a)