[OpenLayers-Users] changing style of a WFS layer
Alexandre Dube
adube at mapgears.com
Tue Nov 25 10:46:32 EST 2008
I'm glad it worked. But to my eyes there seems to be a flaw in this
solution : performance. In the example I gave you, there was a need of
calculating the radius for each features because of the cluster
strategy. But for you, triggering map.getZoom() for each features that
will end up being all at the same size is pretty useless.
Anybody know a clean way to trigger this once ?
Or maybe you could try something like registering a zoomstart event that
changes the radius value of the style directly to nextZoom + 2 ( dunno
if nextZoom is available at this point though...).
Alexandre
Lehtonen, Mika wrote:
> I can't believe my eyes!
> You're absolutely right. With this, I get exactly what I wanted to get:
> var shpStyle = new OpenLayers.Style({
> pointRadius: "${radius}",
> strokeColor: "red",
> strokeWidth: 1,
> strokeOpacity: 1,
> fillColor: 'black',
> fillOpacity: 0.2
> }, {
> context: {
> radius: function() {
> return map.getZoom() + 2;
> }
> }
> });
> And then I add only 'styleMap: shpStyle' to my wfs layer and that's
> it. Spots are 2 pixels at the initial level and finally at the zoom
> level 7, they are 9 pixels.
>
> Thanks!
> - mika -
>
> Alexandre Dube kirjoitti:
>> Hi Mika,
>>
>> Try to remove all listeners, you don't need them. There's no need
>> to force of a new style, the context should already change the
>> radius value before drawing each features ( didn't try, but I think
>> it should do it ).
>>
>> Best of luck,
>>
>> Alexandre
>>
>> Lehtonen, Mika wrote:
>>> Hi Alexandre,
>>> interesting example.
>>> My problem is that I can't figure out how to force the wfs layer to
>>> read the new style parameters after the user has clicked zoom
>>> button. I have tried all sorts of, occassionaly desperate, methods
>>> for make it to do that. Like mergeNewParams and redraw. I switched
>>> them for example to map.event listener and tried to listen to any
>>> "sounds" of zooming; like zoomend. And those listeners sure did
>>> trigger the functions they were to, but the wfs layer stayed with
>>> the same style. I guess the easiest variable to use here, would be
>>> map.getZoom( ).
>>> - mika -
>>>
>>> Alexandre Dube kirjoitti:
>>>> Hi,
>>>>
>>>> Take a look at this example :
>>>>
>>>> http://dev.openlayers.org/sandbox/vector-behavior/examples/strategy-cluster.html
>>>>
>>>>
>>>> You could try to change the radius : function(feature) using
>>>> feature.layer.map.zoom
>>>>
>>>> Alexandre
>>>>
>>>> Lehtonen, Mika wrote:
>>>>> Hi,
>>>>>
>>>>> probably I'm asking something that's been asked for several times,
>>>>> but I just couldn't find the answer.
>>>>>
>>>>> I have a WFS layer which has points. My intention is to render
>>>>> those points with a style depending on the zoom level. So more you
>>>>> zoom in, bigger the points should be. I have styleMap defined in
>>>>> my wfs layer definition. I tried to do dynamic out of it, but
>>>>> didn't succeed. Even if I redraw my wfs layer, the styles defined
>>>>> at the first place stays.
>>>>>
>>>>> So, what would be a proper approach in this challenge?
>>>>>
>>>>> Here's my "static" code:
>>>>>
>>>>> shpStyle = new OpenLayers.StyleMap({
>>>>> pointRadius: 3,
>>>>> strokeColor: "red",
>>>>> strokeWidth: 1,
>>>>> strokeOpacity: 1,
>>>>> fillColor: 'black',
>>>>> fillOpacity: 0.2
>>>>> });
>>>>>
>>>>>
>>>>> fserver = new OpenLayers.Layer.WFS("Uploaded SHP",
>>>>> "http://10.8.0.1:8080/cgi-bin/featureserver-1.12/featureserver.cgi/shape?format=WFS",
>>>>>
>>>>> {typename: "KUNTA"},{extractAttributes: false, projection: new
>>>>> OpenLayers.Projection("EPSG:2393"), styleMap: shpStyle});
>>>>>
>>>>> - mika -
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at openlayers.org
>>>>> http://openlayers.org/mailman/listinfo/users
>>>>>
>>>>
>>>>
>>
>>
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list