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

Optimize canvas hit detection by rendering features in a limited extent #3072

Merged
merged 1 commit into from
Jan 8, 2015
Merged

Optimize canvas hit detection by rendering features in a limited extent #3072

merged 1 commit into from
Jan 8, 2015

Conversation

tschaub
Copy link
Member

@tschaub tschaub commented Dec 20, 2014

Inspired by @tsauerwein's work in #3065, this adds an optimization for hit detection with the Canvas renderer. Features are only considered for hit checking if their extent intersects a buffered extent around the provided coordinate - using the buffer from the new renderBuffer property for vector layers (see #3061).

In some unscientific benchmarking, it looks like this cuts the hit detection time by up to 50% (~2.3ms v. ~4.9ms in the vector layer example and ~9ms v. ~16ms in the synthetic points example in worst case scenarios).

*/
var hitExtent;
if (goog.isDef(this.renderBuffer_)) {
hitExtent = ol.extent.boundingExtent([coordinate]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use

/**
 * @type {ol.Extent}
 */
var hitExtent;
if (goog.isDef(this.renderBuffer_)) {
  hitExtent = ol.extent.createEmpty();
  ol.extent.extendCoordinate(hitExtent, coordinate);
  ol.extent.buffer(hitExtent, resolution * this.renderBuffer_, hitExtent);
}

and thereby avoid creating an extra array. Minor.

@tsauerwein
Copy link
Member

Thanks for taking care of this! Your change looks good to me.

@tschaub tschaub added this to the v3.2.0 milestone Dec 22, 2014
@tschaub
Copy link
Member Author

tschaub commented Jan 8, 2015

@elemoine did you want to give this another look? @tsauerwein and I agree it is good to go.

@elemoine
Copy link
Member

elemoine commented Jan 8, 2015

Where are the tests? ;-) Just kidding. I don't really think this needs tests at this point. Please merge.

tschaub added a commit that referenced this pull request Jan 8, 2015
Optimize canvas hit detection by rendering features in a limited extent.
@tschaub tschaub merged commit b952f11 into openlayers:master Jan 8, 2015
@tschaub tschaub deleted the hit-extent branch January 8, 2015 06:54
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

Successfully merging this pull request may close these issues.

None yet

3 participants