i'm using openlayers and 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):
function saveToJ(feature) {
feature.getLength()
...
}
gives an error TypeError: Object #<Object> has no method 'getLength'
, but from this i thought i can use it.
So: how can i get a length of selected feature?
getLength
is a method of Geometry
, not Feature
.
So you should write feature.geometry.getLength()
, see http://dev.openlayers.org/docs/files/OpenLayers/Geometry-js.html#OpenLayers.Geometry.getLength
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.