[OpenLayers-Dev] Hover style not working on GML

Gianni Barrotta giannibarrotta at gmail.com
Fri Jan 11 17:51:18 EST 2008


I've done something like this with OL.
My layer loads a gml file:

var layer = new OpenLayers.Layer.Vector("Distretti ASL",{ featureClass:
OpenLayers.Feature});
layer.setIsBaseLayer(false);
layer.setVisibility(true);
PpenLayers.loadURL(GML_FILE, '', '', loadGml,errorGml);
map.addLayer(gmlLayer);

then I created a control to register functions to events:

var control = new OpenLayers.Control.SelectFeature(gmlLayer,{hover:
true,onSelect: selectFunction, onUnselect: unDelectFunction});
map.addControl(control);
control.activate();

The selectFunction registers a function to onClick event, so as to call a
function when I click on the popup:

this.popup.events.register('click', document.getElementById('link'),
onClick.bind(feature));

Hope this help.

On Jan 11, 2008 11:17 PM, Andreas Hocevar <andreas.hocevar at gmail.com> wrote:

> Hi,
>
> On Jan 11, 2008 5:36 PM, Eric Lemoine <eric.c2c at gmail.com> wrote:
> > On Jan 11, 2008 5:15 PM, Dejung Gewissler
> > <dejung.gewissler at oit.state.nj.us> wrote:
> > >     1) features rendered differently based on feature values (done
> with
> > > styles and rules)
> > >     2) on mouseover/hover of a feature the hover styles to take effect
> > >     3) on click of the feature a popup should appear
> > >
> > > 1) is done. 2) I can't get to work unless I attach a selectFeature
> > > control to the layer and set {hover: true}. Is there a way to
> accomplish
> > > this task without using the selectFeature control?
> >
> > Not that I'm aware of. But I understand why you're asking this - the
> > hover* style properties. I've never use these properties myself, and I
> > don't know if they're actually usable. Someone may want to jump in...
>
> Those hover* style properties do not do anything.  The proper way to
> control styling of the features for mouseover is to set the
> selectStyle property of the OL.SelectFeature control, like Eric
> already pointed out.  If you also want to have those rule-based, you
> have to create separate styling rules, again with fillColor,
> strokeColor and so on. Then you have to write a custom select method
> for the SelectFeature control (as also shown in examples/sld.html):
>
>    var hover = new OpenLayers.Control.SelectFeature(myGML, {
>        hover: true,
>        selectStyle: yourSelectStyleHere,
>        select = function(feature) {
>            // store layer style
>            var style = feature.layer.style;
>            // set temporary layer style for hover rendering
>            feature.layer.style = hover.selectStyle;
>            OpenLayers.Control.SelectFeature.prototype.select.apply(hover,
> arguments);
>            // restore layer style
>            feature.layer.style = style;
>        }});
>
>
> > > The reason why is
> > > that I would like to use the selectFeature control in 3) and attach
> some
> > > functionality to the onSelect callback.
> >
> > Have you tried using two select feature controls on the same layer,
> > one with hover:true, the other with hover:false? Again, I've never
> > tried this myself, and I'm not actually sure it'll work. If that
> > doesn't work, I'd say it's a bug in OpenLayers, and we'll need to fix
> > it.
>
> I also do not know if that works, but I did it using the following
> trick: in the onSelect method of the SelectFeature control with
> hover:true, I defined a priority listener for mousedown:
>
>    var onClick = function(evt) {
>        // do your onClick stuff here
>        OpenLayers.Event.stop(evt);
>    }
>
>    feature.layer.events.registerPriority('mousedown', feature, onClick);
>
> In the onClick method, you can do the custom action you want to do on
> click (note that onClick is called in the context of the feature, so
> the feature can be accessed with "this").
>
> And do not forget to also remove the mousedown event in the onUnselect
> method:
>
>    feature.layer.events.unregister('mousedown', feature, onClick);
>
> Regards,
> Andreas.
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20080111/276878db/attachment.html


More information about the Dev mailing list