Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Prompting suggestions I’m going to attempt to reword my question

I have a PostGis table that contains overlapping vector polygons. I need to display a selection in Geoserver and provide functionality for the user to toggle on & off unwanted polygons.

I need to add multiple layers from a PostGis Table.

I’ve made a start with the code below but I’m stuck with the following:

  • Why are all the layers Base Layers? Land should be the only base layer the rest overlays?

  • Can all overlay layers be on at once?

  • How do I move the layerswitcher control outside the map area? When I click inside the map how do I show the attribution?

  • How do I create a new layer by script either with a polygon given a
    co-ordinate string, or a point and radius?

  • How do I create a list of all the selected layers?

    body { margin: 1em; } #map { width: 800px; height: 475px; border: 1px solid black; } OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

        var map;
        function init(){
            map = new OpenLayers.Map('map');
            var Base = new OpenLayers.Layer.WMS(
                "Land",
                "http://localhost:8080/geoserver/cite/wms",
                {LAYERS: 'cite:land',
                 format: 'image/png',
                 isBaseLayer: true
    
                }
            );
    
            var L10299 = new OpenLayers.Layer.WMS(
                "10299",
                "http://localhost:8080/geoserver/cite/wms",
                {
                VIEWPARAMS: 'kathy:10299',
                LAYERS: 'cite:Q_Results',
                isBaseLayer: false
                }
            );
    
    
            var L43352 = new OpenLayers.Layer.WMS(
                "43352",
                "http://localhost:8080/geoserver/cite/wms",
                {
                VIEWPARAMS: 'kathy:43352',
                LAYERS: 'cite:Q_Results',
                isBaseLayer: false
                }
            );
    
    
            var L25177 = new OpenLayers.Layer.WMS(
                "25177",
                "http://localhost:8080/geoserver/cite/wms",
                {
                VIEWPARAMS: 'kathy:25177',
                LAYERS: 'cite:Q_Results',
                isBaseLayer: false
                }
            );
    
    
            map.addLayers([Base, L10299, L43352, L25177]);
    
    
    
            map.addControl(new OpenLayers.Control.LayerSwitcher());
    
            map.zoomToExtent(
                new OpenLayers.Bounds(12.996, 52.172,13.931, 52.958)
            );
        }
    </script>
    

    OpenLayers PostGis Layers

share|improve this question
    
I think your question is poorly worded, please take some time to revise it or it's going to be impossible to help you. Read the gis.stackexchange.com/faq –  unicoletti Mar 25 '12 at 17:34

1 Answer 1

up vote 3 down vote accepted

Yes it's possible.

Starting with GeoServer 2.1.0 the user can also create a new layer by specifying a raw SQL query

You can create SQL Views which reference the same table using SQL Statements.

Instructions and Documentation

Update Per OpenLayers question in comment:

It really depends on how you want to serve out your data which depends on what kind and how much data you have.

If the data is vector data and not more than +-300 features you can use WFS. Add that layer like so: OpenLayers GeoServer WFS Layer Example

If the data is Raster data or you just want your layer served out as an image rather than vector features, then add that layer using WMS. Like so: OpenLayers WMS Layer Example

Update #2:

Based on your latest comment, what you can do is: add multiple wfs layers to your open layers map which point to ONE layer on your GeoServer but have a filter defined so you only get ONE feature back based on ID or some other attribute in your filter.

Take a look at this example.

Basically it will be something like:

var wfs = new OpenLayers.Layer.Vector("WFS", {
    strategies: [new OpenLayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
        url: "http://demo.opengeo.org/geoserver/wfs",
        featureType: "tasmania_roads",
        featureNS: "http://www.openplans.org/topp"
    }),
    filter: new OpenLayers.Filter.Logical({
        type: OpenLayers.Filter.Logical.And,
        filters: [
            new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.EQUAL_TO,
                property: "id",
                value: "POLYGONID"
            })
        ]
    })
});
share|improve this answer
    
I've built sql views before and passed a value on the url. with one feature on a Single layer. How might I do this using OpenLayers using a single polygon per multiple Layers? –  Holly Mar 23 '12 at 17:33
    
Is that your question? If so, please include it somewhere in your question by editing your original question. You need to try to provide as much information about what your trying to achieve as possible so people can help you. Without mention of OpenLayers in a tag, in your title, or in your question how would someone know that's where you want to add your layers? Please see my update. –  CaptDragon Mar 23 '12 at 18:33
    
The data is vector Each layer will contain one feature specified by the Polygon id (if I use a view this will be the variable) but named by an attribute In the example given the line ' var wfs = new OpenLayers.Layer.Vector("States", {' I assume var wfs is arbitrary, what is the syntex for adding a view like viewparams=id:1234 I didn't put openlayers in the title as i wasn't convinced that was the way to go –  Holly Mar 25 '12 at 13:07
    
You can create multiple layers in your GeoServer. Or keep ONE Layer and call var wfs = new OpenLayers.Layer.Vector("States" but supply a wfs filter... SEE MY UPDATE. –  CaptDragon Mar 28 '12 at 13:27
    
Thanx Is there any advatage using Filters over Views Will a filter alow deselecting of unwanted polygons Why would this line (also PanZoomBar) map.addControl(new OpenLayers.Control.Scale($('scale'))); Produce this error in FF error consol .. is not a constructor Opologies is question in wrong place –  Holly Mar 29 '12 at 10:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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