支持config.js中配置多层地图瓦片

pull/1641/head
Kairlec 2024-10-11 11:10:11 +08:00
parent 3e1f31dab4
commit 192e92f772
No known key found for this signature in database
GPG Key ID: DB5579BC03F05D3E
2 changed files with 17 additions and 13 deletions

View File

@ -59,25 +59,28 @@ export default {
maxZoom: mapParam.maxZoom || 19, maxZoom: mapParam.maxZoom || 19,
minZoom: mapParam.minZoom || 1, minZoom: mapParam.minZoom || 1,
}); });
let tileLayer = null; let tileLayers = [];
if (mapParam.tilesUrl) { if (mapParam.tilesUrl) {
tileLayer = new Tile({ const tilesUrls = Array.isArray(mapParam.tilesUrl) ? mapParam.tilesUrl : [mapParam.tilesUrl]
source: new XYZ({ tilesUrls.forEach(tilesUrl => {
projection: getProj("EPSG:3857"), tileLayers.push(new Tile({
wrapX: false, source: new XYZ({
tileSize: 256 || mapParam.tileSize, projection: getProj("EPSG:3857"),
url: mapParam.tilesUrl wrapX: false,
}) tileSize: 256 || mapParam.tileSize,
url: tilesUrl
})
}))
}) })
}else { }else {
tileLayer = new Tile({ tileLayers.push(new Tile({
preload: 4, preload: 4,
source: new OSM(), source: new OSM(),
}) }))
} }
olMap = new Map({ olMap = new Map({
target: this.$refs.mapContainer, // ID target: this.$refs.mapContainer, // ID
layers: [tileLayer], // layers: tileLayers, //
view: view, // view: view, //
controls:[ // controls:[ //
// new ZoomSlider(), // new ZoomSlider(),

View File

@ -8,6 +8,7 @@ window.mapParam = {
// 坐标系 GCJ-02 WGS-84, // 坐标系 GCJ-02 WGS-84,
coordinateSystem: "GCJ-02", coordinateSystem: "GCJ-02",
// 地图瓦片地址 // 地图瓦片地址
// 地图瓦片地址 , 支持string[]类型作为多层地图瓦片
tilesUrl: "http://webrd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8", tilesUrl: "http://webrd0{1-4}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8",
// 瓦片大小 // 瓦片大小
tileSize: 256, tileSize: 256,