|
9 | 9 | :center="center"
|
10 | 10 | :zoom="zoom"
|
11 | 11 | :projection="projection"
|
| 12 | + :constrainRotation="16" |
12 | 13 | />
|
13 | 14 |
|
14 |
| - <ol-tile-layer> |
15 |
| - <ol-source-osm /> |
16 |
| - </ol-tile-layer> |
17 |
| - |
18 |
| - <ol-vector-layer> |
19 |
| - <ol-source-vector :url="url" :format="geoJson"> </ol-source-vector> |
| 15 | + <ol-vector-layer background="#1a2b39" ref="vectorSourceRef"> |
| 16 | + <ol-source-vector :url="url" :format="geoJson"> |
| 17 | + <ol-style :overrideStyleFunction="styleFn"></ol-style> |
| 18 | + </ol-source-vector> |
20 | 19 | </ol-vector-layer>
|
| 20 | + |
| 21 | + <ol-interaction-dragbox |
| 22 | + :condition="shiftKeyOnly" |
| 23 | + @boxstart="log('boxstart', $event)" |
| 24 | + @boxdrag="log('boxdrag', $event)" |
| 25 | + @boxend="log('boxend', $event)" |
| 26 | + @boxcancel="log('boxcancel', $event)" |
| 27 | + ></ol-interaction-dragbox> |
21 | 28 | </ol-map>
|
22 | 29 | </template>
|
23 | 30 |
|
24 |
| -<script setup> |
| 31 | +<script setup lang="ts"> |
| 32 | +import type { Feature } from "ol"; |
| 33 | +import { Fill, Style } from "ol/style"; |
| 34 | +import { shiftKeyOnly } from "ol/events/condition"; |
25 | 35 | import { ref, inject } from "vue";
|
| 36 | +import type { DragBoxEvent } from "ol/interaction/DragBox"; |
26 | 37 |
|
27 | 38 | const center = ref([0, 0]);
|
28 | 39 | const projection = ref("EPSG:4326");
|
29 |
| -const zoom = ref(3); |
30 |
| -
|
| 40 | +const zoom = ref(0); |
31 | 41 | const url = ref("https://openlayers.org/data/vector/ecoregions.json");
|
32 | 42 | const format = inject("ol-format");
|
33 | 43 | const geoJson = new format.GeoJSON();
|
| 44 | +
|
| 45 | +function styleFn(feature: Feature) { |
| 46 | + return new Style({ |
| 47 | + fill: new Fill({ |
| 48 | + color: feature.get("COLOR_BIO") || "#eeeeee", |
| 49 | + }), |
| 50 | + }); |
| 51 | +} |
| 52 | +
|
| 53 | +function log(eventType: string, event: DragBoxEvent) { |
| 54 | + console.log(eventType, event); |
| 55 | +} |
34 | 56 | </script>
|
0 commit comments