0

My base layer: google map

My points on the map: from an airports.db file, set up as a WFS layer in the OpenLayers code.

As of now:

map loads, points in the correct places on the map.

My goal:

when the page loads in the browser, the points should not display on the initial zoom. When you zoom in to the second level, they should.

I've successfully done this before using just an OpenLayers map, but never a google map as a base layer.

For MAXSCALEDENOM I've tried all sorts of values, but the points are always displaying.

Here is the Airports LAYER in the mapfile.

LAYER
            NAME Airports
            DEBUG 5
            METADATA
                    "wfs_srs" "EPSG:3857"
                    "wfs_title" "Airports"
                    "gml_featureid" "Name"
                    "gml_include_items" "all"
                    "wfs_enable_request" "*"
                    "wfs_encoding" "UTF-8"
                    "wfs_extent" "-180 -90 180 90"
            END
            TYPE point
            STATUS ON
            MAXSCALEDENOM 20000
            LABELITEM 'Name'
            CONNECTIONTYPE OGR
            CONNECTION '/tmp/navhome/navdata/airports.db'
            DATA 'select "POINT(" || LONG || " " || LAT || ")" as WKT_GEOMETRY, * FROM airports WHERE name LIKE "S%"'
            #DATA 'select "POINT(" || LONG || " " || LAT || ")" as WKT_GEOMETRY, * FROM airports WHERE ICAO != "ZZZZ"'
            PROJECTION
                    "proj=latlong"
                    "ellps=WGS84"
                    "datum=WGS84"
            END # PROJECTION
    END # LAYER

Here is the OpenLayers code for the WFS layer:

var wfs = new OpenLayers.Layer.Vector("Airports", {
            styleMap: new OpenLayers.StyleMap({
                    externalGraphic: "red_pin.png",
                            graphicWidth: 18,
                            graphicHeight: 18
            }),
            wrapDateLine: true,
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.WFS({
                    srsName: "EPSG:3857",
                    version: "1.0.0",
                    url: "http://my_url/cgi-bin/mapserv.exe?map=/tmp/navhome/navcore/airports2/airports_viewer.map&SERVICE=WFS&VERSION=1.1.0&srsName=EPSG:3857",
                    featureType: "Airports"
            })
    });
    map.addLayer(wfs);

Any input on this matter is appreciated. I assume it has something to do with the extent, but I'm not totally sure.

2

MapServer Scale computation only works with GetMap request (WMS or CGI), that's why it doesn't work for feature request like WFS. You should put the scale intelligence on the OpenLayers side like this:

var wfs = new OpenLayers.Layer.Vector("Airports", {
        styleMap: new OpenLayers.StyleMap({
                externalGraphic: "red_pin.png",
                        graphicWidth: 18,
                        graphicHeight: 18
        }),
        minScale: 20000,
        wrapDateLine: true,
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.WFS({
                srsName: "EPSG:3857",
                version: "1.0.0",
                url: "http://my_url/cgi-bin/mapserv.exe?map=/tmp/navhome/navcore/airports2/airports_viewer.map&SERVICE=WFS&VERSION=1.1.0&srsName=EPSG:3857",
                featureType: "Airports"
        })
});
map.addLayer(wfs);

You may have to play with the minScale or maxScale a little bit to get the right numbers. Note that it helps to have LayerSwitcher when playing with that since it grey out the layer when it is present, but out of scale. So add this while developing:

map.addControl(new OpenLayers.Control.LayerSwitcher());
0

Alright, based on what I researched, I'm not even sure it is possible to use MAXSCALEDENOM when using a wfs layer in your mapfile (please correct me if I'm wrong).

This is my solution using Javascript. Nothing was changed in the mapfile.

function zoomChanged() {
    zoom = map.getZoom();
    if (zoom == 2 || zoom == 1 || zoom == 0)
    {
            wfs.setVisibility(false);
    }
    else
    {
            wfs.setVisibility(true);
    }
}

Within the init function:

map.events.register("zoomend", map, zoomChanged);

And then outside the init function at the bottom of the file:

<body onload="init(), zoomChanged();">

Any criticism on this solution is welcome.

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.