问题
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