[OpenLayers-Users] Labels/Tooltips on mouse over a Vector layer

Adrian Popa adrian_gh.popa at romtelecom.ro
Fri Jul 17 07:05:43 EDT 2009


Hello Sajeer,

When I try to use {hover: true} in the SelectFeature definition, the 
popups appear and dissapear when I hover the mouse over a marker. If I 
use hover:false, I get the regular functionality - the popups 
appear/dissapear when I click on them.

This is great... problem is - I would like to use both methods of 
interaction: when the user hovers over a marker, he gets a small 
div/popup with minimal information, and if the user clicks on the marker 
he gets the whole information in a different popup.

 From what I've seen, and from your example, there are no special events 
for mouseOver/mouseOut. It can be achieved with hover true/false. In 
this case, the only sollution would be to create a different 
selectControl for the same layer that handles just hover events. I don't 
know if I can associate different select controls with the same layer, 
or if I can have two controls active and working at the same time (a 
previous example I tried with 2 select cotrols on different layers 
didn't allow the "bottom" select to work).

Here's what I tried so far:

       //markers is a KML layer
        map.addLayer(markers);
       //add the regular select behaviour
        select = new OpenLayers.Control.SelectFeature(markers);
        markers.events.on({ "featureselected": onMarkerSelect, 
"featureunselected": onMarkerUnselect, "visibilitychanged": 
onMarkerToggle });
        map.addControl(select);
        select.activate();

         //add the hover select control
        var hoverSelect = new OpenLayers.Control.SelectFeature(markers, 
{clickout:true, hover:true, onSelect: 
tooltipSelect});                                                   
        map.addControl(hoverSelect);
        hoverSelect.activate();

The behavior is the following: when I hover over an item, 
tooltipSelect() is executed, but also onMarkerSelect(). It seems the 
hover:true "jumps" to the select object :)
Any ideas on how to get the behavior I need?

Thanks.


Regards,
Adrian

