openlayers2 vector

来源:互联网 发布:旧款mac pro工作站型号 编辑:程序博客网 时间:2024/05/19 09:15

1.向map中添加vector图层方式:

首先要想vector属于layer所以查找api总的layer,可以找到vector,查看vector构造方法,


vector需要两个参数,name和options(可以查看OpenLayers.Layer.Vector中的属性)直接截图



也就是在options中我们可以配置这么多属性,我们只配置isBaseLayer

构造的代码如下

var vectors = new OpenLayers.Layer.Vector("vector", {isBaseLayer: true});

将vectore图层添加到map中:

 map.addLayers([vectors]);

之后我们向vector添加features属性可以通过


进行添加。

其次打开addFeatures方法,看看他是如何构造的


参数有features和option,看到features是一个array类型,继续点开Openlayers.Feature.Vector看怎么构造的,方法同上


这里的geometry参数我们通过wkt来进行添加

var feature = new OpenLayers.Feature.Vector(
                OpenLayers.Geometry.fromWKT(
                    "POLYGON((28.828125 0.3515625, 132.1875 -13.0078125, -1.40625 59.4140625, 28.828125 0.3515625))"
                )
            );

feature构造完毕,将feature通过addFeature添加到vector中

vectors.addFeatures([feature]);

此时vector构造完成



0 0
原创粉丝点击