map.on()效果示例
通过map.on监听moveend地图移动触发事件,测试发现事件会多次触发,每移动一次都会触发到moveend事件。我们看效果:
map.once()效果示例
通过map.once监听的moveend事件,地图移动时始终只触发一次。
附源码
<template>
<div id="map" class="imap">
</div>
</template>
<script setup>
// openlayers中map.on()与map.once()区别对比
import {
onMounted,
ref
} from 'vue'
import 'ol/ol.css';
import {
Map,
View
} from 'ol';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';
var map = null
onMounted(() => {
map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new XYZ({
url: "",