[OpenLayers-Users] How does a renderer draw features ?
Eric Lemoine
eric.c2c at gmail.com
Fri Aug 1 11:27:56 EDT 2008
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
More information about the Users
mailing list