Sajeer... wrote:
> Ok, then replace  
>
> selectControl = *new* OpenLayers.Control.SelectFeature(kmlLayer,
>
> {hover: *true*,onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
>
> with
>
> selectControl = *new* OpenLayers.Control.SelectFeature(kmlLayer,
>
> { clickout: true, hover: false });
>
>  
>
> and add this too
>
> kmlLayer.events.on({
>
> "featureselected": function(e) {
>
> onFeatureSelect(e.feature);
>
> },
>
> "featureunselected": function(e) {
>
> onFeatureUnselect(e.feature);
>
> }
>
> });
>
>  
>  
>
> Regards
>
> Sajeer
>
>
> On Thu, Jul 16, 2009 at 3:49 PM, Adrian Popa 
> <adrian_gh.popa at romtelecom.ro <mailto:adrian_gh.popa at romtelecom.ro>> 
> wrote:
>
>     Thank you Sajeer,
>
>     To make it clear for me: you would register the "featureselected"
>     event for mouse over? Where do you specify hover:true/hover:false?
>     I'd like to be able to keep featureselected for when the user
>     actually clicks on the feature - so I'd like to register 2 events
>     to generate 2 different popups...
>
>     Regards,
>     Adrian
>
>
>     Sajeer... wrote:
>>     you can register this function for click event by replacing
>>     hover:true  with hover:false    *  *
>>      
>>      
>>
>>     Regards
>>
>>     Sajeer
>>
>>
>>
>>     On Thu, Jul 16, 2009 at 3:38 PM, Adrian Popa
>>     <adrian_gh.popa at romtelecom.ro
>>     <mailto:adrian_gh.popa at romtelecom.ro>> wrote:
>>
>>         Hello Sajeer,
>>
>>         How do you register your functions to events so that they are
>>         executed on mouse over instead of on click? Or is your popup
>>         created when you click a feature?
>>
>>         Thanks,
>>         Adrian
>>
>>
>>         Sajeer... wrote:
>>>         *
>>>
>>>         Hi,
>>>
>>>         try this one,
>>>
>>>          
>>>
>>>          
>>>
>>>         function
>>>
>>>         *onFeatureSelect(feature) {
>>>
>>>         selectedFeature = feature;
>>>
>>>         popup =
>>>
>>>         *new*
>>>         OpenLayers.Popup.FramedCloud("",
>>>
>>>         feature.geometry.getBounds().getCenterLonLat(),
>>>
>>>         *new* OpenLayers.Size(100,100), "<div style='padding:15px
>>>         5px 5px 10px;'>"+ "<table
>>>         style='font-size:13px;color:red'>"+ "<tr>"+ "<td
>>>         width='40%'>Name</td>"+ "<td width='5%'>:</td>"+
>>>         "<td>"+feature.attributes.label+"</td>"+ "</tr>"+
>>>         "</table></div>", *null*, *true*, onPopupClose);
>>>
>>>         feature.popup = popup;
>>>
>>>         map.addPopup(popup);
>>>
>>>         }
>>>
>>>         *function* onPopupClose(evt) {
>>>
>>>         selectControl.unselect(selectedFeature);
>>>
>>>         }
>>>
>>>         *function* onFeatureUnselect(feature) {
>>>
>>>         *      *map.removePopup(feature.popup);
>>>
>>>         feature.popup.destroy();
>>>
>>>         feature.popup = *null*;
>>>
>>>         }
>>>
>>>         var  kmlLayer = new OpenLayers.Layer.GML(.............);
>>>
>>>          
>>>         var selectControl = *new*
>>>         OpenLayers.Control.SelectFeature(kmlLayer,
>>>
>>>         {hover: *true*,onSelect: onFeatureSelect, onUnselect:
>>>         onFeatureUnselect});
>>>
>>>         map.addControl(selectControl);
>>>
>>>         selectControl.activate();
>>>
>>>
>>>         Regards
>>>
>>>         Sajeer
>>>
>>>
>>>          
>>>         On Thu, Jul 16, 2009 at 3:07 PM, Adrian Popa
>>>         <adrian_gh.popa at romtelecom.ro
>>>         <mailto:adrian_gh.popa at romtelecom.ro>> wrote:
>>>
>>>             Hello Pavel,
>>>
>>>             Great idea... However - I would like to keep popups for
>>>             when I click on an item.
>>>             Would it be possible to do something like:
>>>
>>>             layer.events.on({ "featureselected": onLocationSelect,
>>>             "featureunselected": onLocationUnselect,  //open regular
>>>             popups
>>>                                               "onMouseOver":
>>>             onLocationMouseOver, "onMouseOut": onLocationMouseOut
>>>              });?
>>>
>>>             Problem is - I don't see those kinds of events on my
>>>             layer. These are the event types for a vector layer:
>>>             0 "beforefeatureadded"
>>>             1 "beforefeaturesadded"
>>>             2 "featureadded"
>>>             3 "featuresadded"
>>>             4 "beforefeatureremoved"
>>>             5 "featureremoved"
>>>             6 "featuresremoved"
>>>             7 "beforefeatureselected"
>>>             8 "featureselected"
>>>             9 "featureunselected"
>>>             10 "beforefeaturemodified"
>>>             11 "featuremodified"
>>>             12 "afterfeaturemodified"
>>>             13 "vertexmodified"
>>>             14 "sketchstarted"
>>>             15 "sketchmodified"
>>>             16 "sketchcomplete"
>>>             17 "refresh"
>>>             18 "loadstart"
>>>             19 "loadend"
>>>             20 "loadcancel"
>>>             21 "visibilitychanged"
>>>             22 "move"
>>>             23 "moveend"
>>>
>>>             Any idea what the events would be? If they are supported?
>>>
>>>             Pavel Iacovlev wrote:
>>>>             There many possible ways around this problem.
>>>>
>>>>             One is rewrite/extend your popup code. Popup is triggered on mouseover
>>>>             and on mouseout popup is hidden. You can style the popup so it looks
>>>>             more like a tooltip/label.
>>>>
>>>>             On Thu, Jul 16, 2009 at 2:34 PM, Adrian
>>>>             Popa<adrian_gh.popa at romtelecom.ro> <mailto:adrian_gh.popa at romtelecom.ro> wrote:
>>>>               
>>>>>             Hi,
>>>>>
>>>>>             Just a quick question - my users want to see the name of the city when
>>>>>             they are hovering over points loaded through KML in a vector layer. I
>>>>>             know this isn't supported, but are there plans to support such labels?
>>>>>
>>>>>             I'm thinking a different strategy might be to override/inherit the
>>>>>             OpenLayers.Control.MousePosition class and based on coordinate changes,
>>>>>             load the name from the closest KML feature. It doesn't need to be too
>>>>>             accurate, but it can't be an exact match, because the mouse will never
>>>>>             get that close to the KML coordinates.
>>>>>             However this solution will be costly - because on every mouse move you
>>>>>             would have to go through all the KML items and see which match...
>>>>>
>>>>>             What are your ideas regarding this subject?
>>>>>
>>>>>             ---
>>>>>
>>>>>             Adrian Popa
>>>>>             NOC Division
>>>>>             Network Engineer
>>>>>             Divizia Centrul National de Operare Retea
>>>>>             Departament Transport IP & Metro
>>>>>             Compartiment IP Core & Backbone
>>>>>             Phone: +40 21 400 3099
>>>>>
>>>>>             _______________________________________________
>>>>>             Users mailing list
>>>>>             Users at openlayers.org <mailto:Users at openlayers.org>
>>>>>             http://openlayers.org/mailman/listinfo/users
>>>>>
>>>>>                 
>>>>               
>>>
>>>
>>>             -- 
>>>             --- 
>>>             Adrian Popa
>>>             NOC Division
>>>             Network Engineer
>>>             Divizia Centrul National de Operare Retea
>>>             Departament Transport IP & Metro
>>>             Compartiment IP Core & Backbone
>>>             Phone: +40 21 400 3099
>>>                 
>>>
>>>
>>>             _______________________________________________
>>>             Users mailing list
>>>             Users at openlayers.org <mailto:Users at openlayers.org>
>>>             http://openlayers.org/mailman/listinfo/users
>>>
>>>
>>
>>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090717/0bae5362/attachment.html


More information about the Users mailing list