[OpenLayers-Users] Visibility of features in vector layer
Andreas Hocevar
ahocevar at opengeo.org
Thu Jul 9 06:09:54 EDT 2009
hi,
the reason why it does not work is that you are using Layer.WFS, which
will load features for the visible extent after a pan/zoom. This means
that your modified features get removed, and replaced by fresh ones
from the server.
I see that you set the visibility based on a feature attribute. In
this case it would be best to set the visibility with a context in the
stylemap. See the stylemap-context.html example to see what I mean.
Regards,
Andreas.
On 7/9/09, Matthew Doyle <M.Doyle at bom.gov.au> wrote:
>
> Hi Eric, Andreas and Paul,
>
> Many thanks for getting back to me, and thanks for the suggestions. I have
> tried both ways, and the features still don't remember which renderIntent or
> "style" they have been changed to, always reverting back to the default.
>
> Andreas - I did have a styleMap called "hidden" but i've now renamed that to
> "delete" as suggested, I had assumed you could create your own renderIntent
> names paired with Style objects, now I realise it's best to stick with
> default, selected and delete.
>
> Here's my code: I hope you can perhaps see where I am going wrong?
> First, the StyleMaps and WFS Layer instantiation:
>
> var pacificStyleMap = new OpenLayers.StyleMap({
> "default": {
> externalGraphic : "/ol/img/capital-city.png",
> cursor: "pointer",
> graphicWidth : 10,
> graphicHeight : 10,
> graphicXOffset : -6,
> graphicYOffset : -6,
> graphicOpacity : 1
> },
> "select": {
> externalGraphic : "/ol/img/capital-city.png",
> cursor: "pointer",
> graphicWidth : 12,
> graphicHeight : 12,
> graphicXOffset : -7,
> graphicYOffset : -7,
> graphicOpacity : 1
> },
> "delete": {
> display: "none"
> }
> });
>
> pacificWFS = new OpenLayers.Layer.WFS('Weather Stations',
> OpenLayers.serviceURL, {typename: 'PI-STATIONS', format:
> OpenLayers.Format.WFS}, {
> extractAttributes: true,
> displayOutsideMaxExtent: true,
> styleMap: pacificStyleMap
> });
>
>
> (... and then the function which is trying to hide/show the features)
>
>
> function toggleDataType(dataType) {
> var renderIntent;
> for(var i = 0; i< pacificWFS.features.length; i++) {
> if(dataType == "rain") {
> if(pacificWFS.features[i].attributes.rain != "True") {
> renderIntent = "delete";
> } else {
> renderIntent = "default";
> }
> } else if(dataType == "tmax") {
> if(pacificWFS.features[i].attributes.tmax != "True") {
> renderIntent = "delete";
> } else {
> renderIntent = "default";
> }
> }
> pacificWFS.features[i].renderIntent = renderIntent;
> pacificWFS.drawFeature(pacificWFS.features[i]);
> }
> }
>
>
> The toggleDataType(dataType) is called onclick from a drop-down menu, all is
> working well with this as i have debugged the code thoroughly. I have 30
> features, and they have differing dataType attributes.
>
> I hope you guys can spot something that i'm missing here.
>
> I have also tried Eric's suggestion:
> pacificWFS.features[i].style = OpenLayers.Feature.Vector.style["delete"];
> instead of setting the renderIntent at the bottom of the loop. In either
> method, the features do hide, but as soon as i pan around or zoom (causing a
> redraw) then the features come back.
>
> Best regards,
> Matt
>
>
>
>
>
> Eric Lemoine-2-2 wrote:
>>
>> On Wednesday, July 8, 2009, Paul Spencer <pagameba at gmail.com> wrote:
>>> Eric,
>>>
>>> On 8-Jul-09, at 9:25 AM, Eric Lemoine wrote:
>>>
>>>
>>> On Wednesday, July 8, 2009, Matthew Doyle <M.Doyle at bom.gov.au> wrote:
>>>
>>>
>>> Hello all,
>>>
>>> Sorry for resurrecting this topic, but i am having trouble getting my
>>> features to "remember" which StylemMap they have been changed to, using
>>> the
>>> renderIntent.
>>>
>>> After following Heidtmare's suggestions below, my WFS layer is now
>>> showing
>>> and hiding features on the fly using the renderIntent and then calling
>>> drawFeature, as follows:
>>>
>>> for(var i = 0; i < WFSLayer.features.length; i++) {
>>> WFSLayer.features[i].renderIntent = "hidden";
>>> WFSLayer.drawFeature(WFSLayer.features[i]);
>>> }
>>>
>>> This works great, right up until i zoom the map or move to a different
>>> extent. Each feature goes back to their "default" renderIntent and the
>>> features are shown once again.
>>>
>>> How can i force a permanent change for each feature so that when the user
>>> zooms it remembers what changes have just been made?
>>>
>>>
>>> Hi
>>>
>>> You can use the "style" property. E.g.
>>>
>>> feature.style = OpenLayers.Feature.Vector.style["delete"];
>>>
>>>
>>>
>>> why does the renderIntent approach not work? It does work for controls
>>> like SelectFeature. From what I see in the code, the renderIntent of the
>>> feature is changed in createSymbolizer called from drawFeature, which
>>> should use the renderIntent of the feature (in this case, 'hidden').
>>> Unless the style map doesn't contain a 'hidden' style, in which case it
>>> would default back to ... um ... 'default' :)
>>
>>
>> I agree with your reasonning Paul - setting feature.renderIntent to
>> "delete" should work equally.
>>
>>
>>>
>>> Paul
>>>
>>>
>>
>> --
>> Eric Lemoine
>>
>> Camptocamp France SAS
>> Savoie Technolac, BP 352
>> 73377 Le Bourget du Lac, Cedex
>>
>> Tel : 00 33 4 79 44 44 96
>> Mail : eric.lemoine at camptocamp.com
>> http://www.camptocamp.com
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
>
> --
> View this message in context:
> http://n2.nabble.com/Visibility-of-features-in-vector-layer-tp2792029p3228871.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Sent from my mobile device
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list