Skip to content

OL layer properties are no longer reactive #365

@fschmenger

Description

@fschmenger

It seems that lately vue-bindings to layer.getProperties() or via the layer.get('someProperty') will not get updated. Particularly puzzling is, that it seems to work for all layers added in the 1st generation, i.e. those configured statically in app.conf but not for those added dynamically in a later cycle.

To see an example: Create a drag drop layer (e.g. download GeoJSON from https://openlayers.org/en/latest/examples/drag-and-drop.html) and open the layer list module. Then switch the active language. The drag drop layer is localized and supposed to switch its language, however only the "static" wegue layers will receive the update.

The related code in LayerListItem looks like

<v-list-item-title>
        {{ layer.get('name') }}
</v-list-item-title>

Neither does it work via getProperties() if you alter the code above to

<v-list-item-title>
        {{ layer.getProperties().name }}
 </v-list-item-title>

or by using explicit computed properties, etc.

Note that some other components, i.e. the AttributeTable will still update the layer name. This is just a happy circumstance because they use other localized attributes in the same block, causing the whole thing to re-render.

Trying to track it down I rolled Wegue all the way back to v1.2.1 to finally see it working. However, if I delete the package-lock.json and do a full reinstall of dependencies, then the functionality is broken even back then.

A workaround could be to register for layer propertychange events and then manage our own binding targets, e.g.

layer.on('propertychange', (evt) => {
   if (evt.key === 'name') {
       this.layerName = layer.get('name')
  }
});

We used to have something like this in a very old version of Wegue but it would be cumbersome to reintroduce it and hunt down all code blocks where a binding to layer properties occurs.

Any ideas on the underlying cause and what to do about it?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions