2014-12-16 1 views
1

ol.interaction.Draw를 사용하여 맵에 점을 그립니다. "draw"아이콘을 클릭 할 때마다 사용자가 하나의 고유 한 점을 그릴 수있게하려고합니다. 그 방법에 대한 아이디어가 있으십니까?Openlayer3에서 하나의 그리기 기능 허용

function addInteraction() { 
draw = new ol.interaction.Draw({ 
    source: sourceComments, 
    type: "Point" 
}); 

draw.on('drawend', 
    function(evt) { 
    // unset sketch 
    sketch = null; 
    var allFeatures = comments.getSource().getFeatures(); 
    var format = new ol.format.GeoJSON(); 
    document.getElementById('geometry').value = JSON.stringify(format.writeFeatures(allFeatures), null, 4); 
    }, this); 

map.addInteraction(draw); 
} 

감사 :

여기의 상호 작용에 대한 코드입니다!

답변

0

나는 동일한 문제가 있었지만 그것을 해결하기 위해 다른 접근법을 사용했습니다. 상호 작용을 사용하지 않았지만지도에서 클릭 이벤트를 발견했습니다.

var pinpointFeature = new ol.Feature();   
var pinpointOverlay = new ol.FeatureOverlay({ 
    features: [pinpointFeature] 
});   

map.on('click', function(event) { 
    pinpointFeature.setGeometry(new ol.geom.Point(event.coordinate)); 
    //do something with your feature if needed 
}); 
1

drawend 이벤트에서지도에서 상호 작용을 제거 할 수 있습니다.

var draw; 

function addInteraction() { 
    draw = new ol.interaction.Draw({ 
     source: sourceComments, 
     type: "Point" 
    }); 

    draw.on('drawend', function(evt) { 
     //... unset sketch 
     map.removeInteraction(draw); 
    }, this); 

    map.addInteraction(draw); 
} 
관련 문제