每张单张都有自动触发鼠标悬停功能
Leaflet foreach feature auto trigger mouseover function
我遇到了一个情况,我必须创建一个类似于choropletheexample的仪表板应用程序。但唯一的问题是我必须在所有状态(geoJSON中的功能)之间进行迭代,并在每次迭代中暂停3秒。
我发现这个主题,鼠标悬停触发的例子给出。但是我们如何在这种情况下使用它呢?
下面是需要在每次迭代中触发的函数:LeafletExample
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
}
您可以使用L.GeoJSON
的eachLayer
方法迭代各层,然后在当前层使用highlightFeature
方法,在前一层(如果有的话)使用resetHighlight
方法。
删除当前交互:
function onEachFeature(feature, layer) {
layer.on({
//mouseover: highlightFeature,
//mouseout: resetHighlight,
//click: zoomToFeature
});
}
添加迭代器:
// Variables for storing currently highlighted feature and delay amount
var highlight, delay = 0;
// Iterate over each layer in the geojsonlayer
geojson.eachLayer(function (layer) {
// Mimick event object because highlightFeature and resetHighlight
// expect an object with the layer as target property
layer = {'target': layer};
// Up the delay amount
delay = delay + 3000;
setTimeout(function() {
// Check if there is a highlight, if so reset
if (highlight) {
resetHighlight(highlight);
}
// Highlight current and store
highlightFeature(layer);
highlight = layer;
}, delay);
});
示例:http://plnkr.co/edit/QD2uHv?p=preview
相关文章:
- 当鼠标悬停在文本中的单词上时显示警报
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 在鼠标悬停时展开列表
- jQuery悬停在没有鼠标悬停的情况下启动
- 鼠标悬停时如何居中放大背景图像
- 使用鼠标悬停JavaScript/HTML显示文本
- 如何在MVC3中显示鼠标悬停在文本上的部分视图
- d3.js鼠标悬停鼠标输出问题
- 如何在鼠标悬停时将对象从起始位置移动到结束位置,然后在鼠标悬停后再次移动
- 鼠标悬停时播放随机轨迹
- 鼠标悬停时的css转换
- 将鼠标悬停在同级元素上的 jquery 上轻拂
- 将鼠标悬停在Angular JS中的一个元素上,并将Class添加到另一个元素中
- aspx中鼠标悬停时横向扩展DIV
- ajax鼠标悬停和鼠标悬停脚本
- 在鼠标悬停处隐藏图像
- 如何停止地图移动时,鼠标悬停在标记在谷歌地图API 3
- 通过鼠标悬停向上或向下滑动的图片
- 鼠标悬停时更改按钮的 CSS