更改 openlayers 中 feature.vector 的外观

发布于 2024-11-28 15:55:02 字数 478 浏览 1 评论 0原文

我正在将代码从使用标记层转换为矢量图层。我在将地图上的标记显示为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 和创建标记同样不起作用。

提前致谢!

I am transitioning my code from using a marker layer to a vector layer. I am having problems displaying markers on the map as a Feature.Vector class (before I used simply the Feature class).

Specifically, I cannot figure out how to display each feature with a distinct image that I choose. I've seen some examples of how to change the style of a feature in general using stylemaps, but I have not seen a way to directly set the image of a feature.

This seems to be a simple problem but I have not yet found the solution. I am currently trying to use a style property:

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

However, this just results in the normal default icon (an orange circle).

Setting data.icon of the feature and creating a marker equally does not work.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长梦不多时 2024-12-05 15:55:02

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

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);

you put placeholders in the layer style which get populated by the features attributes.

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文