- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我目前正在寻找一种在 OpenLayers.Layer.Vector 中选择(或突出显示)矢量的解决方案。
我构建了一个简单的网格表,用户可以在其中选择一个矢量(以 WKT 格式的字符串给出),该矢量应突出显示图层上的相应矢量。当用户访问网站时,gridtable 中的所有矢量被绘制到 map 上的矢量层。
我发现我要么需要 OpenLayers.Control.ModifyFeature的 selectFeature(feature)函数或 OpenLayers.Control.SelectFeature(请参阅 dev.openlayers.org/apidocs/files/OpenLayers/Control/SelectFeature-js.html 的 select(feature) 函数(可能不存在或不再存在?)。请参阅邮件列表中的帖子:osgeo-org.1803224.n2.nabble.com/Programatically-Select-a-Feature-tt2192485.html#a2193928 了解更多信息。
我尝试了以下但没有成功,所以我希望有人可以捕获这些代码行并向我展示一个有效的代码片段;-)
// ... some initializing code
this.vlayer = new OpenLayers.Layer.Vector("VectorLayer"); // VectorLayer
// some controls
this.openLayerControlPoint = new OpenLayers.Control.DrawFeature(this.vlayer, OpenLayers.Handler.Point);
this.openLayerControlPolygon = new OpenLayers.Control.DrawFeature(this.vlayer, OpenLayers.Handler.Polygon);
this.openLayerControlModify = new OpenLayers.Control.ModifyFeature(this.vlayer, {
mode: OpenLayers.Control.ModifyFeature.RESHAPE | OpenLayers.Control.ModifyFeature.DRAG,
standalone: false
});
// just deactivate to make sure everything is really deactivated
this.openLayerControlPoint.deactivate();
this.openLayerControlPolygon.deactivate();
this.openLayerControlModify.deactivate();
// add the just created layer to the map
this.map.addLayer(this.vlayer);
// add all (deactivated) controls to the map
this.map.addControl(this.openLayerControlPoint);
this.map.addControl(this.openLayerControlPolygon);
this.map.addControl(this.openLayerControlModify);
后面的代码:
// ... another function doing the action
selectVector: function(wktVector) {
this.openLayerControlModify.activate();
// this is no elegant solution, this should only show how I would
// test the functionallity.
for (var i = 0; i < this.vlayer.features.length; ++i) {
// returns a WKT formatted string:
// 'POLYGON((xxxx.xxx xxxx.xxx), (xxxx.xxx xxxx.xxx))'
var wktVectorCurrent = this.vlayer.features[i].geometry.toString();
if (wktVector == wktVectorCurrent) {
// \/ doesn't work :-(
this.openLayerControlModify.selectFeature(this.vlayer.features[i]);
break;
}
}
}
最佳答案
我不明白您为什么要使用 ModifyFeature 来选择特征。 OpenLayers.Control.SelectFeature 是专门用来选择特征的,所以我建议你改用这个控件。
因此,创建 SelectFeature 控件:
var selectFeature = new OpenLayers.Control.SelectFeature(this.vlayer);
selectFeature.activate();
然后在你的 if 语句中(我想它可以通过比较几何来找到你想要选择的特征?)使用 select 方法:
if (wktVector == wktVectorCurrent) {
selectFeature.select(this.vlayer.features[i]);
}
根据文档,此方法应将功能标记为选中并引发适当的事件:
* Method: select
* Add feature to the layer's selectedFeature array, render the feature as
* selected, and call the onSelect function.
如果您想在选择要素时在 map 上做一些事情(比如显示弹出窗口),您应该在创建矢量图层时订阅它以选择事件:
this.vlayer.events.on({'featureselected': function(){
//Handle select event
}});
关于javascript - 如何在 OpenLayers 的矢量图层上以编程方式选择特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832029/
设置 我希望能够定义一个特征,使得任何实现该特征的结构不仅必须实现函数,而且还必须为某些常量指定值。所以也许是这样的: trait MyTrait { const MY_CONST: u8;
在我的 Web 应用程序中,授权用户至少有 4 个“方面”:http session 相关数据、持久数据、facebook 数据、运行时业务数据。 我决定使用案例类组合而不是特征至少有两个原因: 性状
我正在尝试使用以下代码从类中获取完整数据成员的列表: import std.stdio; import std.traits; class D { static string[] integr
我正在尝试实现 From对于我的一种类型。它应该消耗任意长度的行(仅在运行时已知)并从行中获取数据。编译器提示 &[&str; 2]不是 &[&str] ,即它不能将固定大小的切片转换为任意长度的切片
有人可以请你这么好心,并指出一种提取拟合树中使用的列/特征的方法,使用如下代码: library(dplyr) library(caret) library(rpart) df % dplyr
假设我定义了一个 Group所有组操作的特征。是否可以创建一个包装器AGroup超过 Group无需手动派生所有操作? 基本上,我想要这个: #[derive (Copy, Debug, Clone,
最近浏览了Markus Stocker的博客他很好地解释了如何在使用 observation 时表示传感器观察结果。 SSN 的模块本体论。我完全理解他的解释,但我发现有一件事多余地代表了一个的两个特
我有以下情况/代码; trait Model { def myField: String } case class MyModel(myField: String) extends Model
我想让一个案例类扩展一个特征 以下是我的要求: 我需要为 child 使用案例类。这是一个硬性要求,因为 scopt ( https://github.com/scopt/scopt ) parent
最近浏览了Markus Stocker的博客他很好地解释了如何在使用 observation 时表示传感器观察结果。 SSN 的模块本体论。我完全理解他的解释,但我发现有一件事多余地代表了一个的两个特
我有以下情况/代码; trait Model { def myField: String } case class MyModel(myField: String) extends Model
不确定标题是否完全有意义,对此感到抱歉。我是机器学习新手,正在使用 Scikit 和决策树。 这就是我想做的;我想获取所有输入并包含一个独特的功能,即客户端 ID。现在,客户端 ID 是唯一的,无法以
我想读取具有 Eigen 的 MNIST 数据集,每个文件都由一个矩阵表示。我希望在运行时确定矩阵大小,因为训练集和测试集的大小不同。 Map> MNIST_dataset((uchar*)*_dat
在 MATLAB 中,我可以选择一个分散的子矩阵,例如: A = [1 ,2 ,3;4,5,6;7,8,9] A([1,3],[1,3]) = [1,3;7,9] 有没有用 Eigen 做到这一点的聪
我在执行 Into 时遇到问题Rust 中通用结构的特征。下面是我正在尝试做的简化版本: struct Wrapper { value: T } impl Into for Wrapper {
我有这段 matlab 代码,我想用 Eigen 编写: [V_K,D_K] = eig(K); d_k = diag(D_K); ind_k = find(d_k > 1e-8); d_k(ind_
我正在使用 Eigen C++ 矩阵库,我想获取对矩阵列的引用。文档说要使用 matrix_object.col(index),但这似乎返回了一个表示列的对象,而不是简单地引用原始矩阵对象中的列。我担
在乘以很多旋转矩阵之后,由于舍入问题(去正交化),最终结果可能不再是有效的旋转矩阵 重新正交化的一种方法是遵循以下步骤: 将旋转矩阵转换为轴角表示法 ( link ) 将轴角转换回旋转矩阵 ( lin
定义可由命名空间中的多个类使用的常量的最佳方法是什么?我试图避免太多的继承,所以扩展基类不是一个理想的解决方案,我正在努力寻找一个使用特征的好的解决方案。这在 PHP 5.4 中是可行的还是应该采用不
定义可由命名空间中的多个类使用的常量的最佳方法是什么?我试图避免太多的继承,所以扩展基类不是一个理想的解决方案,我正在努力寻找一个使用特征的好的解决方案。这在 PHP 5.4 中是可行的还是应该采用不
我是一名优秀的程序员,十分优秀!