[OpenLayers-Dev] Hide/Show Feature + KML + Stylemap
Thomas PAPIN
thomas.papin at gmail.com
Wed Aug 4 10:38:48 EDT 2010
Ok
I finally found a solution (not sure it's the easier solution but it's
working in all case
When declaring StyleMap I add this Rule:
new OpenLayers.Rule({
name : "changestate",
symbolizer: { "Polygon": { display : "none"} },
filter: new OpenLayers.Filter.FeatureId({fids :
[]})
})
So currently this has no impact, as the list of features id is empty.
Now, in my changestate function (this function is called when a feature
status must be changed : show/hide)
features = layer.features;
unactivelist = new Array(); // List of feature ids to hide
n = 0;
for(i=0;i<dtnode.parent.childList.length;i++) { // I am
using dynatree (tree with checkbox)
// if style is defined (no stylemap associated) normal
case, just style.display = "none"
if (features[i].style) {
if (dtnode.parent.childList[i].isSelected())
features[i].style.display = "block";
else
features[i].style.display = "none";
} else {
if (!dtnode.parent.childList[i].isSelected())//
checkbox not active so add to unactive
unactivelist[n++] = features[i].id;
}
}
}
//Get layer.stylemap.style.rules.filter and change fids to
the new list, redraw the layer
style = layer.styleMap.styles["default"];
for(j=0;j<style.rules.length;j++)
{
if (style.rules[j].name == 'changestate')
{
style.rules[j].filter.fids = unactivelist;
}
}
}
layer.redraw();
2010/8/4 Thomas PAPIN <thomas.papin at gmail.com>
> Hi, it's again me :)
>
> When I want to hide/show a feature, I just do in a normal case:
> feature.style.display = "none";
> This is working great.
>
> But in the following case it's not working, and I don't have what to do.
>
> - I have a KML with placemark (Point and Polygon)
> - Each Placemark have attributes like (fontColor,label,labeloffestY)
> - I used a StyleMap to style the features of this KML
> like that:
> var extraMap = new OpenLayers.StyleMap({'default':{
> fillOpacity: 1,
> pointRadius: "${pointSize}",
> label : "${label}",
> fontColor: "${fontColor}",
> fontSize: "${labelSize}px",
> ....
>
> GMLlayer = new OpenLayers.Layer.GML(json.files[i].name, json.files[i].kml,
> {
> format:
> OpenLayers.Format.KML,
> formatOptions: {
> extractStyles: true,
> extractAttributes:
> true,
> maxDepth: 2
> },
> styleMap: style
> });
>
> Then when I tried to do feature.style.display but feature.style is not
> defined.
>
> What can I do :-( ?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20100804/c201bd8e/attachment.html
More information about the Dev
mailing list