Unable to use OpenLayers library in Browser Debugger Console (React JS)

女生的网名这么多〃 提交于 2019-12-11 15:14:53

问题


I am having one application which has OpenLayers Map and implemented using reactjs with OpenLayers library. I am trying to get the latitude and longitude of the map from the browser console in order to use the same in my selenium automation.

I am using the below code in the console and getting an error as below

Error:

"Uncaught TypeError: map.getLayers is not a function
    at <anonymous>:1:5"

Script:

   map.getLayers().forEach(function(layer){
    if(layer instanceof ol.layer.Vector){
      var features = layer.getSource().getFeatures();
      features.forEach(function(feature) {
        console.log("Features Coordinates from Main Class :"+ol.proj.toLonLat(feature.getGeometry().getCoordinates()));
     });
    }
  });

When I inspect OpenLayersMap and it has class name as map.So, I have used map.getLayers() in script.

来源:https://stackoverflow.com/questions/51067818/unable-to-use-openlayers-library-in-browser-debugger-console-react-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!