我喜欢使用深色和浅色风格的 openlayers map 。那么如何更改 map 颜色或 map 样式?
我的 friend (亲爱的 morteza)找到了我在这篇文章中回答的简单方法。
我的html文件是:
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 50%;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.1.1/build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([37.41, 8.82]),
zoom: 4
})
});
// function applies greyscale to every pixel in canvas
</script>
</body>
</html>
最佳答案
openlayes 在 <canvas>
中显示 map .和 <canvas>
将添加到 <div>
带有 openlayers 库的容器。所以添加波纹管代码来添加 map 并改变它的颜色:
var map = new ol.Map({
target: 'map',//div with map id
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([61.2135, 28.2331]),
zoom: 13
})
});
//change map color
map.on('postcompose',function(e){
document.querySelector('canvas').style.filter="invert(90%)";
});
您还可以测试其他过滤器
关于javascript - 更改 openlayers map 颜色(深色和浅色样式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59819792/