Skip to content

Reactivity of opacity in Layers.OlTileLayer broken in v11 #410

Closed
@vincerubinetti

Description

@vincerubinetti

Describe the bug

Put this into the current playground:

<template>
  {{ opacity }}
  <Map.OlMap style="height: 400px">
    <Map.OlView
      :center="center"
      :rotation="rotation"
      :zoom="zoom"
      projection="EPSG:4326"
    />

    <Layers.OlTileLayer :opacity="opacity">
      <Sources.OlSourceOsm />
    </Layers.OlTileLayer>
  </Map.OlMap>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { Layers, Map, Sources } from "vue3-openlayers";

const center = ref([40, 40]);
const zoom = ref(3);
const rotation = ref(0);
const opacity = ref(1);

setInterval(() => (opacity.value = Math.random()), 1000);
</script>

And it works, the tile layer opacity changes at random. I couldn't figure out why it wasn't working locally for me, then I noticed the Playground is still on v10. If you upgrade it to v11, the opacity is no longer reactive, it just stays whatever its initial value was.

P.S. The playground should really be updated, v11 has been out for several months.

Affected version(s)


I believe this warning I get in the console is related:

[Vue warn] toRefs() expects a reactive object but received a plain one.
setup	@	vue3-openlayers.js?v=5488eae0:76669

var _sfc_main$1b = defineComponent({
  __name: "OlTileLayer",
  props: mergeDefaults({
    className: {},
    opacity: {},
    visible: { type: Boolean },
    extent: {},
    zIndex: {},
    minResolution: {},
    maxResolution: {},
    minZoom: {},
    maxZoom: {},
    preload: {},
    source: {},
    map: {},
    useInterimTilesOnError: { type: Boolean },
    properties: {},
    cacheSize: {},
    openInLayerSwitcher: { type: Boolean },
    title: {},
    name: {},
    allwaysOnTop: { type: Boolean },
    baseLayer: { type: Boolean }
  }, useDefaults$1({
    preload: 1
  })),
  emits: ["sourceready", "change", "error", "propertychange", "change:extent", "change:maxResolution", "change:maxZoom", "change:minResolution", "change:minZoom", "change:opacity", "change:source", "change:visible", "change:zIndex", "postrender", "prerender", "change:useInterimTilesOnError", "change:preload"],
  setup(__props, { expose: __expose }) {
    const props = __props;
    const { layer } = useLayer(Tile_default4, toRefs({ ...props }), [ // <----------------------------
      "change:useInterimTilesOnError",
      "change:preload"
    ]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions