我正试图将一个maplayer GEOJSON分配给一个按钮,而我曾尝试将其作为一个函数,但效果不佳
<button type="button" class="btn btn-secondary btn-sm" id="geojson1" onclick="layer1()">
GeoJSON</button>
function layer1(){
rainfall1 = new ol.layer.Tile({
title: "layer1",
source: new ol.source.TileWMS({
url: './data/bsk.geojson',
// Countries have transparency, so do not fade tiles:
transition: 0,
}),
请告诉我如何将这个分配给按钮。
您只是创建了一个图层,但您没有将其添加到地图中。你需要
function layer1(){
let rainfall1 = new ol.layer.Tile({
title: "layer1",
source: new ol.source.TileWMS({
url: './data/bsk.geojson',
// Countries have transparency, so do not fade tiles:
transition: 0,
});
yourMAP.addLayer(rainfall1);
}