Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_featureWithinTimeRange() missing a case #1173

Closed
pjbiogit opened this issue Nov 7, 2019 · 3 comments
Closed

_featureWithinTimeRange() missing a case #1173

pjbiogit opened this issue Nov 7, 2019 · 3 comments

Comments

@pjbiogit
Copy link
Contributor

pjbiogit commented Nov 7, 2019

  • Browser and version:

All

  • Version of Leaflet (L.version):

1.5.1

  • Version of esri Leaflet (L.esri.VERSION):

2.3.1

I am using the time filtering ability of feature layers to filter specific layers by a start and end time on each field. For this, I have defined the timeField with both a start and an end and defined the layer as having a to and a from to be used as the time range over which a feature should appear.
The function featureWithinTimeRange(feature) , which I have copied below, is used to determine if a feature falls within a time range. When a feature has a start and end time it evaluates to true if either the start or end time of the feature falls within the layer's set time range. I believe that this is operating under the assumption that there are 5 cases:

  • A feature's start and end fall before the from time.
  • A feature's start falls before the from time and its end falls between from and to.
  • A feature's start and end times fall between the from and to times.
  • A feature's start time falls between the from and to times, and its end time falls after to.
  • A feature's start and end fall after the to time.

The middle three cases should evaluate to true, and are implemented in the code below:

_featureWithinTimeRange: function (feature) {
	    if (!this.options.from || !this.options.to) {
	      return true;
	    }

	    var from = +this.options.from.valueOf();
	    var to = +this.options.to.valueOf();

	    if (typeof this.options.timeField === 'string') {
	      var date = +feature.properties[this.options.timeField];
	      return (date >= from) && (date <= to);
	    }

	    if (this.options.timeField.start && this.options.timeField.end) {
	      var startDate = +feature.properties[this.options.timeField.start];
	      var endDate = +feature.properties[this.options.timeField.end];
	      return ((startDate >= from) && (startDate <= to)) || ((endDate >= from) && (endDate <= to));
	    }
	  },

However, I believe that there should be a sixth case:

  • The from and to times fall between the feature's start and end times.

In the current code, this will not evaluate to true, however in my application I would like the feature to persist over its entire time range even if the from and to represent a time within that range.
In this case, the final return statement would have one more or case as follows:
return ((startDate >= from) && (startDate <= to)) || ((endDate >= from) && (endDate <= to)) || ((startDate <= from) && (endDate >= to));
Please let me know if there was a reason to exclude this case and I can make the necessary changes to my own code to get the proper functionality that I'm looking for.
Thank you

@jgravois
Copy link
Contributor

jgravois commented Nov 7, 2019

thanks for the writeup @pjbiogit! a pull request with a fix would be welcome.

@pjbiogit
Copy link
Contributor Author

pjbiogit commented Nov 7, 2019

Pull request #1174

@jwasilgeo
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants