-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Possibility to restrict the type of features you can select #3277
Conversation
* @private | ||
* @type {ol.interaction.SelectFilterFunction} | ||
*/ | ||
this.filter_ = goog.isDef(options.filter) ? options.filter : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new filter
option needs to be added to olx.interaction.SelectOptions
. See the externs/olx.js
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could change this to:
this.filter_ = goog.isDef(options.filter) ? options.filter : goog.functions.TRUE;
and thereby avoid testing that this.filter_
is defined in the handleEvent
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tip. I just start reading "Closure the definite guide".
… the SelectFilterFunction
… the SelectFilterFunction
@@ -150,7 +167,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) { | |||
* @param {ol.layer.Layer} layer Layer. | |||
*/ | |||
function(feature, layer) { | |||
selected.push(feature); | |||
if (goog.isFunction(filter) && filter(feature, layer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the isFunction
test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
Updated PR with the @elemoine comments. Added documentation to the Although the In addition, I have added a second parameter to the |
if (types === null) { | ||
return true; | ||
} else { | ||
return goog.array.contains(types, feature.getGeometry().getType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use goog
functions in ol3 examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use indexOf
.
@acanimal, I don't think we need a new example for that new option. |
/** | ||
* A function that takes an {@link ol.Feature} and an {ol.layer.Layer} and | ||
* returns true if the feature may be selected or false otherwise. | ||
* @typedef {function(ol.Feature, ol.layer.Layer): boolean} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@typedef
- > @type
. And why don't you use ol.interaction.SelectFilterFunction
here too?
We don't have a typedef for the layer filter so I think I'd drop the typedef entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, mistake copy&paste. Now apidoc is generated fine.
I think sample can help to show how to use the property. Anyway the property is so trivial that can be removed. Simply confirm me and I will remove. I vote for not removing :) |
@acanimal, yes, using the new |
Sample removed. |
Did you see my other comments? |
Strange, I didn't receive any notification to my email. |
@acanimal Sorry for that. Your pull request cannot be merged without conflicts, this is why it did not get merged yet. Also, it did not have a milestone assigned, so I did not wait for it when I created the release yesterday. But since we have a monthly release schedule, I'm assigning it the 3.4.0 milestone now. So if you are able to resolve the conflicts, we can merge your pull request and it will be in the next release. |
I though the conflict was due the addition of #3018, Thanks |
@ahocevar Merge done |
Have you seen @elemoine's last comment? |
Sorry for the late reply. Yes, I just uploaded the modified code using |
This feature is important for a project I'm currently working on. Very much looking forward to it being available in 3.4.0. Thanks to those involved. |
@elemoine, are your concerns addressed now? |
LGTM. I just think we should squash the commits into one before merging. I will do that myself this morning, and create a new PR. |
@@ -27,6 +27,15 @@ ol.SelectEventType = { | |||
}; | |||
|
|||
|
|||
/** | |||
* A function that takes an {@link ol.Feature} and an {ol.layer.Layer} and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link for ol.layer.Layer
should be
{@link ol.layer.Layer}
- missing the @link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Thanks for catching this.
Hi, Cheers. |
@acanimal it needs a rebase at least, not sure if there are any other reasons. |
fixed with #3402 ? |
Yes. |
See #3257 issue.
This PR includes samples and also an initial implementation based on a new
filter
property which accepts aol.interaction.SelectFilterFunction
invoked for each selected feature and that determines if the feature must be selected or not.