Skip to content

Commit

Permalink
refactor: make heatmapLayer and vectorLayer not a ref
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
potentially exposed `layer`, `heatmapLayer` and `vectorLayer` are not refs anymore.
They can now be used without the need of `.value`
  • Loading branch information
d-koppenhagen committed Jun 7, 2023
1 parent 776e72d commit f6dca4c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/layers/OlAnimatedClusterLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ watch(properties, () => {
});
onMounted(() => {
map.addLayer(vectorLayer.value);
map.addLayer(vectorLayer);
vectorLayer.value.changed();
map.changed();
});
onUnmounted(() => {
map.removeLayer(vectorLayer.value);
map.removeLayer(vectorLayer);
});
provide("vectorLayer", source);
Expand Down
10 changes: 5 additions & 5 deletions src/components/layers/OlVectorLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script setup>
import { inject, provide, onUnmounted, onMounted, watch, computed } from "vue";
import { inject, provide, onUnmounted, onMounted, watch } from "vue";
import VectorLayer from "ol/layer/Vector";
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
Expand Down Expand Up @@ -34,18 +34,18 @@ const map = inject("map");
const { properties } = usePropsAsObjectProperties(props);
const vectorLayer = computed(() => new VectorLayer(properties));
const vectorLayer = new VectorLayer(properties);
watch(properties, () => {
vectorLayer.value.setProperties(properties);
vectorLayer.setProperties(properties);
});
onMounted(() => {
map.addLayer(vectorLayer.value);
map.addLayer(vectorLayer);
});
onUnmounted(() => {
map.removeLayer(vectorLayer.value);
map.removeLayer(vectorLayer);
});
provide("vectorLayer", vectorLayer);
Expand Down
2 changes: 1 addition & 1 deletion src/components/map/OlFeature.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ watch(vectorSource, (newVal, oldVal) => {
onMounted(() => {
vectorSource.value.addFeature(feature.value);
if (animation != null) {
vectorLayer.value.animateFeature(feature.value, animation.value);
vectorLayer.animateFeature(feature.value, animation.value);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/mapControls/OlAttributionControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script setup>
import { Attribution } from "ol/control";
import useControl from "@/composables/useControl";
import { useAttrs, useSlots } from "vue";
import { useAttrs } from "vue";
const props = defineProps({
className: {
Expand Down
10 changes: 5 additions & 5 deletions src/components/sources/OlSourceVector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const { properties } = usePropsAsObjectProperties(props);
const source = computed(() => new VectorSource(properties));
const applySource = () => {
layer.value.setSource(null);
layer.value.setSource(source.value);
layer.value.changed();
layer.setSource(null);
layer.setSource(source.value);
layer.changed();
};
watch(properties, () => {
applySource();
Expand All @@ -70,11 +70,11 @@ watch(layer, () => {
});
onMounted(() => {
layer.value.setSource(source.value);
layer.setSource(source.value);
});
onUnmounted(() => {
layer.value.setSource(null);
layer.setSource(null);
});
provide("vectorSource", source);
Expand Down
2 changes: 1 addition & 1 deletion src/composables/usePropsAsObjectProperties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toRefs, watch, reactive, type ToRefs, ref, type Ref } from "vue";
import { toRefs, watch, reactive, type ToRefs, ref } from "vue";

/**
* We can't use 'style' as a component prop since it's a reserved property
Expand Down
2 changes: 1 addition & 1 deletion src/demos/ImageWMSDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ol-map>
</template>

<script>
<script setup>
import { ref } from "vue";
const zoom = ref(4);
Expand Down
1 change: 0 additions & 1 deletion src/demos/SnapModifyDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function vectorStyle() {
return style;
}
const geoJsonFormat = new GeoJSON();
const selectConditions = inject("ol-selectconditions");
const selectCondition = selectConditions.click;
Expand Down

0 comments on commit f6dca4c

Please sign in to comment.