|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <slot></slot> |
| 4 | + </div> |
| 5 | +</template> |
| 6 | + |
| 7 | +<script setup> |
| 8 | +import { inject, watch, onUnmounted, onMounted, computed } from "vue"; |
| 9 | +
|
| 10 | +import FlowLine from "ol-ext/style/FlowLine"; |
| 11 | +import Draw from "ol/interaction/Draw"; |
| 12 | +import Modify from "ol/interaction/Modify"; |
| 13 | +import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties"; |
| 14 | +
|
| 15 | +const props = defineProps({ |
| 16 | + color: { |
| 17 | + type: [String, Function], |
| 18 | + }, |
| 19 | + color2: { |
| 20 | + type: String, |
| 21 | + }, |
| 22 | + width: { |
| 23 | + type: [Number, Function], |
| 24 | + }, |
| 25 | + width2: { |
| 26 | + type: Number, |
| 27 | + }, |
| 28 | + arrow: { |
| 29 | + type: Number, |
| 30 | + }, |
| 31 | + arrowColor: { |
| 32 | + type: String, |
| 33 | + }, |
| 34 | +}); |
| 35 | +
|
| 36 | +const styledObj = inject("stylable", null); |
| 37 | +
|
| 38 | +const { properties } = usePropsAsObjectProperties(props); |
| 39 | +
|
| 40 | +const style = computed(() => new FlowLine(properties)); |
| 41 | +
|
| 42 | +const setStyle = (val) => { |
| 43 | + if (styledObj instanceof Draw || styledObj instanceof Modify) { |
| 44 | + styledObj.getOverlay().setStyle(val); |
| 45 | + styledObj.value.dispatchEvent("styleChanged"); |
| 46 | + return; |
| 47 | + } |
| 48 | + try { |
| 49 | + styledObj.value.setStyle(val); |
| 50 | + styledObj.value.changed(); |
| 51 | + styledObj.value.dispatchEvent("styleChanged"); |
| 52 | + } catch (error) { |
| 53 | + styledObj.value.style_ = val; |
| 54 | + styledObj.value.values_.style = val; |
| 55 | +
|
| 56 | + styledObj.value.changed(); |
| 57 | + styledObj.value.dispatchEvent("styleChanged"); |
| 58 | + } |
| 59 | +}; |
| 60 | +
|
| 61 | +const styleFunc = computed(() => { |
| 62 | + return (feature) => { |
| 63 | + if (properties.overrideStyleFunction != null) { |
| 64 | + properties.overrideStyleFunction(feature, style.value); |
| 65 | + } |
| 66 | + return style.value; |
| 67 | + }; |
| 68 | +}); |
| 69 | +
|
| 70 | +watch(properties, () => { |
| 71 | + if (properties.overrideStyleFunction == null) { |
| 72 | + setStyle(style.value); |
| 73 | + } else { |
| 74 | + setStyle(styleFunc.value); |
| 75 | + } |
| 76 | +}); |
| 77 | +
|
| 78 | +onMounted(() => { |
| 79 | + if (properties.overrideStyleFunction == null) { |
| 80 | + setStyle(style.value); |
| 81 | + } else { |
| 82 | + setStyle(styleFunc.value); |
| 83 | + } |
| 84 | +}); |
| 85 | +
|
| 86 | +onUnmounted(() => { |
| 87 | + setStyle(null); |
| 88 | +}); |
| 89 | +
|
| 90 | +defineExpose({ |
| 91 | + style, |
| 92 | +}); |
| 93 | +</script> |
| 94 | + |
| 95 | +<style lang=""></style> |
0 commit comments