<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-15">
<META content="MSHTML 6.00.2900.3243" name=GENERATOR></HEAD>
<BODY defanghtml_style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>Thanks to Arnd and Dane, this is what works:</DIV>
<DIV> </DIV>
<DIV>I first create the layer:</DIV>
<DIV> </DIV>
<DIV>function cropsreturn(cropsresponse) {<BR> crop_style.strokeColor = "#ff0000";<BR> if (cropsresponse.responseText.indexOf('Error') != -1) {<BR> window.alert("no crops");<BR> crops = new OpenLayers.Layer.Vector("Crop areas",<BR> {isBaseLayer: false,<BR> style: crop_style, <BR> extractAttributes: true });<BR> map.addLayer(crops);<BR> map.zoomToMaxExtent();<BR> }<BR> else {<BR> crops = new OpenLayers.Layer.Vector("Crop areas",<BR> {isBaseLayer: false,<BR> style: crop_style, <BR> extractAttributes: true }); <BR> crops.addFeatures(geojson_format.read(cropsresponse.responseText));<BR> map.addLayer(crops);<BR> map.zoomToExtent(crops.getDataExtent());<BR> }</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>//later:</DIV>
<DIV>crops.onFeatureInsert = function(feature) {<BR> feature.attributes.prop0 = 'new'; //This should be modified to get actual primary key<BR> window.alert("New crop area inserted");<BR> }</DIV>
<DIV> </DIV>
<DIV>Robert<BR><BR>>>> "Arnd Wippermann" <arnd.wippermann@web.de> 16/10/2008 6:44 a.m. >>><BR></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>Hi Robert,</DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008></DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>perhaps this is a way</DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008></DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>register 'featureadded' for the vector layer</DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008></DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008> * - *featureadded* Triggered after a feature is added. The event<BR> * object passed to listeners will have a *feature* property with a<BR> * reference to the added feature.<BR></DIV></DEFANGHTML_SPAN>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>crop_layer.events.register('featureadded', crop_layer, regFeatureAdded);<BR></DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>function regFeatureAdded()</DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>{</DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008> this.attributes['name'] = 'name';</DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008> this.attributes['description'] = 'description';</DEFANGHTML_SPAN></DIV></DEFANGHTML_SPAN></DIV>
<DIV dir=ltr align=left><DEFANGHTML_SPAN class=875103917-15102008>}</DEFANGHTML_SPAN></DIV>
<DIV> </DIV>
<DIV><DEFANGHTML_SPAN class=875103917-15102008></DEFANGHTML_SPAN>b<DEFANGHTML_SPAN class=875103917-15102008>ut I have it not tested.</DEFANGHTML_SPAN></DIV>
<DIV><DEFANGHTML_SPAN class=875103917-15102008></DEFANGHTML_SPAN></DIV>
<DIV><DEFANGHTML_SPAN class=875103917-15102008>Arnd Wippermann</DEFANGHTML_SPAN></DIV>
<DIV><BR></DIV>
<DIV class=OutlookMessageHeader lang=de dir=ltr align=left>
<HR tabIndex=-1>
<B>Von:</B> users-bounces@openlayers.org [mailto:users-bounces@openlayers.org] <B>Im Auftrag von </B>Robert Sanson<BR><B>Gesendet:</B> Mittwoch, 15. Oktober 2008 05:46<BR><B>An:</B> users@openlayers.org<BR><B>Betreff:</B> [OpenLayers-Users] Adding an attribute field to a vector layer<BR><BR></DIV>
<DIV></DIV>
<DIV>I am developing an application that allows a user to digitise crop areas. The areas created will then be uploaded to a SQL-server database via a geoJSON string sent to a ColdFusion service.</DIV>
<DIV> </DIV>
<DIV>How can I specify one or more attribute fields?</DIV>
<DIV> </DIV>
<DIV>I am using the following construct:</DIV>
<DIV> </DIV>
<DIV>var crop_layer = new OpenLayers.Layer.Vector(); <BR>map.addLayer(crop_layer);</DIV>
<DIV> </DIV>
<DIV>Many thanks,</DIV>
<DIV> </DIV>
<DIV>Robert Sanson</DIV><BR><BR>
<TABLE style="COLOR: black" bgColor=white>
<TBODY>
<TR>
<TD><BR>------------------------------------------------------------------<BR>The contents of this email are confidential to AsureQuality. If you have received this communication in error please notify the sender immediately and delete the message and any attachments. The opinions expressed in this email are not necessarily those of AsureQuality. This message has been scanned for known viruses before delivery. AsureQuality supports the Unsolicited Electronic Messages Act 2007. If you do not wish to receive similar communications in future, please notify the sender of this message.<BR>------------------------------------------------------------------</TD></TR></TBODY></TABLE><BR><BR>
<P align=center><FONT style="BACKGROUND-COLOR: #ffffff">This message has been scanned for malware by SurfControl plc. </FONT><A href="http://www.surfcontrol.com/"><FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>www.surfcontrol.com</FONT></A></P><BR><BR><FONT style="BACKGROUND-COLOR: #ffffff">
<P align=center><FONT style="BACKGROUND-COLOR: #ffffff">Click <A href="https://www.mailcontrol.com/sr/4agG!UriteLTndxI!oX7Uk5xG16jLorQQdHcnaqaSdCccDFHLAbYsv!kKJyfABBkPcDY0etAPoqtoBNtFUgrMg==">here</A> to report this email as spam.</FONT></P></FONT><br><br><table bgcolor=white style="color:black"><tr><td><br>------------------------------------------------------------------<br>
The contents of this email are confidential to AsureQuality. If you have received this communication in error please notify the sender immediately and delete the message and any attachments. The opinions expressed in this email are not necessarily those of AsureQuality. This message has been scanned for known viruses before delivery. AsureQuality supports the Unsolicited Electronic Messages Act 2007. If you do not wish to receive similar communications in future, please notify the sender of this message.<br>
------------------------------------------------------------------</td></tr></table></BODY></HTML>