0

I have added a WMS layer to the map. Now I want to add styles to the WMS layer using filters.

I have tried with the below code but it is not working

  var poilayer = new OpenLayers.Layer.WMS("poi",
            "http://localhost:8080/geoserver/cite/wms",
            {
                "LAYERS": "AMBALA_sma",
               srs:'EPSG:3857',
               transparent: true,           
                format: "image/png"     
            }, 
            {
                isBaseLayer: false,
                buffer: 0,
                visibility: true
            }
         );
  info = new OpenLayers.Control.WMSGetFeatureInfo({
         url: 'http://localhost:8080/geoserver/cite/wms',
         title: 'Identify features by clicking',
         layers: [poilayer],
         vendorParams: {
            propertyName: "P_TYPE,WAQF_ID"
        },
        // hover:true,
         queryVisible: true,

         eventListeners: {
             getfeatureinfo: function(event) {

                      popupwindow = new OpenLayers.Popup.FramedCloud(
                      "chicken",
                      mapPanel.map.getLonLatFromPixel(event.xy),
                      null,
                      event.text,
                      null,
                      true
                      );

   mapPanel.map.addPopup(popupwindow);
        }  

   }

});
    mapPanel.map.addLayer(poilayer);
     mapPanel.map.addControl(info);
     info.activate();

    var filter = new OpenLayers.Filter.Comparison({
    property: 'P_TYPE',
    type: OpenLayers.Filter.Comparison.EQUAL_TO,
    value: 'MOSQUE'
});



/* Rule */
var rule = new OpenLayers.Rule({
    filter: filter,
    symbolizer: {fillColor: "green"}
});


/* Style */
var style = new OpenLayers.Style();
style.addRules([rule]);

/* Style map */
styleMap = new OpenLayers.StyleMap(style);
poilayer.styleMap = styleMap;   

Please tell me where I am doing mistake.

I am using WMSGetFeatureInfo because I have tried with WFS for 1 week but it was not success. So I am using WMS only.

I have added a dropdown in my page. In that dropdown the values are houses, mosques which are in the shapefile also(column name is 'P_TYPE'). When user selects the houses then houses has to be highlighted in the WMS layer.

GetFeatureInfo is necessary. By using the above code selected features are not highlighting.

Please tell me how to create SLD

  • please edit your question to tell us what is not working, What are you trying to style? is there a reason not to style the layer in GeoServer? is GetFeatureInfo relevant? – Ian Turton Mar 8 '17 at 8:41
  • You can't add styles to WMS images using OpenLayers symbolizers. You'll need to create SLD and send back to the WMS service – nmtoken Mar 8 '17 at 19:54
  • i have added a dropdown i my page. In that dropdown the values are houses,mosques which are in the shapefile also(column name is 'P_TYPE'). when user selects the houses then houses has to be highlihted in the wms layer. GetFeatureInfo is necessary. By using the above code selected features are not highlighting. Please tell me how to create SLD. – iit Mar 9 '17 at 3:51
  • A WMS GetFeatureInfo operation (effectively) gets information about the data that is used to create the map image at a point (image coordinates) in the map, it does not highlight the feature(s). – nmtoken Mar 9 '17 at 10:58
1

Please tell me where I am doing mistake.

You can't add styles to WMS images using OpenLayers symbolizers. You'll need to create SLD and send back to the WMS service

-3

We cannot add styles to wms layer so i have added wfs layer and the added styles to that layer.

Below is my code:

  var e = document.getElementById("assets");
  var asset = e.options[e.selectedIndex].value;
            var wfslayer        = new OpenLayers.Layer.Vector(asset, {

               strategies: [new OpenLayers.Strategy.BBOX()],
               projection: new OpenLayers.Projection("EPSG:3857"),
               protocol: new OpenLayers.Protocol.WFS({
               version: "1.0.0",
                               url:  "http://localhost:8080/geoserver/wfs",
               featurePrefix: "cite",
               featureNS: "http://www.opengeospatial.net/cite",
                               featureType: "AMBALA_sma",
               geometryName: "the_geom",
               rsName: "EPSG:3857"
                           }),

            styleMap: new OpenLayers.StyleMap({
                 fillColor: "#ff0000",
                 strokeWidth: 1,
                strokeColor: "#333333"
            }),
            filter: new OpenLayers.Filter.Logical({
                type: OpenLayers.Filter.Logical.OR,
                filters: [
                    new OpenLayers.Filter.Comparison({
                        type: OpenLayers.Filter.Comparison.EQUAL_TO,
                        property: "P_TYPE",
                        value: asset
                    })
                    ]
                    })
            });

mapPanel.map.addLayers([wfslayer]);
  • It's not correct that you can't add styles to WMS layer, as per comments to the question. Your answer here does not answer the question posed, it answers a different question. – nmtoken Mar 24 '17 at 7:47

Your Answer

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

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