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.
Best Answer
To summarize what we say in comments and to add a solution:
To put a contol in a custom div use the
target
property of the control:To allow the click on your custom div to trigger the control functionnality, you need a bit of CSS:
Tested here , I've verified with the console and the click is well triggered.