[OpenLayers-Users] Visibility of features in vector layer [SEC=UNCLASSIFIED]

mippon smarty at programmer.net
Thu Oct 1 07:56:02 EDT 2009


Hi Mathew

I am trying to acheive the same, but not getting anywhere. 
I am using a Layer.GML with format GeoRSS. 

How can i change the render intent? 

Thanks


Matthew Doyle wrote:
> 
> Thank you Andreas, my features are now working perfectly.
> 
> For those interested in the final solution; I used Layer.Vector with a
> Fixed strategy. Once this was set up correctly I was able to modify the
> renderIntent parameter of each feature to toggle them on and off
> appropriately.
> 
> var vectorLayer = new OpenLayers.Layer.Vector("Pacific Stations", {
> 		strategies: [new OpenLayers.Strategy.Fixed()],
> 		styleMap: pacificStyleMap,
> 		protocol: new OpenLayers.Protocol.HTTP({
> 			url: "...", 
> 			format: new OpenLayers.Format.GML()
> 		})
> 	});
> 
> Big thanks to all who responded and helped,
> 
> Best regards,
> Matt
> 
> 
> -----Original Message-----
> From: Andreas Hocevar [mailto:ahocevar at opengeo.org] 
> Sent: Saturday, 11 July 2009 7:17 AM
> To: Matthew Doyle; users
> Subject: Re: [OpenLayers-Users] Visibility of features in vector layer
> [SEC=UNCLASSIFIED]
> 
> Matthew Doyle wrote:
>> Thanks Andreas! Should I be using Layer.Vector instead then?
> 
> Either Layer.Vector with a Fixed strategy, or, if you do not want to
> change a lot of code, just use Layer.GML instead of Layer.WFS. But the
> disadvantage is that it will load all features from your server, which
> will be slow if you have more than ~100 features.
> 
> Regards,
> Andreas.
> 
>> I'll give the stylemap-context a go first and let you know how I get on.
>> Thanks again.
>> 
>> Cheers,
>> Matt
>> 
>> -----Original Message-----
>> From: andreas.hocevar at gmail.com [mailto:andreas.hocevar at gmail.com] On 
>> Behalf Of Andreas Hocevar
>> Sent: Thursday, 9 July 2009 8:10 PM
>> To: Matthew Doyle; users at openlayers.org
>> Subject: Re: [OpenLayers-Users] Visibility of features in vector layer
>> 
>> 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-tp2792029
>>> p 3228871.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.
> 
> 
> --
> Andreas Hocevar
> OpenGeo - http://opengeo.org/
> Expert service straight from the developers.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Re-Visibility-of-features-in-vector-layer-SEC-UNCLASSIFIED-tp3240883p3748529.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list