【问题标题】:Increase the size/height of the OpenLayer map/canvas增加 OpenLayer 地图/画布的大小/高度
【发布时间】:2019-03-02 02:47:25
【问题描述】:

我试图让 OpenLayers 的 Map/Canvas 高度为 100%,但我做不到。

我已经尝试在几个地方添加“高度:100%;”并使用了“map.updateSize()”函数,但没有成功。我已经尝试使用“高度:100vh;”也一样,但它会拉伸地图而不是增加画布。

我发送下面的打印屏幕说明会发生什么:

我希望地图/画布在页面上的高度为 100%

图片上显示的那段代码:

<div id="map" class="olMap">
    <div class="ol-viewport" data-view="146" style="position: relative; overflow: hidden; width: 100%; height: 100%; touch-action: none;">

        <canvas class="ol-unselectable" width="937" height="480" style="width: 100%; height: 100%; display: block;"></canvas>

        <div class="ol-overlaycontainer"></div>
        <div class="ol-overlaycontainer-stopevent">
        <div class="ol-zoom ol-unselectable ol-control">
        <button class="ol-zoom-in" type="button" title="Zoom in">+</button>
        <button class="ol-zoom-out" type="button" title="Zoom out">−</button>
        </div>
        <div class="ol-rotate ol-unselectable ol-control ol-hidden">                
        <button class="ol-rotate-reset" type="button" title="Reset rotation"><span class="ol-compass" style="transform: rotate(0rad);">⇧</span></button>
        </div>
        <div class="ol-attribution ol-unselectable ol-control ol-collapsed" style="display: none;"><ul></ul><button type="button" title="Attributions"><span>i</span></button>
</div>
</div>
</div>
</div>

我创建地图的代码 (Explore.vue):

export default {
  ...
  methods: {
    initMap: function () {
      // eslint-disable-next-line
      this.map = new Map({
        target: 'map',
        layers: [
          layerGroupBaseMap
        ],
        view: new View({
          projection: 'EPSG:4326',
          center: [0, 0],
          zoom: 5
        })
      })
    }
  },
  mounted: function () {
    this.initMap()
  },
  ...
}

源码:https://github.com/rmmariano/executive_frontend/tree/dev-rodrigo

有人知道吗?

PS:我已经在 gis.stackexchange.com [1] 中问过这个问题,但是在 OpenLayers 网站上说要在 stackoverflow 中提问,因此,我在这里添加了这个问题。

[1]https://gis.stackexchange.com/questions/314059/increase-the-size-height-of-the-openlayer-map-canvas

【问题讨论】:

    标签: canvas mapping openlayers


    【解决方案1】:

    确保包含

    <style>
        html, body, .olmap {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }
    </style>
    

    使用 Chrome 的 devtools 检查是没有意义的,因为 devtools 会减少应用程序的可用页面大小,因此地图将按比例缩小。但是您可以使用 Edge 进行检查:

    在 1680 x 1050 显示器上符合预期的 1680 x 977,允许顶部条形

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2011-12-03
    • 1970-01-01
    相关资源
    最近更新 更多