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

Sajeer... sajeertk15 at gmail.com
Thu Jul 16 09:44:35 EDT 2009


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>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
> > 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> 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> <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 listUsers at openlayers.orghttp://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
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>>
>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090716/64389d81/attachment.html


More information about the Users mailing list