[GIS] Openlayers drawing interaction geometryFunction

draw-interactiongeometrymap-drawingopenlayers

Can anyone help me to convert this function so that it is not dependant on the ol3-debug file as I don't know quite what is replaced upon build. The function works but only in debug mode.

It is in reference to this question: Sketch event in Openlayers 3 drawing interaction

The intention is that it will allow me to display each features co-ords as they are drawn on-screen.

geometryFunction: function (c, g) {
        if (goog.isDef(g)) {
            g.setCoordinates(c);
        } else {
            g = new ol.geom.LineString(c);
        }
        if (c[0].length > ct) {
            console.log('click coord : ' + c[0][c[0].length - 1]);
            ct = c[0].length;
        } else {
            console.log('move coord : ' + c[0][c[0].length - 1]);
        }

        return g;
    }

Best Answer

You can use:

var draw = new ol.interaction.Draw({
    source: vectorSource,
    type: "LineString",
    geometryFunction: function(coords, geom) {
        if (!geom) {
            geom = new ol.geom.LineString(null);
        }
        console.info(coords);
        geom.setCoordinates(coords);
        return geom;
    }
});
map.addInteraction(draw);

See https://gis.stackexchange.com/a/152646/50718

http://jsfiddle.net/jonataswalker/8b322285/