1

I have three layers, the base layer and two WMS layers. When I load the map, one of them always shows up even when I put visibility:false. And when it shows up, the base layer disappears. What can I do?

My code in OpenLayers is:

map = new OpenLayers.Map('map', {controls: [], displayProjection: new OpenLayers.Projection("EPSG:32632"), numZoomLevels: 31, tileSize: new OpenLayers.Size(256,256)});
wms1 = new OpenLayers.Layer.WMS('base', 'http://172.26.10.126/fcgi-bin/mapserv.exe?map=/ms4w/apps/guinea/guinea.map', {layers: 'base'},{isBaseLayer:true, visibility:true,transparent:true});
wms2 = new OpenLayers.Layer.WMS('guinea','http://172.26.10.126/fcgi-bin/mapserv.exe?map=/ms4w/apps/guinea/guinea.map', {layers: 'guinea'},{isBaseLayer:false, visibility:true,transparent:true});
wms3 = new OpenLayers.Layer.WMS('municipios','http://172.26.10.126/fcgi-bin/mapserv.exe?map=/ms4w/apps/guinea/guinea.map', {layers: 'municipios'},{isBaseLayer:false, visibility:false,transparent:true});
map.addLayers([wms1,wms2,wms3]);
map.zoomToExtent(new OpenLayers.Bounds(123360.47,-162161.43,767730.83,418254.41));
map.setCenter(new OpenLayers.LonLat(8.80899,1.83925), 7);
map.addControl( new OpenLayers.Control.LayerSwitcher() );

And my map file is:

LAYER
NAME "base"
STATUS ON
PROCESSING "LABEL_NO_CLIP=True"
CONNECTIONTYPE POSTGIS
CONNECTION "host=localhost user=postgres dbname=Guinea_Ecuatorial password=tph"
DATA "geom from gnq_africa_central using unique gid srid=32632"
METADATA
    WMS_NAME "base"
    WMS_SRS "EPSG:32632 EPSG:4326"
END
TYPE POLYGON
LABELITEM "na2_descri"
CLASS
    STYLE
        COLOR 185 122 87
        OUTLINECOLOR 0 0 0
    END
    LABEL
        TYPE TRUETYPE
        FONT "arial"
        SIZE 15
        COLOR 0 0 255            
        ANTIALIAS TRUE
    END
END

LAYER
NAME "provincias"
STATUS ON 
PROCESSING "LABEL_NO_CLIP=True"
CONNECTIONTYPE POSTGIS
CONNECTION "host=localhost user=postgres dbname=Guinea_Ecuatorial password=tph"
DATA "geom from gnq_provincia using unique gid srid=32632"
METADATA
    WMS_NAME "provincias"
    WMS_SRS "EPSG:32632 EPSG:4326"
END
TYPE POLYGON
LABELITEM "provincia"
CLASS
    STYLE
        COLOR 85 185 107
        OUTLINECOLOR 0 0 0
    END
    LABEL
        TYPE TRUETYPE
        FONT "arial"
        SIZE 15
        COLOR 255 0 128
        ANTIALIAS TRUE
        POSITION CC
    END
END
LAYER
NAME "municipios"
STATUS ON
PROCESSING "LABEL_NO_CLIP=True"
CONNECTIONTYPE POSTGIS
CONNECTION "host=localhost user=postgres dbname=Guinea_Ecuatorial password=tph"
DATA "geom from gnq_municipios using unique gid srid=32632"
METADATA
    WMS_NAME "municipios"
    WMS_SRS "EPSG:32632 EPSG:4326"
END
TYPE POLYGON
LABELITEM "distrito"
CLASS
    STYLE
        COLOR 85 185 107
        OUTLINECOLOR 0 0 0
    END
    LABEL
        TYPE TRUETYPE
        FONT "arial"
        SIZE 10
        ANTIALIAS ON
        COLOR 0 0 0
        POSITION CC
    END
END

The layer that always shows up is "distritos".

2 Answers 2

1

'transparent' is a WMS parameter (by default it's false), so put it together with 'layers' and try again.

2
  • It works but the layer always appear when I up the layer provincias. What's the problem? Thx by the way for the answer. Commented Jul 29, 2014 at 12:08
  • I fix it. I have a bad layer name. Commented Jul 29, 2014 at 12:13
1

I think you simply need to add percent opacity to your layer options:

...{layers: 'municipios'},
 {isBaseLayer:false, visibility:false,transparent:true,opacity:0.5}
);
1
  • Mingfeng was rigth it works when I put the transparent parameter in the rigth place. Commented Jul 29, 2014 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.