getting attributes of Openlayer Map by Javascript

المشرف العام

Administrator
طاقم الإدارة
I have created an OpenLayers map via the following code:

var map = new ol.Map({ target: 'mapdiv', layers: [ new ol.layer.Tile({ source: new ol.source.MapQuest({layer: 'sat'}) }), new ol.layer.Tile({ source: new ol.source.MapQuest({layer: 'hyb'}), opacity:01 }) ], view: new ol.View({ center: ol.proj.transform([7.72,47.94], 'EPSG:4326', 'EPSG:3857'), zoom: 10 }) }); console.log('map created'); Now, of course, 'mapdiv' is the ID of the div I want the map to show up. This part is working according to the plan.

I nonetheless am implementing a seperate JS library to manipulate maps. As such, I want to access the created map (post creation) and its informaption. I look at the built in DOM inspector in firefox, to see what exactly is created inside my div called 'mapdiv'.

The direct child of my 'mapdiv' is : <div style="position: relative; overflow: hidden; width: 100%; height: 100%;" class="ol-viewport">, which inturn has the child :

This canvas seems to be the relevant one here. In the firefox element inspector console, hovering my mouse over this generates a small preview of the map. See Image please :



So I would like to grab the openlayer.Map object responsible for this, and call the calculateBounds method, to know the latitude and longitude boundaries of the displayed map.

Noting that the map is displayed in an element given by class, I am aware of this. But note that I am not aware of the class name beforehand. If forexample, there are multiple maps, then using the linked method won't work, because they all have the same class, despite residing inside different divs.

I thus need a method to access the openlayer maps in a div element via javascipt, if the div ID is known.

Any pointer would be appreciated.

Edit: I am using openlayers -3



أكثر...
 
أعلى