【问题标题】:OpenLayers 3 - Display text on map, text size relative to zoomOpenLayers 3 - 在地图上显示文本,相对于缩放的文本大小
【发布时间】:2016-08-31 09:43:45
【问题描述】:

我目前正在开发 OL3 并尝试在我的地图上显示文本。没问题,我是用ol.style的text属性来显示的。

我的问题如下:此文本的大小始终相同。即:如果我取消最大缩放或最大缩放,它在屏幕上的大小仍然相同。我希望它在缩放时增长,在取消缩放时缩小以保持文本相对于地面的大小。

我在下图中绘制了预期的结果: Expected result

有人有想法吗?也许不使用 ol.style 文本?

【问题讨论】:

  • 任何反馈...?

标签: javascript openlayers-3


【解决方案1】:

要走的路是a style function。见演示fiddle

var style = function () {
  var zoom = map.getView().getZoom();
  var font_size = zoom * 10; // arbitrary value

  return [
    new ol.style.Style({
      text: new ol.style.Text({
        font: font_size + 'px Calibri,sans-serif',
        fill: new ol.style.Fill({ color: '#000' }),
        stroke: new ol.style.Stroke({
          color: '#fff', width: 2
        }),
        text: 'Some text!'
      })
    })
  ];
};

【讨论】:

  • 这样就行了!谢谢!
  • @YoannB 那么请把问题标记为正确并完成它。
猜你喜欢
  • 1970-01-01
  • 2014-08-19
  • 2017-04-26
  • 2016-09-21
  • 1970-01-01
  • 2016-10-23
  • 2016-08-23
  • 2018-02-03
  • 2012-03-31
相关资源
最近更新 更多