[OpenLayers-Users] Adding multiple Image Layers
Bennos
benjaminpreisig at gmx.at
Thu Jun 28 10:50:28 PDT 2012
Hi,
I am trying to add two OpenLayers.Layer.Image() layers to my map but if I am
adding both at the same time, they will not appear.
When I am trying to add just one layer, with the code for the other one
commented everything works fine. But if I just create the .Image() Object
for the second image without adding it to the map, no image is shown. After
some research with Firebug I found that the aspectRatio for the second image
is set to "NaN", altough I am defining it. Furthermore the images are not
even loaded.
The images have the exact same size and should be visible at the exact same
place. When adding only one Layer and changing the URL manually with
layer.setUrl("image.png"); everything works fine.
Below I am posting my code, help is much appreciated.
Cheers,
b
function init(){
// increase reload attempts
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
var spherical = new OpenLayers.Projection("EPSG:900913");
var geographical = new OpenLayers.Projection("EPSG:4326");
var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508,
20037508),
restrictedExtent = maxExtent.clone(),
maxResolution = 156543.0339;
var boundaries = new OpenLayers.Bounds(8.098224, 45.772682, 17.74378,
49.478924);
var options = {
projection: spherical,
displayProjection: geographical,
units: "m",
numZoomLevels: 21,
maxResolution: maxResolution,
maxExtent: maxExtent,
restrictedExtent: restrictedExtent,
};
var map = new OpenLayers.Map('map', options);
var osm = new OpenLayers.Layer.OSM("OpenStreetMap");
map.addLayer(osm);
var theme = new OpenLayers.Layer.Image(
"Data",
"data/prec1h/GOOGLE.RR_15min.20120612.1215.15.png",
boundaries.transform(geographical,spherical),
new OpenLayers.Size(598, 378),
{
isBaseLayer: false,
resolutions:map.layers[0].resolutions,
maxResolution : map.layers[0].resolutions[0],
aspectRatio: 0.9024712214132586
// visibility: false
}
);
map.addLayer(theme);
var meme= new OpenLayers.Layer.Image(
"otherData",
"data/prec1h/GOOGLE.RR_15min.20120612.1230.15.png",
boundaries.transform(geographical,spherical),
new OpenLayers.Size(598, 378),
{
isBaseLayer: false,
resolutions:map.layers[0].resolutions,
maxResolution : map.layers[0].resolutions[0],
aspectRatio: 0.9024712214132586
// visibility: false
}
);
map.addLayer(meme);
console.log(theme);
console.log(meme);
var lat=47.5;
var lon=13.3333;
var zoom = 7;
var center=new OpenLayers.LonLat();
center.lon=lon;
center.lat=lat;
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(center.transform(geographical,spherical),zoom);
}
--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Adding-multiple-Image-Layers-tp4984653.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list