OpenLayers点击选中的Feature触发功能
OpenLayers Click on selected Feature triggering function
我使用OpenLayers在地图上使用集群策略绘制点特征。
strategy = new OpenLayers.Strategy.Cluster();
clusters = new OpenLayers.Layer.Vector("Clusters", {
strategies: [strategy],
styleMap: new OpenLayers.StyleMap({
"default": style,
"select": {
fillColor: "#ff0000",
strokeColor: "#ffbbbb"
}
})
});
[.......]
clusters.addFeatures(features);
我还使用SelectFeature来选择我的地图上的点特征。
select = new OpenLayers.Control.SelectFeature(
clusters, {
clickout: false,
toggle: false,
hover: false
}
);
map.addControl(select);
select.activate();
clusters.events.on({"featureselected": clickPoint});
当用户选择一个集群特征时,将出现一个弹出窗口,其中包含要选择的特征列表。当他选择其中一个时,弹出窗口关闭,聚类特征保持选中。
现在问题来了。我希望能够点击集群功能,使弹出框再次出现。我唯一能做的就是设置toggle:true,但随后该功能被取消选中。
是否有一种方法来触发一个事件,当用户点击一个选定的功能?
提前谢谢,困难的
为了解决这个问题,我将unselectAll
覆盖为:
mySelectControl.unselectAll = function(options) {
OpenLayers.Control.SelectFeature.prototype.unselectAll.apply(
mySelectControl, arguments);
if (options && options.except) {
var myReselecteFeature = options.except;
... your code to show the popup of myReselecteFeature ...
}
};
你可能有兴趣看看这个例子:
http://jorix.github.com/OL-FeaturePopups/examples/feature-popups.html它是一个控件,可以完成您所做的以及更多的操作。例如,在使用集群缩放后保留选择。
注意:默认行为不是你想要的,但可以自定义
您也可以在特性被选中时取消选择。对我来说,这是实现点击事件功能的最短途径。还可以将切换标志设置为true,以在单击时触发取消选择事件。
var pdfFeatureSelector = new OpenLayers.Control.SelectFeature(pdfLayer,{
clickout: true,
multiple: true,
toggle: true,
autoActivate: true,
onSelect: function(){
OpenLayers.Control.SelectFeature.prototype.unselectAll.apply(
pdfFeatureSelector);//unselect the feature when it is selected
}
});
相关文章:
- 添加文字和评论功能更新Div
- JavaScript打印功能使日历停止工作
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 如何防止网页加载后自动启动功能
- 除修剪外的其他功能
- 悬停功能触发器
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 删除CKEditor工具栏按钮,但不删除功能
- 异步facebook功能
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- jQuery滚动功能只工作一次
- Graphiti中是否有任何工具提示功能
- React redux初始化功能,无论状态变化如何
- 在哪里可以学习ECMAScript标准中尚未包含的JavaScript功能
- 正在获取select上的功能id
- Rhino打印功能
- 使用(navigator.geolocation)检测浏览器功能错误
- 主体单击删除功能上的输入框宽度
- JQuery使用相同的功能自动完成各种输入文本
- OpenLayers点击选中的Feature触发功能