-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create ol-style-regular-shape for square points. #267
Labels
Comments
This is how I draw triangles:
and then:
I hope this helps. |
Thx, it helps but could be good to have ol-style-regular-shape as a component. I created this one but It is not a good solution :
<template>
<slot></slot>
</template>
<script setup>
import RegularShapeStyle from "ol/style/RegularShape";
import Fill from "ol/style/Fill";
import Stroke from "ol/style/Stroke";
import {
inject,
watch,
onMounted,
onUnmounted,
provide,
computed,
reactive,
toRefs,
ref
} from "vue";
function checkAndUpdateStylePropDef(options, key) {
if (key === "styles") {
options.style = ref(options[key].value);
}
}
function usePropsAsObjectProperties(props, ignoredKeys = []) {
const globalOptions = inject("ol-options");
let options = toRefs(props);
Object.keys(options).forEach((key) => {
checkAndUpdateStylePropDef(options, key);
options[key] = options[key].value;
});
const properties = reactive({ ...options });
watch(props, () => {
options = toRefs(props);
Object.keys(options).forEach((key) => {
if (properties[key] != options[key].value && !ignoredKeys.includes(key)) {
checkAndUpdateStylePropDef(options, key);
properties[key] = options[key].value;
}
});
});
if (globalOptions == null ? void 0 : globalOptions.debug) {
console.debug("[Vue3-OpenLayers Debug] PROPS", {
in: props,
out: properties
});
}
return {
properties
};
}
const props = defineProps({
radius: {
type: Number,
default: undefined
},
points: {
type: Number,
required: true
},
scale: {
type: Number,
default: undefined
},
rotation: {
type: Number,
default: 0
}
});
const style = inject("style", null);
const styledObj = inject("styledObj", null);
const { properties } = usePropsAsObjectProperties(props);
const createRegularShapeStyle = (innerProperties) => {
const rss = new RegularShapeStyle({
...innerProperties,
stroke: new Stroke({}),
fill: new Fill()
});
rss.setRadius = function setRadius() {
this.render();
};
return rss;
};
const regularShape = computed(() => createRegularShapeStyle(properties));
const applyStyle = () => {
style?.value?.setImage(null);
style?.value?.setImage(regularShape.value);
styledObj?.value?.changed();
};
watch(properties, () => {
applyStyle();
});
watch(
() => style,
() => {
applyStyle();
}
);
onMounted(() => {
style?.value?.setImage(regularShape.value);
});
onUnmounted(() => {
// @ts-ignore
style?.value?.setImage(null);
});
provide("circle", regularShape);
provide("styledObj", styledObj);
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I just wanted a square point but ol-style-regular-shape don't exists.
Describe the solution you'd like
Add support of ol-style-regular-shape
Describe alternatives you've considered
Using Icon.
Thx
The text was updated successfully, but these errors were encountered: