2016-07-22 1 views
0

add 이벤트를 어떻게 만들 수 있는지 또는 기능이 소스에 추가되면 이벤트에 리스너를 첨부 할 수 있는지 알 수 없습니다. 내가 drawend 이벤트가 내가 필요한 것을 생각기능 이벤트 추가

draw.on("drawend", function (e) { 
//.... 
}); 

하지만 알고 보니이 이벤트가 발생하면,이 기능은 아직 소스에 추가되지 않습니다 : 같은이 순간에 나는, 다른 이벤트의 무리가 .

답변

1

시도 소스에 수동으로 추가 : 당신은 소스 레이어에 기능을 밀어 drawend 이벤트에 오버레이

var features = new ol.Collection(); 
var featureOverlay = new ol.layer.Vector({ 
    source: new ol.source.Vector({features: features}), 
    style: new ol.style.Style({ 
     fill: new ol.style.Fill({ 
      color: 'rgba(255, 255, 255, 0.2)' 
     }), 
     stroke: new ol.style.Stroke({ 
      color: '#ffcc33', 
      width: 2 
     }), 
     image: new ol.style.Circle({ 
      radius: 7, 
      fill: new ol.style.Fill({ 
       color: '#ffcc33' 
      }) 
     }) 
    }) 
}); 
featureOverlay.setMap(map); 

var draw = new ol.interaction.Draw({ 
    features: features, // we set the newly drawn feature on the overlay declared previously 
    type: /** @type {ol.geom.GeometryType} */ ('Polygon') // for example polygon 
    }); 

에 무승부 상호 작용을 추가하려면 또는

draw.on('drawend', function(event) { 
    yourSource.addFeature(event.feature); 
} 
1

을 원하는 '추가 기능'이벤트를 사용할 수 있습니다.

source.on('addfeature', function (ft) { 
    // ft - feature being added 
});