OPENLAYERS Add/Save new feature into existing GeoJson file

by Edgar Rodriguez   Last Updated April 16, 2018 07:22 AM

I have one point that I found geocoding api and I can create vertor layer with the point. but I cant add to my exiting GeoJson file and I need to save this new point into a existing GeoJson file like new feature point. But I cant found the correct way. Please can you give me some suggestions of How I can to add/save one new feature point into a existing GeoJson file??? I try with Writefeaute and Addfeature but nothing happen.

Thank you.

part of my code:


// VCoord = Lat and Log result of geocodingAPI.
// Add point // var point_feature = new ol.Feature({}); var point_geom = new ol.geom.Point(ol.proj.transform(vCoord, 'EPSG:4326', 'EPSG:3857')); point_feature.setGeometry(point_geom);

var vector_layer = new ol.layer.Vector({ source: new ol.source.Vector({ features: [point_feature] }), style: new ol.style.Style({ image: new ol.style.Icon(({ anchor: [0.5, 0.9], src: iconpng })), text: new ol.style.Text({ font: '13px Calibri,sans-serif', fill: new ol.style.Fill({ color: '#ffffff' }), stroke: new ol.style.Stroke({ color: '#000000', width: 2 }), text: vformatted[0], // Formated Address like Label// offsetY: 15 }) }) }); map.addLayer(vector_layer);

      //ADD MY EXITING GEOJSON FILE INCIDENTS//
      var vectorIncident = new ol.layer.Vector({
            source: new ol.source.Vector({
              url: "geo_json/Incidents.geojson",
              format: new ol.format.GeoJSON()
            }),
            style:  new ol.style.Style({
                    image: new ol.style.Icon(({
                    anchor: [0.5, 0.9],
                    src: 'symbols/police.png'
                    }))
             })
          });

          map.addLayer(vectorIncident);

     //write the new point into the existing GeoJson
     vectorIncident.writefeature(vector_layer.getSource().getFeatures());


Related Questions



show all features in popup using openlayers 2

Updated September 23, 2017 05:22 AM

Missing files in HEC-RAS 5.0.3

Updated February 11, 2017 13:51 PM

Save as .csv with SEMICOLON separator by default

Updated April 19, 2017 16:22 PM

Cannot save anything in QGIS

Updated June 23, 2018 22:22 PM