Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm implementing an appication with openlayers 2.12. Gets features from Geoserver after CQL search. Now, when the users clicks on one point/line/polygon, gets textual info via websockets (nodejs) for what she clicked.

Also, a "menu" to modify the clicked feature appears.

After user edits the features, I want to get the FID and geometry, so I can save them via websockets again. To get clicked feature's FID and geometry I use the same "selected_feature" function. The FID/geometry they are availiable to modify functions, because the vars are global.

Now, this works for a couple of times (with some bugs) and if I refresh the page, the features never render , but I can see them in the console.

Please be patient , and please advice me, I dont know how to fix this. I thought it was a good idea, but I cannot get it to work.

Thanks for your time.

The code

    var modifyControl;
    var jas;
    var sf;
    var sfi;

    //Add a select feature control 
    var select_feature_control = new OpenLayers.Control.SelectFeature(pins, {
    multiple: false,
    toggle: true});


    //Activate the control 

    //split the feature, to get the id 
    function selected_feature(event){
        var sf = event.feature.fid;        
         var sfs = sf.split(".");
         var sff = sfs[1];
         sfi = event.feature.id;
        //the jas and sfi above, are globals so are availiable to the modify functions

       //create websockets, send the id , to get textual info, alert them--works
        var so = new WebSocket("ws://localhost:8000");

          so.onerror=function (evt) 
         {response.textContent = evt;}

         so.onopen = function(){
          response.textContent = "opened";

         so.onmessage = function (evt) { 
        var received_msg = evt.data;
            var packet = JSON.parse(received_msg);
            var ena=packet['text'];alert ('text '+ena);
            var dio=packet['nam'];alert('nam '+dio);


    pins.events.register('featureselected', this, selected_feature);
    //add modifyFeature
    modifyControl = new OpenLayers.Control.ModifyFeature(pins);

    //called from html form 
    function changeMode() {
    //activate control
    var mode = null;

    //ste mode
    if(document.getElementById("reshape").checked) {
    mode |= OpenLayers.Control.ModifyFeature.RESHAPE;
    if(document.getElementById("resize").checked) {
    mode |= OpenLayers.Control.ModifyFeature.RESIZE;
    if(document.getElementById("rotate").checked) {
    mode |= OpenLayers.Control.ModifyFeature.ROTATE;
    if(document.getElementById("drag").checked) {
    mode |= OpenLayers.Control.ModifyFeature.DRAG;
    //this is to set the mode on the control
    modifyControl.mode = mode;

    //called from html form 
    function saveedpoint(){
    //sfi is global....
    var grabf=pins.getFeatureById(sfi).geometry;

        //create websockets to send
        var ef = new WebSocket("ws://localhost:8000");

          ef.onerror=function (evt) 

                    //get original geomerty, turn it to string
                      var org=new String(grabf);

                  //get first 5 letters
             var frontpiece=org.substring(0,5);

                        //if they are point, send the corresponding data
                  var gtog=org.substring(6,org.length-1);
                          ef.onopen = function(){
                         ef.send(JSON.stringify({command: 'editedfeature',
                           idoff: jas,
                   newgeo: gtog,

    //same ifs for linestring and polygon....

       ef.onmessage = function (evt) {var received_msg = evt.data;


I click a feature and the text data alerts. I press ok. I get to the modify menu and pick "drag" for example. I click the feature again. Alert appears again. Kind fo bug, but I can tolerate it. I drag the feature, and Click "Save". saveedpoint activates. and saves the geometry. But sometimes the whole system is very slow. An if the page gets refreshed, the features never appear on the map again.

Please help. Advice, give tips, or suggest another way around.


share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.