如何使用CSS更改Open Layers默认缩放工具的位置?

问题描述 投票:0回答:2

如何使用CSS更改Open Layers的默认缩放工具的位置? enter image description here

css openlayers openlayers-3 openlayers-6
2个回答
2
投票

要将缩放控件放在地图的左上角,请设置:

.map .ol-zoom {
  top: 10px;
  left: auto;
  right: 10px;

}

(正如@Mike 在他的评论中指出的那样)

概念证明小提琴

代码片段:

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
  })
});
html,
body {
  height: 100%;
  width: 100%;
  padding: 0px;
  margin: 0px;
}

.map {
  height: 100%;
  width: 100%;
}

.map .ol-zoom {
  top: 10px;
  left: auto;
  right: 10px;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/css/ol.css" type="text/css">
  <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/build/ol.js"></script>
  <title>OpenLayers example</title>
</head>

<body>
  <div id="map" class="map"></div>
</body>

</html>


0
投票

添加此 CSS 会将缩放按钮移至右侧

div.ol-zoom {
    top: .5em;
    right: .5em;
    left: auto;
}
© www.soinside.com 2019 - 2024. All rights reserved.