【发布时间】: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