tombatossals/angular-openlayers-directive

Ways to refresh a vector layer

Closed this issue · 3 comments

Hello,

Currently we are facing an issue where we are only able to refresh a layer based on the "active" property.

Lets say our html GeoJSON layer is like this:

<ol-layer ng-if="layer.active" ng-repeat="layer in layers" ol-layer-properties="layer"></ol-layer>

and the config is like this:

{
	clustering: true,
	active: false,
	name: 'vector_layer',
	source: {
		type: 'GeoJSON',
			geojson: {
				object: {
					"type": "FeatureCollection",
					"features": []
				}
			}
		},
		style: function(groupFeature) {
			// Based on external javascript object properties
		},
		click: function(event, feature) {
			// Based on external javascript object properties
		},
		mousemove: function(event, feature) {
			// Based on external javascript object properties
		},
	}
}

And we want to change either the feature set or the appearance of features of the layer, we are currently only able to do it by setting the active property on the layer to false and back to true, which leads to flickering of the layer.

Are there any other ways we can achieve a redraw of the layer features without disabling the layer from view and adding it back?

Regards

Hi @wcoebergh, I'm not sure whether there is a way to do this yet. We would probably have to implement such a way to synchronize these changes.

What you could do though at the moment is to call through to the native openlayers api, for example:

olData.getMap().then(function(map) {
    // map is the native ol3 map object, so
    // all those APIs can be used

    var layers = map.getLayers();
    // iterate over "layers" and pick out the layer of interest
});

once you have the layer of interest, you could directly adjust the properties such as the features, styles etc.

Hi, thanks for the reply. I have considered that as well, takes away a little the use of this directive though :) I'll see what I can do to make it work, thanks!

👍 in case feel free to discuss a possible PR 😄