0
votes

I am trying to add new features to OpenLayers3 map through websocket. Websocket is getting data , and I can see it in console log but it never shows on the map after first one.

Why would first feature work, and rest of them fail , I am puzzled.

Here is the code

      function positioningUpdate() {
      var host = 'ws://127.0.0.1:9000/websocket/';
      websocket = new WebSocket(host);
      websocket.onopen = function (evt) {
          console.log('Opend Conn.')
      };
      websocket.onmessage = function(evt) {
        var new_position = JSON.parse(evt.data);
        console.log(new_position);
        //global = new_position;
        gJSONFeatures.addFeature(new ol.Feature({
          geometry: new ol.geom.Point([new_position.data.lat, new_position.data.lon]),
          name: new_position.TAG,
          style: point_style
        }));

        console.log('WORKS: gJSONFeatures.addFeature');
      }
      websocket.onerror = function (evt) { };
      websocket.onclose = function (evt){
        console.log('Closed Conn.');
      };
  };
  positioningUpdate();
</script>
1
Can you share a JSFiddle to reproduce? - bartvde

1 Answers

0
votes

Ok I just want to put answer for others. Solution was rather simple, coordinate needs to be put in proper projection.