angular-openlayers-directive
angular-openlayers-directive copied to clipboard
[feature request]Auto-zoom/pan on layer(s) features
My use case of your (excellent) directive requires being able to auto-zoom/pan on features contained in given layer(s). After reading the documentation, I couldn't find a way to achieve this without painful additions of code in my map controller. I'd love to see such feature (pun intended) available as an option to the layer directive (or should it be a sub-option to the openlayers ol-view parameter?).
After digging a bit in the openlayers documentation, I came with two ways to achieving this:
the first one is the easiest, yet not the one I prefer, and looks like this:
/* after markers addition/deletion lines */
if(isDefined(olScope.view.autofit) && olScope.view.autofit == true){
/* update map extent to fit all markers */
map.getView().fitExtent(markerLayer.getSource().getExtent(),map.getSize());
}
Obviously, we could make it more generic than this (it just works on the markers layer) but I guess the principle would remain the same.
The second one involves exposing events of layers' sources ol.Collections such as addFeature
, removeFeature
and so on. I guess the second may be more potent in terms of usage but may be an overkill for most users (basically letting them handle what to do when OpenLayers events are fired).
Thoughts?
For completeness, the directive should put a watch on the property, and react on toggle too.
That way, while the property is set, the map would zoom+pan as features are added/removed (but what about features changing position instead?) or when the autofit is momentarily set to true (which would be my use case btw, I don't need to zoom/pan automatically, but only per user request), but it would refrain from doing anything as soon as the property is set to false.
Another way to implement this would be for the ol-center directive to have bidirectional binding on the (optional) "bounds" property.
Can you guys provide a PR for this? Would be great :smile: