一, 引入:
npm install ol
二, 使用:
// 引入依赖
// import proj from 'ol'
import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ' //xyz
// 初始化地图
const map = new Map({
layers: [
new TileLayer({
visible: true,
source: new XYZ({
visible: true,
url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
})
})
],
target: 'map',
view: new View({
center: [12791868.560463652, 3482284.5520139523],
zoom: 8,
maxZoom: 18,
projection: 'EPSG:3857',
constrainResolution: true, // 设置缩放级别为整数
smoothResolutionConstraint: false, // 关闭无级缩放地图
}),
});