[OpenLayers-Users] How does a renderer draw features ?
Alexandre Dube
adube at mapgears.com
Fri Aug 1 09:48:12 EDT 2008
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 ? The renderer does not
contain any feature, but it can draw features ?
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 ?
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list