[OpenLayers-Users] How to call a function that sets attributes
for features added by drawfeature-control
Alexandre Dube
adube at mapgears.com
Tue Sep 1 11:12:13 EDT 2009
Hi Max,
I'm not sure about what could be the best approach. My guess would be
to define a stylemap with your default 'default' and 'select' styles for
newly added features, then when your user choose a color for the
feature, add a rule based on the feature id.
Have you checked : http://trac.openlayers.org/wiki/Styles ? It could
helps to learn more about this.
Also, an example with unique rules :
http://openlayers.org/dev/examples/styles-unique.html
Regards,
Alexandre
Max Stephan wrote:
> Hi Alexandre,
>
> I got it working now. The Problem was that in the function that was
> triggered by the featureadded-event I tried something like feature.id and
> not evt.feature.id.
> I registered the event via
> "drawFeatureControlName.events.register("featureadded", ' ' , function)".
>
> But, as always, one problem solved and another one evolves. As said before I
> want to apply a user-customizable style to each feature added. I´ve done
> this for example via "evt.feature.style = {fillcolor: "#FF9933",
> pointRadius: 10, strokeColor: 'black'}" and after that I´m redrawing the
> feature via "vectorLayer.drawFeature(evt.feature)". This works and the point
> is symbolized in the planned way. But when I select one of those points on
> the map the radius shrinks (I guess to the size of the default-style for
> point-Vectorfeatures) and the stroke is gone. Even when I unselect the
> feature it stays in this changed style. Now I tried to apply a stylemap with
> default- and selectStyle to the feature but that didn´t have any effect (the
> points stayed in their default-orange-style).
>
> Any idea how to solve this problem? Rulebased styling via a layerwide
> stylemap is no option cause as said above the user should be able to choose
> color etc. independently.
>
> Greets and thx for your help
> Max Stephan
>
> Alexandre Dube wrote:
>
>> Hi Max,
>>
>> Here's an old demo that could help you for some of your needs :
>>
>> http://dev4.mapgears.com/bdga/bdgaWFS-T.html
>>
>> Simply click on a feature. This demonstrate a way to edit feature's
>> attributes in a form. If your data is stored in a DB, you don't need to
>> take care of the id manually. The DB will automatically generate one.
>>
>> The example is using WFS-T to TinyOWS connected to a PostGIS DB.
>>
>> Best of luck,
>>
>> Alexandre
>>
>> Max Stephan wrote:
>>
>>> Hi list,
>>>
>>> I´m actually implementing a drawfeature-control for my web-GIS.
>>> Everything´s
>>> working fine so far but now I want to add a little more functionality:
>>> - the user should be able to specify the appearance of the features he´s
>>> adding. This shall only have an effect on the features he´s adding after
>>> specifying the style (so a change of the general vectorlayer-Style is not
>>> useful)
>>> - each feature should get a unique ID whose format I´d like to specify
>>> and
>>> which is generated by a script-wide counter for example
>>>
>>> For both of this cases I thought of the event featureadded. But I´m
>>> having
>>> some trouble with it. Here´s what I tried:
>>>
>>> 1. event-listener on the layer to which the features are added:
>>>
>>> example: vectorLayer.events.register('featureadded', vectorlayer,
>>> testFunction);
>>>
>>> 2. event-listener on the handler for drawfeature-control (same as above
>>> but
>>> with vectorLayer being replaced by the drawfeature-control)
>>>
>>> 3. event-listener in this form:
>>>
>>> vectorLayer.events.on("featureadded": testFunction, ...);
>>>
>>> The testFunction is meant to specify the attributes like style, id etc.
>>> on
>>> the feature that was added. The function is executed (tested it with an
>>> alert).
>>>
>>> The problem is that it´s not possible to select features on this layer
>>> (the
>>> other vectorlayers are still working) when using the
>>> featureadded-listener.
>>> But I need to be able to select features to modify it´s attributes later
>>> on
>>> or to clear them via a form.
>>>
>>> I also thought of using the create-callback of the point-handler but
>>> don´t
>>> know how to implement it.
>>>
>>> Any ideas and help is appreciated.
>>> Thx in advance
>>> Max Stephan
>>>
>>>
>> --
>> Alexandre Dubé
>> Mapgears
>> www.mapgears.com
>>
>> _______________________________________________
>> 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