AW: [OpenLayers-Users] Re: SLDSelect doesn't highlight anything

Arnd Wippermann arnd.wippermann at web.de
Mon Apr 23 13:06:31 EDT 2012


it seems, that the GetFeature Control have no functions to reproject the 
BBOX for the query and to reproject the returned feature geometry.

A possible way is to overwrite OpenLayers.Control.GetFeature.request 
to transform the BBOX from client to server supported projection

and

add to control.events.register("featureselected", ...
reprojecting for the responded feature geometry from server projection to
client projection.

code see below:

Regards,
Arnd

//transformes the bounds from map.projection to hardcoded projection
EPSG:4326

OpenLayers.Control.GetFeature.prototype.request = function(bounds, options)
{
        options = options || {};
        var filter = new OpenLayers.Filter.Spatial({
            type: this.filterType,

            //add transform to create BBOX in server projection coordinates
            value: bounds.transform(map.getProjectionObject(),new
OpenLayers.Projection("EPSG:4326"))
        });

        // Set the cursor to "wait" to tell the user we're working.
        OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait");

        var response = this.protocol.read({
            maxFeatures: options.single == true ? this.maxFeatures :
undefined,
            filter: filter,
            callback: function(result) {
                if(result.success()) {
                    if(result.features.length) {
                        if(options.single == true) {
                            this.selectBestFeature(result.features,
                                bounds.getCenterLonLat(), options);
                        } else {
                            this.select(result.features);
                        }
                    } else if(options.hover) {
                        this.hoverSelect();
                    } else {
                        this.events.triggerEvent("clickout");
                        if(this.clickout) {
                            this.unselectAll();
                        }
                    }
                }
                // Reset the cursor.
                OpenLayers.Element.removeClass(this.map.viewPortDiv,
"olCursorWait");
            },
            scope: this
        });
        if(options.hover == true) {
            this.hoverResponse = response;
        }
    }


control = new OpenLayers.Control.GetFeature({
//return following Attributes
    protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer, {version:"1.0.0",
srsName:"EPSG:4326", "propertyNames": ["country", "msGeometry"],
        featurePrefix: 'ms', geometryName:"msGeometry"}),
    box: false,
    hover: false,
    multipleKey: "shiftKey",
    toggleKey: "ctrlKey"
});

//add transform to reproject the returned feature to the client projection
control.events.register("featureselected", this, function(e) 
{
    //transformes the bounds from EPSG:4326 to map.projection

    if(e.feature.length==undefined)
        e.feature.geometry.transform(new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject());

    select.addFeatures([e.feature]);
});


 

-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von vrbikdan
Gesendet: Montag, 23. April 2012 08:42
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Re: SLDSelect doesn't highlight anything

Hmm, I tried to set transform function, but in fact, I don't know, where in
my code I should write it. Let supposse I have this code for selection:

select = new OpenLayers.Layer.Vector("Selection", {styleMap: new
OpenLayers.Style({'fillOpacity': 1,'fillColor': "#FFFF00",'strokeColor':
"#FFFF00"})});
map.addLayer(select);
control = new OpenLayers.Control.GetFeature({
protocol: OpenLayers.Protocol.WFS.fromWMSLayer(vrstvy['vrstvaC'])});
control.events.register("featureselected", this, function(e) {
select.addFeatures([e.feature]); alert(1);});
control.events.register("featureunselected", this, function(e) {
select.removeFeatures([e.feature]);});
map.addControl(control);
control.activate(); 

So I tried to set select.transform(map.projection,map.displayProjection);
(where projection is 900913 and displayProjection is 4326), than
control.transform(map.projection,map.displayProjection);. Both with the same
end: Object # has no method 'transform'. So I don't know, where I should
define transform or what I should transform. In my map I have handler for
writting coordinates on click in map and there I'm using transform, so in
fact, I have somewhere stored position of last click in two variables as
4326, so can I use it somehow?

Thanks
Dan

--
View this message in context:
http://osgeo-org.1560.n6.nabble.com/SLDSelect-doesn-t-highlight-anything-tp4
689209p4909338.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list