javascript - Saving the coordinates of multiple points in OL3 -


i'm using openlayers3 , have map user can draw 1 or more points. implemented that. however, i'd save coordinates of every point.

but don't know how that, since openlayers3 rather new , i'm having hard time finding examples online.

this have far:

var modeselect = document.getelementbyid('type'); var draw; // global can remove later  //modify  var featureoverlay = new ol.featureoverlay({   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); // modify end  function addinteraction() {     var value = modeselect.value;     if (value == 'point') {         draw = new ol.interaction.draw({           //source: source,           features: featureoverlay.getfeatures(),           type: /** @type {ol.geom.geometrytype} */ (value)         });         map.addinteraction(draw);     }     // modify     if (value == 'modify') {         var modify = new ol.interaction.modify({             features: featureoverlay.getfeatures(),             // shift key must pressed delete vertices,             // new vertices can drawn @ same position             // of existing vertices             deletecondition: function(event) {             return ol.events.condition.shiftkeyonly(event) &&                 ol.events.condition.singleclick(event);           }         });         map.addinteraction(modify);     }  } addinteraction(); 

ok. came solution @ least step in right direction. rearranged code in general , implemented function:

function savedata() {     // save geojson     var format = new ol.format['geojson']();     // data in chosen format     var data;      try {     // convert data of vector_layer chosen format     data = format.writefeatures(vector_layer.getsource().getfeatures());     } catch (e) {     // @ time of creation there error in gpx format (18.7.2014)     $('#data').val(e.name + ": " + e.message);     return;     }      $('#data').val(json.stringify(data, null, 4));  } 

i'm still struggling write actual .json-file on server though, i'm pretty confident i'll find solution.

edit:

it pretty simple actually. wrote piece of php work:

    <?php      include 'dbconnection.php';           $str="insert multipoint_tabelle (id, geom) values (1,(select st_multi(st_union(geom)) punkttabelle));";         $test_str=pg_query($conn, $str);       // write geojson           $json = $_post['json'];         //$points_coords = $_post['coords'];          if (json_decode($json) != null) { /* sanity check */          // w+ read/write. opens , clears contents of file; or creates new file if doesn't exist             $file = fopen('points.json','w+');             fwrite($file, $json);             fclose($file);         } else {          // handle error          }   ?> 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -