0

I need add and quit a layer WFS vía Leaflet Control, So far I can add the WFS layer to the map, but how do I add it and remove it using the leaflet control?

This is my code.

var owsrootUrl ='http://geo.gporellana.gob.ec/geoinfo/gadpo/wfs';

var defaultParameters = {

          service: 'WFS',
          version: '2.0.0',
          request: 'GetFeature',
    typeName: 'gadpo:clima_estacion',
    outputFormat: 'application/json',
    format_options:'callback:getJson',
    SrsName:'EPSG:4326'
};

var parametres = L.Util.extend(defaultParameters);

var URL = owsrootUrl + L.Util.getParamString(parametres);
var WFSLayer =null;

var ajax = $.ajax({

    url:URL,
    dataType:'json',
    jsonpCallback:'getJson',
    success: function(response){
       WFSLayer = L.geoJson(response,{
            style:function(feature){
                return {
                    stroke:true,
                    fillColor:'FFFFFF',
                    fillOpacity:0
                };
            },
            onEachFeature: function (feature, layer){
                popupOptions = {maxWidth: 200};
                layer.bindPopup("<span style='color: green'>Estación Meteorológica</span> " + feature.properties.nam, popupOptions);
            }
        });//.addTo(mapa);
    }

});
0
1

You should have a look at the relevant Leaflet tutorial. In your case this would look similar to this:

 L.control.layers({}, {"Climate stations": WFSLayer).addTo(map);

You will receive a layer control with a checkbox that lets you toggle your WFSLayer on and off.

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.