Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Need help with getfeatureinfo for OpenLayers/WMS

  • 12-04-2017 03:12PM
    #1
    Registered Users, Registered Users 2 Posts: 232 ✭✭


    Hi Folks, I am developing a GIS web-map and am hoping someone could help me with the getfeatureinfo method to call information from a WMS layer. I have the web-map working in that I can display various WMS/WFS layers. Behind the layers that are attribute tables and everything is hosted by GeoServer 2.8.2. I'm trying to figure out how to click on a feature on a WMS layer and call the attributes of that into a pop-up. I've looked at a load of examples on line but can't get any of them to work on my map.

    Here is the code for a map.js page. I have deleted the code for most of the layers for convenience sake. There is an attribute behind the DART station layer called stop_name.
    var map;
    
    function initMap() {
    
        //initialise variables
        var osmlayer;
        var point;
        var dlr_libraries_wfs;
    	var dlr_libraries_wms;
    	var dlr_townlands_wms;
    	var dlr_mtowers_wfs;
    	var dlr_mtowers_wms;
    	var dlr_DART_wfs;
    	var dlr_dart_wms
    	var dlr_war_memorial_wfs
    	var dlr_war_memorial_wms
    	var info;
    
        //create new map object
        map = new OpenLayers.Map("mymap");
    
        //create new OSM base layer
        osmlayer = new OpenLayers.Layer.OSM("Open Street Map");
    
        //create WMS layers
    
    	// DART Station Layer.
    	dlr_DART_wfs = new OpenLayers.Layer.Vector("DART Stations (WFS)",
            {
            strategies:[new OpenLayers.Strategy.BBOX()],
            protocol: new OpenLayers.Protocol.WFS(
                    {
                    version: "1.1.0",
                    url: "http://localhost:8080/geoserver/wfs",
                    featureType: "EastC_Darts",
                    featurePrefix: "egm715",
                    featureNS: "http://geoserver.org/egm715",
                    }
                ),
            visibility: false,
            }
        );
    
    	dlr_dart_wms = new OpenLayers.Layer.WMS("DLR DART Stations (WMS)", "http://localhost:8080/geoserver/egm715/wms",
            {
            layers: "egm715:EastC_Darts",
            transparent: true
            }, {
            projection: "EPSG:3857",
            opacity: 0.5,
            visibility: false
            }
        );
    	
    	
        //add layers to the map
        map.addLayers([osmlayer, dlr_libraries_wfs, dlr_libraries_wms, dlr_DART_wfs, dlr_dart_wms, dlr_war_memorial_wfs, dlr_war_memorial_wms ]);
    
        //add LayerSwitcher control object
        map.addControl(new OpenLayers.Control.LayerSwitcher());
    
    
        // define point as a new LonLat object and transfom
        point = new OpenLayers.LonLat(-6.1832, 53.2560); 
        point.transform("EPSG:4326", "EPSG:900913");
    	
    	
        //centre the map and set zoom level
        map.setCenter(point, 11.7);
    
    }
    
    I'm grateful to anyone who gets back to me with some help. Thanks.


Advertisement