开放层扩展——longtouch
Open layer extension - longtouch
我是开放图层的新手,我正在尝试与我的地图进行一些交互。我正在使用像 longtouch 一样的 ol 扩展,一段时间后我想在地图上显示 fetaure。它与此扩展一起工作正常,但问题是它在释放点击后显示。
有没有办法在释放点击后不在 pointerdown 事件上显示添加的功能?
这里我举个例子。 http://viglino.github.io/ol-ext/examples/mobile/map.interaction.longtouch.html
真是奇怪。我重新编写了函数来分解和理解它。即使有了它,Point
功能也只显示在 pulse
功能之后。
这是我的代码:
map.on('pointerdown', function(e){
timeOutVar = setTimeout(test(e), 1000);
});
map.on('pointerup', function(e){
clearTimeout(timeOutVar);
});
function test(e){
var point = new ol.Feature(new ol.geom.Point(e.coordinate));
vector.getSource().addFeature(point);
};
var touchi = new ol.interaction.LongTouch(
{ handleLongTouchEvent: function(e){
pulseFeature(e.coordinate);
setTimeout( function(){
pulseFeature(e.coordinate);
}, 400);
$(".options div").text(vector.getSource().getFeatures().length+" features added!");
}
});
map.addInteraction(touchi);
问题不在于交互,而在于你的矢量图层。如果要在交互时反映插入,则必须为图层设置 updateWhileInteracting
选项,否则该功能将添加到图层,但仅在完成时(鼠标向上)绘制。
我已经更新了示例来处理这种情况。
我是开放图层的新手,我正在尝试与我的地图进行一些交互。我正在使用像 longtouch 一样的 ol 扩展,一段时间后我想在地图上显示 fetaure。它与此扩展一起工作正常,但问题是它在释放点击后显示。
有没有办法在释放点击后不在 pointerdown 事件上显示添加的功能?
这里我举个例子。 http://viglino.github.io/ol-ext/examples/mobile/map.interaction.longtouch.html
真是奇怪。我重新编写了函数来分解和理解它。即使有了它,Point
功能也只显示在 pulse
功能之后。
这是我的代码:
map.on('pointerdown', function(e){
timeOutVar = setTimeout(test(e), 1000);
});
map.on('pointerup', function(e){
clearTimeout(timeOutVar);
});
function test(e){
var point = new ol.Feature(new ol.geom.Point(e.coordinate));
vector.getSource().addFeature(point);
};
var touchi = new ol.interaction.LongTouch(
{ handleLongTouchEvent: function(e){
pulseFeature(e.coordinate);
setTimeout( function(){
pulseFeature(e.coordinate);
}, 400);
$(".options div").text(vector.getSource().getFeatures().length+" features added!");
}
});
map.addInteraction(touchi);
问题不在于交互,而在于你的矢量图层。如果要在交互时反映插入,则必须为图层设置 updateWhileInteracting
选项,否则该功能将添加到图层,但仅在完成时(鼠标向上)绘制。
我已经更新了示例来处理这种情况。