2017-06-30 2 views
0

Hallo gibt es eine Möglichkeit, einen Rückruf zu haben, nachdem ein Polygon auf einer bestimmten Ebene hinzugefügt wurde? Das Szenario ist, dass ich ein benutzerdefiniertes Steuerelement in meiner Map hinzugefügt habe und dieses Steuerelement eine Polygoninteraktion für Zeichenaufrufe aufruft. Jetzt möchte ich einen Rückruf haben, der mir hilft, herauszufinden, dass die Polygonzeichnung bereits hinzugefügt wurde. Im Moment ist mein Code wie untenPolygon featureadded Rückruf auf benutzerdefinierten Steuerelement Openlayers

var polysource = new ol.source.Vector({wrapX: false}); 
var map = new ol.Map({ 
    target: id, 
    controls: ol.control.defaults() 
     .extend([ 
      new ol.control.FullScreen(), 
      new windowpoly.DrawPolygon() 
     ]), 
    layers: [ 
     new ol.layer.Tile({ 
      source: new ol.source.OSM() 
     }), 
     new ol.layer.Vector({ 
      source: polysource 
     }) 
    ], 
    loadTilesWhileAnimating: true, 
    view: new ol.View({ 
     center: [0,0], 
     zoom: 11 
    }) 
}); 

// Create a custom control for the drawpolygon 
var windowpoly = {}; 
windowpoly.DrawPolygon = function(opt_options) { 

    var options = opt_options || {}; 

    var button = document.createElement('button'); 
    button.innerHTML = '/'; 

    var this_ = this; 
    var drawPolygon = function(e) { 
     addInteraction(); 
    }; 

    button.addEventListener('click', drawPolygon, false); 
    button.addEventListener('touchstart', drawPolygon, false); 

    var element = document.createElement('div'); 
    element.className = 'draw-polygon ol-unselectable ol-control'; 
    element.appendChild(button); 

    ol.control.Control.call(this, { 
     element: element, 
     target: options.target 
    }); 

}; 
ol.inherits(windowpoly.DrawPolygon, ol.control.Control); 

// Function to initialize draw polygon 
function addInteraction() 
{ 
    draw = new ol.interaction.Draw({ 
     source: polysource, 
     type: /** @type {ol.geom.GeometryType} */ ('Polygon') 
    }); 
    map.addInteraction(draw); 
} 

Nun, was ich will, ist, nachdem ich das Polygon ein Ajax-Aufruf zeichnen ausgelöst. Aber ich weiß nicht, wie Sie den Feature-Callback für ein benutzerdefiniertes Steuerelement hinzufügen. Ich benutze dafür Openlayers 3.

Antwort

0

Sie können die Quelle in opt_options an das Steuerelement übergeben und dann das Steuerelement auf "addfeature" hören lassen.

source.on('addfeature', function(feature) { 
     // do something with the feature 
    }, this); 
Verwandte Themen