ol-interaction-synchronize
Synchronize interaction from ol-ext that allows synchronizing multiple maps
Demo
Setup
Plugin usage
This component is part of the Interactions plugin. If not installed globally, you need to import and use the plugin in your main.ts or use the explicit component import (see section below).
Import and use the Interactions plugin
ts
import { createApp } from "vue";
import App from "./App.vue";
import {
Map,
Layers,
Sources,
Interactions,
} from "vue3-openlayers";
const app = createApp(App);
// ...
app.use(Interactions);
// ...Explicit import
If you don't want to install a plugin, you can import the component explicitly. It's available as a child of the named export Interactions.
NOTE
The following documentation refers to the plugin usage. Please make sure to adopt the component names, when you decided to use explicit component imports (e. g. <ol-map> becomes <Map.OlMap> etc.).
Usage
| Plugin Usage | Explicit Import |
|---|---|
<ol-interaction-synchronize> | <Interactions.OlInteractionSynchronize> |
vue
<template>
<div style="display: flex; gap: 10px;">
<div style="width: 400px; height: 300px;">
<ol-map ref="map1" :loadTilesWhileAnimating="true" style="height: 100%">
<ol-view :center="center" :zoom="zoom" />
<ol-tile-layer>
<ol-source-osm />
</ol-tile-layer>
<ol-interaction-synchronize :maps="syncMaps1" />
</ol-map>
</div>
<div style="width: 400px; height: 300px;">
<ol-map ref="map2" :loadTilesWhileAnimating="true" style="height: 100%">
<ol-view :center="center" :zoom="zoom" />
<ol-tile-layer>
<ol-source-xyz url="https://tile.openstreetmap.org/{z}/{x}/{y}.png" />
</ol-tile-layer>
<ol-interaction-synchronize :maps="syncMaps2" />
</ol-map>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed } from "vue";
const center = ref([2226389.8158654715, 5465442.183322753]);
const zoom = ref(6);
const map1 = ref();
const map2 = ref();
const syncMaps1 = computed(() => map2.value?.map ? [map2.value.map] : []);
const syncMaps2 = computed(() => map1.value?.map ? [map1.value.map] : []);
</script>Properties
maps
- Type:
Array<Map> - Default:
[] - Description: Array of maps to synchronize with the current map
Features
- Synchronizes view center, zoom level, and rotation between maps
- Shows cursor position on all synchronized maps
- Automatically handles map interactions and updates