I've done something like this with OL.<br>My layer loads a gml file:<br><br>var layer = new OpenLayers.Layer.Vector("Distretti ASL",{ featureClass: OpenLayers.Feature});<br>layer.setIsBaseLayer(false);<br>layer.setVisibility
(true);<br>PpenLayers.loadURL(GML_FILE, '', '', loadGml,errorGml);<br>map.addLayer(gmlLayer);<br><br>then I created a control to register functions to events:<br><br>var control = new OpenLayers.Control.SelectFeature
(gmlLayer,{hover: true,onSelect: selectFunction, onUnselect: unDelectFunction});<br>map.addControl(control);<br>control.activate();<br><br>The selectFunction registers a function to onClick event, so as to call a function when I click on the popup:
<br><br>this.popup.events.register('click', document.getElementById('link'), onClick.bind(feature));<br><br>Hope this help.<br><br><div class="gmail_quote">On Jan 11, 2008 11:17 PM, Andreas Hocevar <<a href="mailto:andreas.hocevar@gmail.com">
andreas.hocevar@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br><div class="Ih2E3d"><br>On Jan 11, 2008 5:36 PM, Eric Lemoine <
<a href="mailto:eric.c2c@gmail.com">eric.c2c@gmail.com</a>> wrote:<br>> On Jan 11, 2008 5:15 PM, Dejung Gewissler<br>> <<a href="mailto:dejung.gewissler@oit.state.nj.us">dejung.gewissler@oit.state.nj.us</a>> wrote:
<br></div><div class="Ih2E3d">> > 1) features rendered differently based on feature values (done with<br>> > styles and rules)<br>> > 2) on mouseover/hover of a feature the hover styles to take effect
<br>> > 3) on click of the feature a popup should appear<br>> ><br>> > 1) is done. 2) I can't get to work unless I attach a selectFeature<br>> > control to the layer and set {hover: true}. Is there a way to accomplish
<br>> > this task without using the selectFeature control?<br>><br>> Not that I'm aware of. But I understand why you're asking this - the<br>> hover* style properties. I've never use these properties myself, and I
<br>> don't know if they're actually usable. Someone may want to jump in...<br><br></div>Those hover* style properties do not do anything. The proper way to<br>control styling of the features for mouseover is to set the
<br>selectStyle property of the OL.SelectFeature control, like Eric<br>already pointed out. If you also want to have those rule-based, you<br>have to create separate styling rules, again with fillColor,<br>strokeColor and so on. Then you have to write a custom select method
<br>for the SelectFeature control (as also shown in examples/sld.html):<br><br> var hover = new OpenLayers.Control.SelectFeature(myGML, {<br> hover: true,<br> selectStyle: yourSelectStyleHere,<br> select = function(feature) {
<br> // store layer style<br> var style = feature.layer.style;<br> // set temporary layer style for hover rendering<br> feature.layer.style = hover.selectStyle;<br> OpenLayers.Control.SelectFeature.prototype.select.apply
(hover,<br>arguments);<br> // restore layer style<br> feature.layer.style = style;<br> }});<br><div class="Ih2E3d"><br><br>> > The reason why is<br>> > that I would like to use the selectFeature control in 3) and attach some
<br>> > functionality to the onSelect callback.<br>><br>> Have you tried using two select feature controls on the same layer,<br>> one with hover:true, the other with hover:false? Again, I've never<br>> tried this myself, and I'm not actually sure it'll work. If that
<br>> doesn't work, I'd say it's a bug in OpenLayers, and we'll need to fix<br>> it.<br><br></div>I also do not know if that works, but I did it using the following<br>trick: in the onSelect method of the SelectFeature control with
<br>hover:true, I defined a priority listener for mousedown:<br><br> var onClick = function(evt) {<br> // do your onClick stuff here<br> OpenLayers.Event.stop(evt);<br> }<br><br> feature.layer.events.registerPriority
('mousedown', feature, onClick);<br><br>In the onClick method, you can do the custom action you want to do on<br>click (note that onClick is called in the context of the feature, so<br>the feature can be accessed with "this").
<br><br>And do not forget to also remove the mousedown event in the onUnselect method:<br><br> feature.layer.events.unregister('mousedown', feature, onClick);<br><br>Regards,<br><font color="#888888">Andreas.<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>Dev mailing list<br><a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a><br><a href="http://openlayers.org/mailman/listinfo/dev" target="_blank">
http://openlayers.org/mailman/listinfo/dev</a><br></div></div></blockquote></div><br>