I want to render freehand drawn geometry from a geojson object on a map. I have the freehand drawing all set up and working. The geometry is LineString but I am adding the freehand: true property which works. Now after getting the coordinates on 'drawend' event using

var shape = event.feature.getGeometry();
var coords = shape.getCoordinates();

I am saving the coordinates e.g [[-1.213123, 3.123123], [0.213123, 2.2312123]], so I can load it later.

To render it, I am doing the following

        var geojsonObject = {
            'type': 'FeatureCollection',
            'crs': {
                'type': 'name',
                'properties': {
                    'name': 'EPSG:3857'
            'features': [{
                'type': 'Feature',
                'geometry': {
                    'type': 'LineString',
                    'coordinates': [[-1.213123, 3.123123], [0.213123, 2.2312123]],
                    'freehand': true

        var vectorSource = new ol.source.Vector({
            features: (new ol.format.GeoJSON()).readFeatures(geojsonObject),

to get my vector source, but it renders as an actual lineString instead of a drawn lineString. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.