Search code examples
javascriptmouseeventopenlayers-3markers

How to slow down mouse before modifyend with OpenLayers


I have a map with a draggable marker (ol.style.icon in fact). There is a strange issue: If I try to move marker, it is like trying to reel in a marlin but after a zoomin/out or a first drag (clic tight then clic release), marker naturally slows down. I tried to play with PixelTolerance but any difference. Why and how to immediately slow down this marker, please?

var mark_style = new ol.style.Style({
    image: new ol.style.Icon({
    anchor: [.5, 48],
    anchorXUnits: 'fraction',
    anchorYUnits: 'pixels',
    opacity: 0.75,
    src: mark_path
 })
});

var iconFeature = new ol.Feature(position);
iconFeature.set('style', mark_style);

var vectorLayer = new ol.layer.Vector({
    style: function(feature) {
        return feature.get('style');
    },
    source: new ol.source.Vector({features: [iconFeature]})
})
var dragInteraction = new ol.interaction.Modify({
  features: new ol.Collection([iconFeature]),
  style: null,
  pixelTolerance: 10//?
});

dragInteraction.on('modifyend',function(f){
    var coordf = f.features.getArray()[0].getGeometry().getCoordinates();
    ol.View-view.setCenter(coordf);
    GMapWidget.prototype.A = coordf;
    GMapWidget.prototype.updatePosition(position);
    },iconFeature);

  map.addInteraction(dragInteraction);

After a lot of tries, it seems it's a 'modifyend' problem: mouse is fast before first dragInteraction end. How to do please? with a modifystart, no more speed up but then, how to access all mouse positions after first clic ?


Solution

  • well, seems ok with dragInteraction.on(['modifyend', 'modifystart'] I'm a beginner and I don't know why my code is now ok. I succeeded after lot of tries.