1

I tried to display data with popup from Geoserver or Postgres to my map, but it dosen't work at all. Can anyone please help me? I used this code:

    function Info(e) 
        {
                if (e.features && e.features.length) 
                {

                    //console.log(e.features[0].attributes);
                    var popupId = e.xy.x + "," + e.xy.y;
                    var popup = popups[popupId];
                    if (!popup || !popup.map) {
                    popup = new OpenLayers.Popup.FramedCloud(
                    popupId, 
                    map.getLonLatFromPixel(e.xy),
                    null,
                    " ",
                    null,
                    true,
                    function(e) {
                        delete popups[this.id];
                        this.hide();
                        OpenLayers.Event.stop(e);
                    }
                );
                popups[popupId] = popup;
                map.addPopup(popup, true);
                }   
            popup.setContentHTML(popup.contentHTML + "nom_user:" +e.features[0].attributes.nomservice +" region_user :"+ e.features[0].attributes.region);
            popup.show();                   
                }


    selectcltr = {
        click: new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://localhost/geoserver/wms', 
            title: 'Identify features by clicking',
            layers: [ser],
            queryVisible: true
        }),
        hover: new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://localhost/geoserver/wms', 
            title: 'Identify features by clicking',
            layers: [ser],
            hover: true,
            // defining a custom format options here
            formatOptions: {
                typeName: 'projet', 
                featureNS: 'http://www.openplans.org/topp'
            },
            queryVisible: true
        })
    }
3

You can get attribute information by simply adding this control.

new OpenLayers.Control.WMSGetFeatureInfo({
autoActivate: true,
infoFormat: "application/vnd.ogc.gml",
maxFeatures: 5,
eventListeners: {
    "getfeatureinfo": function(e) {
        var items = [];
        Ext.each(e.features, function(feature) {
                items.push({
                xtype: "propertygrid",
                title: feature.fid,
                source: feature.attributes
                });
            });
        new GeoExt.Popup({
            title: "Feature Info",
            width: 200,
            height: 300,
            layout: "accordion",
            map: mapPanel,
            location: e.xy,
            items: items
            }).show();
        }
}

})

Let me know, if this helps.

  • How would you use this control but instead of click, handle selection of a block area to get all features in selected area? – user3657279 Dec 29 '14 at 20:16

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.