[OpenLayers-Users] Get Feature Info from GML Layer (not to a popup)

Frederick Löbig frederick.loebig at live.de
Fri Nov 1 01:05:47 PDT 2013


Hi all,I have a quite small problem with my OL Script. What my current map looks like: I have a base OSM map and a GML layer loaded. The layer is loaded as a vector layer with the format GML. When I select one of the features of the GML layer, a function is called (currently, making a div visible, and on unselect, hide the div. This is done via the OpenLayers.Control.SelectFeature and the onSelect function.So far, so good. What I am trying to do now, is gathering information from the selected feature and hand it to the called function, so that I can fill the appearing div with data I get from the database in a later step using AJAX. I hope you get what I am trying to do. The missing link is to get the information from the feature to the function "openDetail () ". This is my current file:[...]			OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                                defaultHandlerOptions: {                    'single': true,                    'double': false,                    'pixelTolerance': 0,                    'stopSingle': false,                    'stopDouble': false                },
                initialize: function(options) {                    this.handlerOptions = OpenLayers.Util.extend(                        {}, this.defaultHandlerOptions                    );                    OpenLayers.Control.prototype.initialize.apply(                        this, arguments                    );                     this.handler = new OpenLayers.Handler.Click(                        this, {                            'click': this.trigger                        }, this.handlerOptions                    );                }, 
                trigger: function(e) {                    var lonlat = map.getLonLatFromPixel(e.xy);						openFormAdd(lonlat.lat,lonlat.lon);                    //alert("You clicked near " + lonlat.lat + " N, " +                    //                          + lonlat.lon + " E");                }
            });			        var map, layer, pointLayer;
        function init() {            if (!OpenLayers.CANVAS_SUPPORTED) {                var unsupported = OpenLayers.Util.getElement('unsupported');                unsupported.innerHTML = 'Your browser does not support canvas, nothing to see here !';            }
            layer = new OpenLayers.Layer.OSM('Simple OSM Map', null, {                eventListeners: {                    tileloaded: function(evt) {                        var ctx = evt.tile.getCanvasContext();                        if (ctx) {                            var imgd = ctx.getImageData(0, 0, evt.tile.size.w, evt.tile.size.h);                            var pix = imgd.data;                            for (var i = 0, n = pix.length; i < n; i += 4) {                                pix[i] = pix[i + 1] = pix[i + 2] = (3 * pix[i] + 4 * pix[i + 1] + pix[i + 2]) / 8;                            }                            ctx.putImageData(imgd, 0, 0);                            evt.tile.imgDiv.removeAttribute("crossorigin");                            evt.tile.imgDiv.src = ctx.canvas.toDataURL();                        }                    }                }            });						pointLayer = new OpenLayers.Layer.Vector("GeoJSON", {            strategies: [new OpenLayers.Strategy.Fixed()],            protocol: new OpenLayers.Protocol.HTTP({                url: "http://127.0.0.1/L11/geoData/data.xml.gml",                format: new OpenLayers.Format.GML()            })			});

            map = new OpenLayers.Map('map', {                layers: [layer, pointLayer],                zoom: 3,                center: [-1081125, 6212801]            });										var click = new OpenLayers.Control.Click();                map.addControl(click);				//click.activate();							clickFeature = new OpenLayers.Control.SelectFeature(			   [pointLayer],			   {				   clickout: true, toggle: false,				   multiple: false, hover: false,				   hover: 			   }			);										map.addControl(clickFeature);								pointLayer.events.on({				   "featureselected": function(e) {						//drag.activate();						openDetail();				   },				   "featureunselected": function(e) {						closeDetail();				   }			   });			   			clickFeature.activate();                			map.addControl(new OpenLayers.Control.LayerSwitcher());        }		[...]					function openDetail () {				document.getElementById("contentLayerDetail").style.visibility='visible';			}					function closeDetail () {				document.getElementById("contentLayerDetail").style.visibility='hidden';			}			</script>
[...]

I hope somebody can give me a little help with this. 
Thanks in advance,Freddy


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20131101/0a931141/attachment.html>


More information about the Users mailing list