[英]openlayers: get length of selected feature
i'm using openlayers and geoExt. 我正在使用openlayers和geoExt。
what i have is this: 我所拥有的是:
var options = {
hover : true,
box : true,
onSelect : saveToJ
};
var select = new OpenLayers.Control.SelectFeature(vecLayer, options);
map.addControl(select);
select.activate();
now in saveToJ
function i want to get length of selected feature (let's say feature = lineString): 现在在saveToJ
函数中,我想获取选定特征的长度(假设特征= lineString):
function saveToJ(feature) {
feature.getLength()
...
}
gives an error TypeError: Object #<Object> has no method 'getLength'
, but from this i thought i can use it. 给出错误TypeError: Object #<Object> has no method 'getLength'
,但是据此我认为我可以使用它。
So: how can i get a length of selected feature? 所以:我如何获得所选功能的长度?
getLength
is a method of Geometry
, not Feature
. getLength
是Geometry
方法,不是Feature
。
So you should write feature.geometry.getLength()
, see http://dev.openlayers.org/docs/files/OpenLayers/Geometry-js.html#OpenLayers.Geometry.getLength 因此,您应该编写feature.geometry.getLength()
,请参阅http://dev.openlayers.org/docs/files/OpenLayers/Geometry-js.html#OpenLayers.Geometry.getLength
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.