[OpenLayers-Users] Overlay and BaseLayer problem

Eric Lemoine eric.c2c at gmail.com
Wed Jun 25 10:27:38 EDT 2008


On Wed, Jun 25, 2008 at 2:36 PM, Christian Braun
<christian.braun at tudor.lu> wrote:
> Hi List,

Hello,



> I am just starting with OpenLayers and I am a looser ;-) in Javascript,
> so please be patient.
>
> I want to overlay different png images in a rudimentary map. Therefore I
> created the following code embedded in my standard html:
>
>  var map;
>            function init(){
>                map = new OpenLayers.Map ("map", {
>                controls:[
>                    new OpenLayers.Control.Navigation(),
>                    new OpenLayers.Control.PanZoomBar(),
>                    new OpenLayers.Control.Attribution(),
>                    new OpenLayers.Control.MousePosition(),
>                    new OpenLayers.Control.ScaleLine(),
>                    ],
>                numZoomLevels: 5,
>                maxExtent: new OpenLayers.Bounds(57500, 57500, 106600,
> 101800),
>                maxResolution: 'auto',
>                units: 'm',
>                projection: new OpenLayers.Projection("EPSG:2169")
>                } );
>
>                layer1 =
> newOpenLayers.Layer.Image('LAN1','/lan_output/schedule_baseline_normal_weather/schedule_baseline_normal_weather_L_den.png',
>                                new OpenLayers.Bounds(57500, 57500,
> 106600, 101800),
>                                new OpenLayers.Projection("EPSG:2169"),
>                                new OpenLayers.Size(491,443)
>                                );
>
>                layer2 = new OpenLayers.Layer.Image(
>
> 'LAN2','/lan_output/schedule_baseline_normal_weather/schedule_baseline_normal_weather_L_day.png',
>                                new OpenLayers.Bounds(57500, 57500,
> 106600, 101800),
>                                new OpenLayers.Projection("EPSG:2169"),

The third argument should be the size. Furthermore you don't need to
pass a projection object to the layer as it's already set in the map
options.

>                                new OpenLayers.Size(491,443)
>                                );
>            map.addLayers([layer1, layer2]);
>            map.addControl(new OpenLayers.Control.LayerSwitcher());
>            map.zoomToMaxExtent();
>
>
>
> I want to show the images as overlays rather than with an "or" checkbox.

So you don't want your image layers to be "baselayers", you want them
to be "overlays". To make them overlays you need to set the
isBaseLayer option to false:

layer2 = new OpenLayers.Layer.Image(
    'LAN2',
    '/lan_output/schedule_baseline_normal_weather/schedule_baseline_normal_weather_L_day.png',
    new OpenLayers.Bounds(57500, 57500,  106600, 101800),
    new OpenLayers.Size(491,443), {
        isBaseLayer: false
    }
);

That being said, it is to be noted that OpenLayers works with at least
one base layer. If you don't want really need one you can create a
fake one using:

var fake = new OpenLayers.Layer('fake', {displayInLayerSwitcher: false});
map.addLayer(fake);

> Furthermore a need a flag to set transparency of some png's.

It seems to me that either your png images are transparent or they
aren't. OpenLayers can't help you with that.

Hope this helps,

--
Eric



More information about the Users mailing list