@@ -63,119 +63,99 @@ import SnapModifyDemo from "@demos/SnapModifyDemo.vue"
6363 </ol-map>
6464</template>
6565
66- <script>
66+ <script setup >
6767import { ref, inject } from "vue";
6868import { GeoJSON } from "ol/format";
6969import { Fill, Stroke, Style } from "ol/style";
7070import { Collection } from "ol";
71- export default {
72- setup() {
73- const map = ref("");
74- const center = ref([-102.13121, 40.2436]);
75- const projection = ref("EPSG:4326");
76- const zoom = ref(5);
77- const rotation = ref(0);
78- const modifyEnabled = ref(false);
79- const drawEnabled = ref(false);
80-
81- const geojsonObject = {
82- type: "FeatureCollection",
83- crs: {
84- type: "name",
85- properties: {
86- name: "EPSG:4326",
87- },
88- },
89- features: [
90- {
91- type: "Feature",
92- geometry: {
93- type: "Polygon",
94- coordinates: [
95- [
96- [-103.86923852630616, 43.45599322423934],
97- [-103.90891107984544, 39.34240191087722],
98- [-98.76630637117387, 39.558687199211114],
99- [-98.89435771175386, 43.945405844902986],
100- [-103.86923852630616, 43.45599322423934],
101- ],
102- ],
103- },
104- },
105- {
106- type: "Feature",
107- geometry: {
108- type: "Polygon",
109- coordinates: [
110- [
111- [-103.85636392303468, 38.10970692739486],
112- [-103.86770698495866, 33.218572724914544],
113- [-98.20654544301988, 33.6532810221672],
114- [-98.4408283538437, 38.31894739375114],
115- [-103.85636392303468, 38.10970692739486],
116- ],
117- ],
118- },
119- },
120- ],
121- };
122-
123- const zones = ref([]);
124- const selectedFeatures = ref(new Collection());
125-
126- const drawend = (event) => {
127- zones.value.push(event.feature);
128- selectedFeatures.value.push(event.feature);
129-
130- modifyEnabled.value = true;
131- drawEnabled.value = false;
132- };
133-
134- zones.value = new GeoJSON().readFeatures(geojsonObject);
135-
136- function vectorStyle() {
137- const style = new Style({
138- stroke: new Stroke({
139- color: "blue",
140- width: 3,
141- }),
142- fill: new Fill({
143- color: "rgba(0, 0, 255, 0.4)",
144- }),
145- });
146- return style;
147- }
148-
149- const geoJsonFormat = new GeoJSON();
150- const selectConditions = inject("ol-selectconditions");
151- const selectCondition = selectConditions.click;
152-
153- function featureSelected(event) {
154- modifyEnabled.value = false;
155- if (event.selected.length > 0) {
156- modifyEnabled.value = true;
157- }
158- selectedFeatures.value = event.target.getFeatures();
159- }
160-
161- return {
162- map,
163- vectorStyle,
164- geoJsonFormat,
165- featureSelected,
166- selectCondition,
167- zones,
168- center,
169- projection,
170- zoom,
171- rotation,
172- modifyEnabled,
173- drawEnabled,
174- drawend,
175- selectedFeatures,
176- };
71+
72+ const map = ref("");
73+ const center = ref([-102.13121, 40.2436]);
74+ const projection = ref("EPSG:4326");
75+ const zoom = ref(5);
76+ const rotation = ref(0);
77+ const modifyEnabled = ref(false);
78+ const drawEnabled = ref(false);
79+
80+ const geojsonObject = {
81+ type: "FeatureCollection",
82+ crs: {
83+ type: "name",
84+ properties: {
85+ name: "EPSG:4326",
86+ },
17787 },
88+ features: [
89+ {
90+ type: "Feature",
91+ geometry: {
92+ type: "Polygon",
93+ coordinates: [
94+ [
95+ [-103.86923852630616, 43.45599322423934],
96+ [-103.90891107984544, 39.34240191087722],
97+ [-98.76630637117387, 39.558687199211114],
98+ [-98.89435771175386, 43.945405844902986],
99+ [-103.86923852630616, 43.45599322423934],
100+ ],
101+ ],
102+ },
103+ },
104+ {
105+ type: "Feature",
106+ geometry: {
107+ type: "Polygon",
108+ coordinates: [
109+ [
110+ [-103.85636392303468, 38.10970692739486],
111+ [-103.86770698495866, 33.218572724914544],
112+ [-98.20654544301988, 33.6532810221672],
113+ [-98.4408283538437, 38.31894739375114],
114+ [-103.85636392303468, 38.10970692739486],
115+ ],
116+ ],
117+ },
118+ },
119+ ],
178120};
121+
122+ const zones = ref([]);
123+ const selectedFeatures = ref(new Collection());
124+
125+ const drawend = (event) => {
126+ zones.value.push(event.feature);
127+ selectedFeatures.value.push(event.feature);
128+
129+ modifyEnabled.value = true;
130+ drawEnabled.value = false;
131+ };
132+
133+ zones.value = new GeoJSON().readFeatures(geojsonObject);
134+
135+ function vectorStyle() {
136+ const style = new Style({
137+ stroke: new Stroke({
138+ color: "blue",
139+ width: 3,
140+ }),
141+ fill: new Fill({
142+ color: "rgba(0, 0, 255, 0.4)",
143+ }),
144+ });
145+ return style;
146+ }
147+
148+ const geoJsonFormat = new GeoJSON();
149+ const selectConditions = inject("ol-selectconditions");
150+ const selectCondition = selectConditions.click;
151+
152+ function featureSelected(event) {
153+ modifyEnabled.value = false;
154+ if (event.selected.length > 0) {
155+ modifyEnabled.value = true;
156+ }
157+ selectedFeatures.value = event.target.getFeatures();
158+ }
179159</script>
180160```
181161
0 commit comments