【问题标题】:changing the appearance of feature.vector in openlayers改变 openlayers 中 feature.vector 的外观
【发布时间】:2013-12-13 01:23:15
【问题描述】:

我正在将我的代码从使用标记层转换为矢量图层。我在地图上将标记显示为 Feature.Vector 类时遇到问题(在我仅使用 Feature 类之前)。

具体来说,我无法弄清楚如何使用我选择的独特图像来显示每个功能。我已经看到了一些关于如何使用样式映射来更改特征样式的示例,但我还没有看到直接设置特征图像的方法。

这似乎是一个简单的问题,但我还没有找到解决方案。我目前正在尝试使用样式属性:

var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(ll.lon, ll.lat), {externalGraphic: "http://www.openlayers.org/dev/img/marker.png"}); 

但是,这只会导致正常的默认图标(橙色圆圈)。

设置特征的 data.icon 和创建标记同样不起作用。

提前致谢!

【问题讨论】:

  • 为什么要使用矢量图层来显示标记?
  • Alex,我正在更改为矢量图层,因为它具有更多功能 - 我将使用几何类在地图上添加诸如聚类和旋转等功能。

标签: openlayers


【解决方案1】:

您将占位符放在由要素属性填充的图层样式中。

var style = OpenLayers.Util.extend({
    externalGraphic : "${icon}",
    pointRadius     : 15
}, OpenLayers.Feature.Vector.style['default']);

var layer   = new OpenLayers.Layer.Vector("Simple Geometry", { style: style }),
    point   = new OpenLayers.Geometry.Point(ll.lon, ll.lat),
    feature = new OpenLayers.Feature.Vector(point, { icon: "icon.png" });

layer.addFeature(feature);

【讨论】:

  • 如果忽略 PointRadius,外部图形根本不会显示。谢谢,救了我。赞成!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-04
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-20
相关资源
最近更新 更多