【发布时间】:2014-09-08 11:53:44
【问题描述】:
我想获取图层上选定点的坐标。
我找到了这样的解决方案:
myLayer.features[0].geometry.getVertices()[0]
但这肯定不是我需要的,因为它只适用于一个具体点。
我想通过单击鼠标来选择点,然后获取相关信息。
我的问题有什么解决方案吗?
【问题讨论】:
标签: javascript extjs html-lists openlayers gis
我想获取图层上选定点的坐标。
我找到了这样的解决方案:
myLayer.features[0].geometry.getVertices()[0]
但这肯定不是我需要的,因为它只适用于一个具体点。
我想通过单击鼠标来选择点,然后获取相关信息。
我的问题有什么解决方案吗?
【问题讨论】:
标签: javascript extjs html-lists openlayers gis
这可能会对您有所帮助:
new OpenLayers.Control.SelectFeature(layer,{
hover:true,
eventListeners:{
onSelect:function(e){
alert(e.feature.geometry.getVertices()[0].x);
alert(e.feature.geometry.getVertices()[0].y);
}
}
});
【讨论】:
您可以在 http://acanimal.github.io/Openlayers-Cookbook/(来源 https://github.com/acanimal/Openlayers-Cookbook)找到 OpenLayers Cookbook 的示例,其中包含用于特征选择的示例。
干杯。
【讨论】:
好的,我找到了适合我的解决方案: (我正在使用 GeoExt)。我刚刚将它添加到我的代码中:
new OpenLayers.Layer.Vector("warstwa", {
styleMap: new OpenLayers.StyleMap({
'default': styl
}),
protocol: new OpenLayers.Protocol.HTTP({
url: '',
format: new OpenLayers.Format.GeoJSON()
}),
strategies: [new OpenLayers.Strategy.Fixed()],
eventListeners: {
featureselected: function(e) {
var xValue = Ext.getCmp('xValue');
var yValue = Ext.getCmp('yValue');
xValue.setValue(e.feature.geometry.getVertices()[0].x);
yValue.setValue(e.feature.geometry.getVertices()[0].y);
}
});
...它对我有用:)
【讨论】: