第二次添加功能不起作用?

时间:2015-04-12 14:13:34

标签: openlayers-3

我正在尝试通过websocket向OpenLayers3地图添加新功能。 Websocket正在获取数据,我可以在控制台日志中看到它,但它在第一个之后就不会在地图上显示。

为什么第一个功能会起作用,其余的功能失败,我很困惑。

这是代码

      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 个答案:

答案 0 :(得分:0)

好的,我只是想为别人回答。 解决方案相当简单,需要对坐标进行适当的投影。

相关问题