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.

I've been working on a WMS with a QuantumGIS server. So I've added the QGIS map as a layer to my OpenLayers map on my webpage. Now I want to use the WMSGetFeatureInfo function of OpenLayers to get information about the feature I've been clicking on. So I've followed some tutorials / examples on the web. Unfortunately it returns blank whenever i click on the layer.

Here is the code:

$(document).ready(function() {

    //wenn geolocation erfolgreich ermittelt wurde, setze die map auf die koordinaten

    function success(position) {
        lat = position.coords.latitude;
        lon = position.coords.longitude;
        jumptolonlat(lat, lon);

    }

    function error(msg) {
        console.log( typeof msg == 'string' ? msg : "error");
    }

    if (navigator.geolocation) {
        // getCurrentPosition ruft die Funktion success auf und übermittelt die Position Werte
        // error wird ausgeführt wenn es einen Fehler beim ermitteln der Position gibt
        navigator.geolocation.getCurrentPosition(success, error);
    } else {
        alert("GeoLocation API ist NICHT verfügbar!");
    }
    //document.getElementById("lat").value = "";
    //document.getElementById("lon").value = "";
    var options = {
        projection : new OpenLayers.Projection("EPSG:900913"),
        displayProjection : new OpenLayers.Projection("EPSG:4326"),
        units : "m",
        //resolutions : [156543.03390000001, 78271.516950000005, 39135.758475000002, 19567.879237500001, 9783.9396187500006, 4891.9698093750003, 2445.98490468750],
        //maxResolution : 156543.0339,
        maxResolution : 0.17578125,
        minResolution : 156543.03390000001,
        maxExtent : new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
        controls : [new OpenLayers.Control.Navigation(), new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Attribution()]
    };
    // Karte initiieren
    map = new OpenLayers.Map('mapdiv', options);

    // Layer hinzufügen
    layerMapnik = new OpenLayers.Layer.OSM("Mapnik");
    var wms = new OpenLayers.Layer.WMS("Karte", "http://localhost/qgis/qgis_mapserv.fcgi.exe", {
        layers : 'gk-1000',
        format : 'image/png',
        map : 'C:/mymaps/karte.qgs'
    });
    map.addLayers([layerMapnik, wms]);
    // Zentrierung der Karte beim initiieren
    var centerLonLat = new OpenLayers.LonLat(9.869824084639358, 51.25325741806755).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    if (!map.getCenter())
        map.setCenter(centerLonLat, 6);

    // Click Control zur Karte hinzufügen
    click = new OpenLayers.Control.Click();
    map.addControl(click);

    // Aktivieren (kann auch mit click.deactivate() wieder deaktiviert werden)
    click.activate();

    var popup = null;
    info = new OpenLayers.Control.WMSGetFeatureInfo({
        url : 'http://localhost/qgis/qgis_mapserv.fcgi.exe',
        title : 'Identify features by clicking',
        queryVisible : true,
        layers : [wms],
        eventListeners : {
            getfeatureinfo : function(event) {
                if (!event.text.match(/<body>\s*<\/body>/)) {
                    if (popup) {
                        popup.destroy();
                        popup = null;
                    }
                    popup = new OpenLayers.Popup.FramedCloud("popup", map.getLonLatFromPixel(event.xy), null, event.text, null, true);
                    document.getElementById('ergebnis').innerHTML = "Ergebnis: " + event.text;
                    map.addPopup(popup);
                }
            }
        }
    });
    map.addControl(info);
    info.activate();

});

Any help would be appreciated.

share|improve this question
    
is this correct? url : 'http://localhost/qgis/qgis_mapserv.fcgi.exe',? –  Gery May 22 '13 at 12:21
    
I've seen exmaples where the url is like: url: 'demo.opengeo.org/geoserver/wms';, but when I change my url to 'localhost/qgis', the popup does not even occur, so I think this is the correct path for the url –  Antivist May 22 '13 at 12:30
    
I don't work with geoserver but looks to me that this example points to an alias. I think you need to test the url in your browser and the NET tab of firebug, probably there you'll find some more ideas about what's going wrong –  Gery May 22 '13 at 12:36
    
Yea I think that should solve the problem. But I don't know how to create an alias. So when I manually look up for the url in the net tab of firebug, there is some part missing. localhost/qgis/qgis_mapserv.fcgi.exe?Map=c:/mymaps/karte.qgs this is the correct url to do the request. So could you tell me how to make an alias for this url? –  Antivist May 22 '13 at 13:10
    
so if that's the correct url, you just have to use that one. I think you have to be sure that the url works well inside your protocol, then you could go for the alias. The alias is easy, you can use apache for that, but I think you're working on windows, aren't you? –  Gery May 22 '13 at 13:22

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.