我正在尝试创建tap + hold事件以创建新的标记位置(tap + hold事件仅适用于移动应用);这些事件处理程序无法按预期运行(发生了一些替代)
我尝试使用map.on('touchstart'...),map.on('mousedown'...)和其他变体,但事件代码仅在touchend或mouseup完成后才触发。
me.mapLibObj.on( 'touchstart', function(e)
{
if ( ! me.mapTapHoldInterval )
{
me.mapTapHoldInterval = setInterval( function() {
me.mapDownIntvCounter += 1
if ( me.mapDownIntvCounter > 20 )
{
me.defaultCoordinatePoint = [ e.latlng.lat,e.latlng.lng ];
me.createMyCoordinateMarker( true );
clearInterval( me.mapTapHoldInterval );
}
}, 100 )
}
} );
me.mapLibObj.on( 'touchend', function(e)
{
if ( me.mapTapHoldInterval )
{
clearInterval( me.mapTapHoldInterval );
}
} );
答案 0 :(得分:0)
您为什么使用var groupItem = [];
for (var i = 1; i <= 3; i++) {
groupItem.push({ "Group": "Group1", "Item1": i, "Item2": "Item " + i, "GroupId" : 1 });
}
for (var i = 1; i <= 2; i++) {
groupItem.push({ "Group": "Group2", "Item1": i, "Item2": "Item " + i, "GroupId": 2, "Parent Group": null });
}
for (var i = 1; i <= 2; i++) {
groupItem.push({ "Group": "Item 2", "Item1": i, "Item2": "Item " + i, "GroupId": 3, "Parent Group": 1 });
}
groupItem.sort((a, b) => {
// if one item is a child of the other, then sort the parent
// before the item or the item after the parent
if (a["Parent Group"] === b.GroupId) return 1;
if (b["Parent Group"] === a.GroupId) return -1;
//finally, if at least one item is not a parent group and the other
//or the two aren't direct parent and child of each other, then
//sort them by the GroupId (for parent groups) or Parent Group (for child items)
var sortingIdA = a["Parent Group"] || a.GroupId;
var sortingIdB = b["Parent Group"] || b.GroupId;
return sortingIdA - sortingIdB;
})
console.log(groupItem);
?
这应该足够了(使用超时,因为您可能只想触发一次)
mapDownIntvCounter