0

Using Leaflet and GeoServer.

Basically, I want to be able to add a new layer with a different bounding box that is user defined by selecting an area on the map. I want it to work with all layers available... so if I could just get the 'layers' name and update it when a new overlay is turned on/off

User turns on a tileLayer with many points on the map. User selects an area on the map with points. The selection area is converted to new bounding box dimensions. A new layer of the same map is added but with with the new bounding box.

I have everything except how to get the name of the current tile layer so that I can make the GeoServer call. It would look like this:

var currentLayerName;

  function addGeoServerLayer(){
       geoServerLayer = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: **currentLayerName**, **<<<<<<<<<<<<<<<  I NEED THIS**
            format: 'image/png',
            transparent: false,
           CQL_FILTER : 'BBOX(geom, ' + boundingBox + ')'
        }).addTo(layersGroup);

    }

I want to be able to pull the 'layers' field from this list of tileLayers in my project (leaflet project). this way, after the user selects an area, I can make a geoserver and return the same map with new bounding box values and I can do it no matter what layer is selected.

        var layer1 = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: 'test:layer1',
            format: 'image/png',
            transparent: true
        });

        var layer2 = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: 'test:layer2',
            format: 'image/png',
            transparent: true,
        });

        var layer3 = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: 'test:layer3',
            format: 'image/png',
            transparent: true
        });

        var layer4 = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: 'test:layer4',
            format: 'image/png',
            transparent: true      
        });            

        var layer5 = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: 'test:layer5',
            format: 'image/png',
            transparent: true
        });

        var layer6 = L.tileLayer.wms("http://12.235.22.99:8080/geoserver/ows?", {
            layers: 'test:layer6',
            format: 'image/png',
            transparent: true
        });

2 Answers 2

0

The layers available at your WMS endpoint depend on the configuration of your WMS server.

Either check your GeoServer configuration, or check the getCapabilities document of your WMS endpoint. Connecting to your WMS endpoint with a graphical client (e.g. qgis) will request the getCapabilities document and display the available layer names.

4
  • Hello. Thanks for the answer. I don't really need a list of layer names, I need a way call the specific layer name... something like: "layers: layer.getName()" ... is there any method that I can pull that information and updated it depending on what tileLayer is active?
    – MH7086
    Commented Jun 26, 2017 at 17:15
  • Pull that information from where? Commented Jun 26, 2017 at 17:23
  • Sorry.. from my Leafletjs project file. You can turn tileLayers on/off. Those tileLayers are pulled form GeoServer. I would like to grab the "layers" name from whichever tileLayer is currently active (which box is checked.). That way, if I turn on layer1, var getCurrentName = <active layer name of layer 1> or whatever. Then, if I turn off 1 and turn on layer2, var getCurrentName = <active layer name of layer2>. I apologize for being confusing.
    – MH7086
    Commented Jun 26, 2017 at 17:33
  • 1
    How many tilelayers do you have? How are you instantiating them? Please edit your original question to reflect this. Commented Jun 26, 2017 at 17:58
0

For anyone needing this info.... After writing a convoluted function that hacks a geoserver url apart to get the layer name, I found out you can just use the following:

    map.on('overlayadd', function(e){
        var activeOverlay = e.layer.options.layers;
    });  

So simple.

1
  • To call the remove event map.on('overlayremove', function (e) { debugger; var activeOverlay = e.layer.options.layers; }); Commented Oct 31, 2017 at 19:44

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.