0

I am trying to get the categorized symbology for a single WMS layer in the layer switcher.

See my code below (I am getting error OpenLayers.Control.WMSLegend is not a constructor) My OpenLayers Map //OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

var map;

function init() { map = new OpenLayers.Map('ch05_wmsfeatureinfo', {});

// Setup our two layer objects var wms_layer_map = new OpenLayers.Layer.WMS( 'Base layer', 'http://vmap0.tiles.osgeo.org/wms/vmap0', {layers: 'basic'}, {isBaseLayer: true} );

        var okombahe_town_and_townlands = new OpenLayers.Layer.WMS(
            'Townland_Boundary',
            'http://192.168.0.112:8080/geoserver/Erongo/wms',
            {layers: 'Erongo:okombahe_town_and_townlands',
            transparent: true,
            isBaseLayer: false},
            {visibility: false, opacity:0.5}
        );

        var okombahe_extensions = new OpenLayers.Layer.WMS(
            'Extension_Boundaries',
            'http://192.168.0.112:8080/geoserver/Erongo/wms',
            {layers: 'Erongo:okombahe_extensions',
            transparent: true,
            isBaseLayer: false},
            {visibility: false, opacity:0.5}
        );



        var okombahe_erven = new OpenLayers.Layer.WMS(
            'Okombahe Erven',
            'http://192.168.0.112:8080/geoserver/Erongo/wms',
            {layers: 'Erongo:okombahe_erven',
            transparent: true,
            isBaseLayer: false},
            {visibility: false, opacity:0.5}
            );

                    map.addLayers([
                    wms_layer_map,
                    okombahe_town_and_townlands,
                    okombahe_extensions,
                    okombahe_erven,
                    ]);

map.addControl(new OpenLayers.Control.LayerSwitcher({}));
map.addControl(new OpenLayers.Control.WMSLegend({
class: 'ol_legend'

}));

map.setCenter(new OpenLayers.LonLat(30, -30), 4);

OpenLayers.Control.WMSLegend = OpenLayers.Class(OpenLayers.Control, { class: null, wmsVersion: '1.3.0', format: 'image/png', draw: function () { var legendP = document.createElement('p'); legendP.innerHTML = 'Legend:'; this.div = document.createElement('div'); this.div.className = this.class + ' olControlNoSelect'; this.div.appendChild(legendP); var layers = this.map.layers; for(var i=0;i

info = new OpenLayers.Control.WMSGetFeatureInfo({ url: 'http://192.168.0.112:8080/geoserver/Erongo/wms', title: 'Identify features by clicking', queryVisible: true, eventListeners: { getfeatureinfo: function(event) { if (event.text.length>658) // <<=== use this, empty feature return 658 character or just check the length using alert(event.text.length);

            {

            var pops = map.popups;
             for (var a = 0; a < pops.length; a++) {
                 if (pops.length == 1) {
                     map.removePopup(map.popups[0]);
                 }
             };

            map.addPopup(new OpenLayers.Popup.FramedCloud(
                "ayam", 
                map.getLonLatFromPixel(event.xy),
                null,
                event.text,
                null,
                true
            ));
            }
        }
    }
});

 map.addControl(info);
info.activate();
}

Activated

  • Please format or delete your xml (it's not really relevant) what is returned by that url? – Ian Turton Oct 13 at 18:02
  • Do you mean I should format the SLD? I have deleted it because I forgot the shortcut on how to format the code. The URL returns a picture with the legend that I would like to have in Openlayers. My problem is how to get the WMS legend with categorized symbols from Georserver to Openlayers displayed in a layerswitcher? – Amelia Nicodemus Oct 13 at 18:13
  • 2
    GetLegendGraphic is an OGC SLD operation, typically associated with OGC WMS. It's not specific to GeoServer. – nmtoken Oct 13 at 18:27
  • @nmtoken noted. – Amelia Nicodemus Oct 13 at 18:28
  • I have updated my question, it appears that my problem is calling the legend in Openlayers, everything else looks fine. – Amelia Nicodemus Oct 14 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.