43 Star 954 Fork 264

德育处主任/前端数据可视化

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Synchronization.vue 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
<!-- ol - 同步两个地图 -->
<template>
<div class="map__container">
<div id="OSM" class="map__x"></div>
<div id="BingMaps" class="map__x"></div>
</div>
<div class="explain">
<p>两个地图使用同一个view,所以在移动、缩放、旋转等操作都是同步的。</p>
<p>按住shift,鼠标在地图上选区,可以放大选区。</p>
<p>按住alt+shift,鼠标可以在地图上拖拽,进行旋转。</p>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useStore } from 'vuex'
import { Map, View } from 'ol'
import Tile from 'ol/layer/Tile'
import OSM from 'ol/source/OSM'
import BingMaps from 'ol/source/BingMaps'
import 'ol/ol.css'
const store = useStore()
const mapO = ref(null)
const mapB = ref(null)
const mapView = new View({
center: [0, 0],
zoom: 2
})
const layerO = new Tile({
source: new OSM()
})
const layerB = new Tile({
source: new BingMaps({
key: 'AiZrfxUNMRpOOlCpcMkBPxMUSKOEzqGeJTcVKUrXBsUdQDXutUBFN3-GnMNSlso-',
imagerySet: 'Aerial'
})
})
// 初始化
function initMap () {
mapO.value = new Map({
target: 'OSM',
layers: [layerO],
view: mapView
})
mapB.value = new Map({
target: 'BingMaps',
layers: [layerB],
view: mapView
})
}
onMounted(() => {
store.commit('setComponentPath', 'src/views/OpenLayers/Basic/pages/Synchronization/Synchronization.vue')
initMap()
})
</script>
<style lang="scss" scoped>
.map__container {
width: 800px;
height: 380px;
margin-bottom: 60px;
display: flex;
justify-content: space-between;
.map__x {
width: 380px;
height: 380px;
box-sizing: border-box;
border: 1px solid #ccc;
position: relative;
}
#OSM::after,
#BingMaps::after {
position: absolute;
display: block;
font-size: 18px;
left: 50%;
bottom: -28px;
transform: translateX(-50%);
}
#OSM::after {
content: 'OSM'
}
#BingMaps::after {
content: 'BingMap'
}
}
</style>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/k21vin/front-end-data-visualization.git
git@gitee.com:k21vin/front-end-data-visualization.git
k21vin
front-end-data-visualization
前端数据可视化
master

搜索帮助