What could be the reason for this code working?
function addMap() {
var view = new ol.View({
center: ol.proj.fromLonLat([29.5646, 44.1575]),
zoom: 4
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: view
});
}
...while this code is not functioning?
var view = new ol.View({
center: ol.proj.fromLonLat([29.5646, 44.1575]),
zoom: 4
});
function addMap() {
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: view
});
}
One might assume that a variable declared outside a function is global and accessible from anywhere in the script.