Skip to content

Commit

Permalink
refactor(ol-map): use default values from OpenLayers
Browse files Browse the repository at this point in the history
BREAKING CHANGES:
- *`ol-map`*: properties with default values are now aligned with all [default values from OpenLayers](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html)
  • Loading branch information
d-koppenhagen committed Sep 19, 2023
1 parent 71dc005 commit 8685ea7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 85 deletions.
41 changes: 7 additions & 34 deletions docs/componentsguide/map/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,16 @@ See also documentation of `ol-view` component.

:::

## Properties
### Props from OpenLayers

### loadTilesWhileAnimating
Properties are passed-trough from OpenLayers directly.
Their types and default values can be checked-out [in the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
Only some properties deviate caused by reserved keywords from Vue / HTML.
This deviating props are described in the section below.

- **Type**: `boolean`
- **Default**: `false`
### Deviating Properties

When set to `true`, tiles will be loaded during animations.

### loadTilesWhileInteracting

- **Type**: `boolean`
- **Default**: `false`

When set to `true`, tiles will be loaded while interacting with the map.

### mouseWheelZoom

- **Type**: `boolean`
- **Default**: `true`

When set to `false`, zooming by using the mouse wheel is disabled.

### moveTolerance

- **Type**: `number`
- **Default**: `1`

The minimum distance in pixels the cursor must move to be detected as a map move
event instead of a click. Increasing this value can make it easier to click on the map.

### pixelRatio

- **Type**: `number`
- **Default**: `1`

The ratio between physical pixels and device-independent pixels (dips) on the device.
None.

## Events

Expand Down
55 changes: 4 additions & 51 deletions src/components/map/OlMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
<script setup lang="ts">
import { ref, provide, onMounted, onUnmounted, watch } from "vue";
import type { AtPixelOptions } from "ol/Map";
import Map from "ol/Map";
import { defaults } from "ol/interaction/defaults";
import type Collection from "ol/Collection";
import type Control from "ol/control/Control";
import Map, { type MapOptions } from "ol/Map";
import type { FeatureLike } from "ol/Feature";
import type { SimpleGeometry } from "ol/geom";
import type LayerRenderer from "ol/renderer/Layer";
Expand All @@ -20,41 +17,7 @@ import type { Source } from "ol/source";
import type { Coordinate } from "ol/coordinate";
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
const props = withDefaults(
defineProps<{
controls?: Collection<Control> | Control[] | undefined;
pixelRatio?: number | undefined;
loadTilesWhileAnimating?: boolean;
loadTilesWhileInteracting?: boolean;
moveTolerance?: number;
altShiftDragRotate?: boolean;
onFocusOnly?: boolean;
doubleClickZoom?: boolean;
keyboard?: boolean;
mouseWheelZoom?: boolean;
shiftDragZoom?: boolean;
dragPan?: boolean;
pinchRotate?: boolean;
pinchZoom?: boolean;
}>(),
{
loadTilesWhileAnimating: false,
loadTilesWhileInteracting: false,
moveTolerance: 1,
pixelRatio: 1,
controls: undefined,
altShiftDragRotate: true,
onFocusOnly: true,
doubleClickZoom: true,
keyboard: true,
mouseWheelZoom: true,
shiftDragZoom: true,
dragPan: true,
pinchRotate: true,
pinchZoom: true,
}
);
const props = defineProps<MapOptions>();
const emit = defineEmits([
"click",
Expand All @@ -72,20 +35,10 @@ const emit = defineEmits([
const { properties } = usePropsAsObjectProperties(props);
const mapRef = ref<string | HTMLElement | undefined>(undefined);
let map: Map | undefined = new Map({
...properties,
interactions: defaults({
...properties,
}),
});
let map: Map | undefined = new Map(properties);
watch(properties, () => {
map?.setProperties({
...properties,
interactions: defaults({
...properties,
}),
});
map?.setProperties(properties);
});
onMounted(() => {
Expand Down

0 comments on commit 8685ea7

Please sign in to comment.