在openlayers中更改feature.vector的外观(changing the appearance of feature.vector in openlayers)

编程入门 行业动态 更新时间:2024-10-26 05:28:53
在openlayers中更改feature.vector的外观(changing the appearance of feature.vector in openlayers)

我正在将我的代码从使用标记图层转换到矢量图层。 我在地图上显示标记时遇到问题,作为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!

最满意答案

您将占位符置于由特征属性填充的图层样式中。

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

                    
                     
          

更多推荐

本文发布于:2023-07-17 04:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1139253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:外观   feature   openlayers   vector   appearance

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!