[OpenLayers-Users] How does a renderer draw features ?
Alexandre Dube
adube at mapgears.com
Mon Aug 25 16:48:00 EDT 2008
Hi Eric,
I've not been able to work on my little project until recently. I
tried what you suggested and and worked fine. When the mouse is over a
feature, its color changes without selecting it. And when the mouse is
out, it regain its original color.
Thank you very much for your hint, it helped me a lot.
If anybody wants to see how I made it, you're welcomed to ask.
Alexandre
Eric Lemoine wrote:
> On Fri, Aug 1, 2008 at 3:48 PM, Alexandre Dube <adube at mapgears.com> wrote:
>
>> Hi list,
>>
>> I was wondering something : when we select a feature using a select
>> or modify control, the feature changes its color... In fact, I saw that
>> it the renderer that draws a feature ( which draw geometry ) using a
>> given style.
>>
>> My question is : does the renderer actually draw a new feature over
>> the original one or it really changes the color ?
>>
>
> It changes its color.
>
>
>> The renderer does not
>> contain any feature, but it can draw features ?
>>
>
> Yes.
>
>
>
>> I'm trying to figure out how it works because I am able to "change"
>> color when my mouse is over a feature without selecting it, but I'm
>> trying to undo the changes as soon as the mouse isn't over anymore and
>> it's not working.
>>
>> Here's a code snippet :
>>
>> var drawnGeometry = null;
>>
>> var styleBlue = OpenLayers.Util.extend(
>> {},
>> OpenLayers.Feature.Vector.style['default']);
>> styleBlue.strokeColor = "blue";
>> styleBlue.strokeWidth = 4;
>>
>> function changeColorOnOverFeature(e){
>> // if no feature is selected, then we want to change the color of a
>> // feature when over it
>> if (!getSelectedFeature(this)){
>> if (drawnGeometry != null){
>> this.renderer.eraseGeometry(drawnGeometry); // I'm pretty
>> sure this is wrong
>> drawnGeometry = null;
>> }
>> else {
>> oFeature = this.getFeatureFromEvent(e);
>> if(oFeature){
>> this.renderer.drawFeature(oFeature, styleBlue);
>> drawnGeometry = oFeature.geometry;
>> }
>> }
>> }
>> }
>>
>> // inside my init()
>> oMap.events.register("mousemove", olWFSRoads, changeColorOnOverFeature);
>>
>>
>> Erasing the geometry makes the feature disappear, but it's still in the
>> layer features, with no changes of its geometry and all... I'm quite
>> sure this is not the best way to do it. Any clues ?
>>
>
> You should use a feature handler (Handler.Feature) to detect
> mouseover/mouseout on features. Look at the select feature control to
> understand how to use it.
>
> --
> Eric
>
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list