[GIS] find or get map in openlayers

findopenlayers

i want to know how to name maps, put an id or something to find it later on openlayers, for example:

div id="map1">

div id="map2">

adition all code to set a map for fill it like:

map1 = new ol.Map({
id: 'Maps 1',
target: 'map1' });

map2 = new ol.Map({
id: 'Maps 1',
target: 'map2' });

then i could find the div for map 1 or 2 with

mapDiv1 = document.getElementbyId('map1');

mapDiv2 = document.getElementbyId('map2');

but how can i Access the map in mapDiv1 o mapDiv2 ?

also i would like how to do this:

$.getJSON(theme.url, null, function (data)

but with pure JavaScript, that is couse data only exist inside this function, even if i asign it to a global variable it gets me null, also i don't use jquery or other frameworks just JavaScript.

Best Answer

but how can I Access the map in mapDiv1 or mapDiv2 ?

Access can mean many things...

If by "access" you mean controlling the map: Normally you don't use the DOM elements for that. You control the map through your (openlayers) map-objects map1 and map2.

Examples:

var baselayer = new ol.layer.Tile({
    source: new ol.source.OSM({
        wrapX:false
    }),
    opacity: 0.7
});
var mpos = new ol.control.MousePosition({
    prefix: 'coordinates: '
});
map1.addLayer(baselayer);
map2.addLayer(baselayer);
map2.addControl(mpos);

If "access" ment you want to get the map as an image, then see this example: Export map.

Did you mean something else?

Related Question