-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add menu for running secondary workflows
- Loading branch information
Showing
9 changed files
with
726 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"vuetify": { | ||
"v-text-field": { | ||
"density": "compact", | ||
"variant": "outlined" | ||
}, | ||
"v-container": { | ||
"class": "pa-0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template></template> | ||
|
||
<script setup lang="ts"> | ||
import { onBeforeUnmount, watch, onBeforeMount } from 'vue' | ||
import { | ||
GeoJSONStoreFeatures, | ||
TerraDraw, | ||
TerraDrawMapLibreGLAdapter, | ||
TerraDrawRectangleMode, | ||
} from 'terra-draw' | ||
import { useMap } from 'vue-maplibre-gl' | ||
import type { FeatureId } from 'node_modules/terra-draw/dist/store/store' | ||
interface Props { | ||
modelValue?: GeoJSONStoreFeatures[] | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
modelValue: () => [], | ||
}) | ||
const emit = defineEmits(['update:modelValue']) | ||
const { map } = useMap() | ||
if (!map) throw new Error('Map is not available to draw polygon') | ||
const mapLibreAdapter = new TerraDrawMapLibreGLAdapter({ map }) | ||
const rectangleMode = new TerraDrawRectangleMode({ | ||
styles: { | ||
fillColor: '#c2bebe', | ||
outlineColor: '#626262', | ||
outlineWidth: 2, | ||
fillOpacity: 0.4, | ||
}, | ||
}) | ||
const draw = new TerraDraw({ | ||
adapter: mapLibreAdapter, | ||
modes: [rectangleMode], | ||
}) | ||
draw.on('finish', (featureId) => { | ||
const features = draw.getSnapshot() | ||
const newFeature = features.find((feature) => feature.id === featureId) | ||
emit('update:modelValue', [newFeature]) | ||
}) | ||
draw.on('change', (featureIds, type) => { | ||
if (type == 'create') { | ||
if (!featureIds.length) return | ||
const newFeature = featureIds[0] | ||
removeAllFeaturesExcept(newFeature) | ||
} | ||
}) | ||
function removeAllFeaturesExcept(featureId: FeatureId) { | ||
const features = draw.getSnapshot() | ||
const toRemove = features | ||
.filter((feature) => feature.id !== featureId) | ||
.map((feature) => feature.id) | ||
draw.removeFeatures(toRemove as FeatureId[]) | ||
} | ||
onBeforeMount(() => { | ||
draw.start() | ||
draw.setMode('rectangle') | ||
}) | ||
onBeforeUnmount(() => { | ||
draw.setMode('static') | ||
draw.stop() | ||
}) | ||
watch( | ||
() => props.modelValue, | ||
() => { | ||
if (props.modelValue.length > 0) { | ||
draw.clear() | ||
draw.addFeatures(props.modelValue) | ||
} | ||
}, | ||
{ deep: true }, | ||
) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.