javascript - 更改 openlayers map 颜色(深色和浅色样式)

标签 javascript dictionary openlayers

我喜欢使用深色和浅色风格的 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/

相关文章:

java - 根据另一个列表的顺序对列表进行排序

WPF按键绑定(bind)到字典中的项目?

javascript - 控制台.log();如何调试javascript

javascript - 购物车 : Cookies only holding 2 - 5 items

swift - 遍历字典并创建对象实例

javascript - Angular - 在复选框上添加事件

javascript - 是否可以允许在 Openlayers 中平移矢量图层?

javascript - Openlayers 根据您的 map 编写并保存 KML

javascript - onChange 内的 React 测试函数

Javascript:函数不会被触发