2016-12-12 5 views
2

クリックやシングルクリック、またはポインタの移動時に行うことができることが分かりますが、mousedown/mouseupで実行できることはありますか?要するに、ユーザーはマウスボタンがクリックされている間は機能を編集できるようにしたいが、マウスボタンを離すと保存/停止する。OL interaction - mousedown

featureRotateDown = new ol.interaction.Select({ 
     condition: ol.events.condition.pointerdown 
    }); 

    featureRotateUp = new ol.interaction.Select({ 
     condition: ol.events.condition.pointerup 
    }); 

    map.addInteraction(featureRotateDown); 
    map.addInteraction(featureRotateUp); 

featureRotateDown.on('select', function(event) { 
     $.each(event.selected, function (index, feature) { 
      console.log(feature); 
      console.log('1'); 
     }); 
    }); 

    featureRotateUp.on('select', function(event) { 
     $.each(event.selected, function (index, feature) { 
      console.log(feature); 
      console.log('3'); 
     }); 
    }); 

つまり、矢印である地図上にマーカーを配置したとします。私は、カーソルがマーカー上にあり、マウスボタンが押されている間に、私が望むくらい回転させる機能が必要です。あなたがforEachFeatureAtPixelgetClosestFeatureToCoordinateを使用して機能にアクセスできる機能で

map.on('pointerdown', function (event) { 
    // doStuff... 
    // ALTERNATIVE 1: get a feature at click position (with very small tolerance) 
    map.forEachFeatureAtPixel(event.pixel, function(feature, layer){ 
    // doStuff with your feature at click position 
    }); 

    // ALTERNATIVE 2: get the closest feature 
    closestFeature = yourVectorSource.getClosestFeatureToCoordinate(event.coordinate); 
}) 

map.on('pointerup', function (event) { 
    // doStuff... 
}) 

+0

ol.interaction.PointerとそのhandleDownEventおよびhandleUpEvent関数を見てください。マウスを下に移動させるには、forEachFeatureAtPixelメソッドを使用します。 – itsyahani

答えて

1

pointerdownpointerupを試してみてください。 これも参照してくださいJSFiddle

+0

私はそれを試した。ポインタの上がうまくいきますが、ポインタの下が失敗します。 – yondaimehokage

+0

それは私のために働いています。 JSFiddleをチェックしてください。 – Lars

+0

一般的なマップ全体ではなく、ベクトルレイヤの個々の機能を使用する必要があります。私が掲示したコードを見てください。 – yondaimehokage