地图左下角的OpenLayer静态归因



我使用OpenLayer,可以从两个不同的基本层切换。因此,我对地图右下角的每一层(作为链接(都有不同的归因。

是否可以在地图的左下角再添加一个归因(链接(?我需要在所有层之间共享这个归因(当我切换层时,我不需要更改它(

您可以将共享属性标签设置为变量,然后将其添加到层属性中。看看我为你做的这个例子,通过修改一个OL,在我用作共享归因的例子中,OSM归因。

<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/build/ol.js"></script>
<title>Attributions</title>
</head>
<body>
<h2>Attributions</h2>
<button onclick="switchMap()">Switch Map</button>
<div id="map" class="map"></div>
<script type="text/javascript">
var osm = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
'All maps © <a href="https://www.opencyclemap.org/">OpenCycleMap</a>',
ol.source.OSM.ATTRIBUTION
]
})
});
var openSeaMapLayer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
'All maps © <a href="http://www.openseamap.org/">OpenSeaMap</a>',
ol.source.OSM.ATTRIBUTION
],
opaque: false,
url: 'https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png'
}),
visible: false
});
var map = new ol.Map({
target: 'map',
layers: [
osm,
openSeaMapLayer
],
view: new ol.View({
center: [-244780.24508882355, 5986452.183179816],
zoom: 18
})
});
function switchMap() {
openSeaMapLayer.setVisible(!openSeaMapLayer.getVisible());
osm.setVisible(!osm.getVisible());
};
</script>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新