[OpenLayers-Users] rules depending on state
Eric Lemoine
eric.c2c at gmail.com
Tue May 20 12:11:13 EDT 2008
Andreas actually did the initial review.
2008/5/20, Pierre GIRAUD <bluecarto at gmail.com>:
> Hi Tim,
>
> The last Andreas' proposal was put into a patch I commit yesterday.
> http://trac.openlayers.org/changeset/7216
>
> Eric reviewed this but you can still have a look and scream if you don't
> agree.
>
> Regards,
> Pierre
>
> On Mon, May 19, 2008 at 9:39 PM, Tim Schaub <tschaub at opengeo.org> wrote:
>> Pierre GIRAUD wrote:
>>> Yep,
>>> I already tried that and this works great.
>>> However, what if I want to set fillColor, strokeColor, fillOpacity and
>>> strokeOpacity at the same time ? This is really painful.
>>> And it seems like I need to provide a valid value for each possible
>>> value of state. Default style won't be applied to features that aren't
>>> in the switch cases.
>>>
>>> I would prefer something like :
>>> var lookup = {
>>> 'Insert': {
>>> fillColor: 'green',
>>> fillOpacity: 0.5
>>> },
>>> ...
>>> };
>>>
>>
>> Yes, you're right, you need a different function for each symbolizer
>> property. However, it shouldn't be too painful.
>>
>> function getValue(state, key) {
>> var value = lookup[state][key];
>> if(value == undefined) {
>> value = defaultSymbolizer[key];
>> }
>> return value;
>> }
>> var context = {
>> getFillColor: function(feature) {
>> return getValue(feature.state, "fillColor");
>> },
>> ...
>> };
>>
>> Wouldn't be too hard to allow the symbolizer to be a function. This
>> function would be called for each feature and would return a symbolizer.
>> In fact, this seems more intuitive than the style context stuff.
>>
>> The style stuff can be made less twisted in OL3.
>>
>> Tim
>>
>>
>>> Regards,
>>> Pierre
>>>
>>>
>>> On Tue, May 13, 2008 at 4:35 PM, Andreas Hocevar
>>> <andreas.hocevar at gmail.com> wrote:
>>>> Hey Pierre,
>>>>
>>>> without having tried, something like the following should work:
>>>>
>>>> var context = {
>>>> getStateColor: function(feature) {
>>>> switch(feature.state) {
>>>> case "Insert": return "green";
>>>> case "Update": return "yellow";
>>>> case "Delete": retrun "red";
>>>> }
>>>> }
>>>> }
>>>>
>>>> var styleMap = new OpenLayers.StyleMap(new OpenLayers.Style({
>>>> strokeColor: "${getStateColor}"
>>>> }, {context: context}));
>>>>
>>>> Regards,
>>>> Andreas.
>>>>
>>>>
>>>> Pierre GIRAUD wrote:
>>>>
>>>>>
>>>>>
>>>>> Hello OpenLayers styleMap gurus,
>>>>>
>>>>> I would like to have different symbolizers for the features depending
>>>>> on their state property.
>>>>> The addUniqueValueRules would look perfect for that but the context of
>>>>> the generated rules is feature.attributes. The state will not be
>>>>> evaluated because it's not one of those attributes.
>>>>>
>>>>> Has anyone a workaround to advice ?
>>>>>
>>>>> Regards,
>>>>>
>>>>> Pierre
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at openlayers.org
>>>>> http://openlayers.org/mailman/listinfo/users
>>>>>
>>>>>
>>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at openlayers.org
>>> http://openlayers.org/mailman/listinfo/users
>>>
>>> !DSPAM:4033,4829ade5124501137850744!
>>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list