【发布时间】:2020-08-19 04:53:08
【问题描述】:
如何在ol 6中添加layerswitcher。
import 'ol/ol.css';
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import XYZ from 'ol/source/XYZ';
const map = new Map({
target: 'map',
layers: [
new TileLayer({
title: 'District',
type: 'base',
source: new XYZ({
url: "http://127.0.0.1:8080/tms/1.0.0/district/distgrid" + "/{z}/{x}/{-y}.png" ,
})
}),
new TileLayer({
title: 'Landmark',
source: new XYZ({
url: "http://127.0.0.1:8080/tms/1.0.0/Landmark/landmarkgrid" + "/{z}/{x}/{-y}.png" ,
})
}),
new TileLayer({
title: 'Road',
source: new XYZ({
url: "http://127.0.0.1:8080/tms/1.0.0/road/roadgrid" + "/{z}/{x}/{-y}.png" ,
})
})
],
view: new View({
center: [0, 0],
zoom: 1
})
});
我尝试了上面的代码,但我得到了错误ol.control.LayerSwitcher is not a constructor。 我按照这个例子http://raw.githack.com/walkermatt/ol-layerswitcher/master/examples/layerswitcher.html
【问题讨论】:
-
您也可以自己构建!例如观看该视频:youtube.com/watch?v=k4b3nqDHCIU
标签: openlayers openlayers-3 openlayers-6