[OpenLayers-Users] Adding an attribute field to a vector layer

Robert Sanson SansonR at asurequality.com
Thu Oct 16 17:08:53 EDT 2008


Thanks to Arnd and Dane, this is what works:
 
I first create the layer:
 
function cropsreturn(cropsresponse) {
              crop_style.strokeColor = "#ff0000";
              if (cropsresponse.responseText.indexOf('Error') != -1) {
                window.alert("no crops");
                crops = new OpenLayers.Layer.Vector("Crop areas",
                  {isBaseLayer: false,
                   style: crop_style, 
                   extractAttributes: true });
                 map.addLayer(crops);
                 map.zoomToMaxExtent();
              }
              else {
                crops = new OpenLayers.Layer.Vector("Crop areas",
                  {isBaseLayer: false,
                   style: crop_style, 
                   extractAttributes: true }); 
                   crops.addFeatures(geojson_format.read(cropsresponse.responseText));
                 map.addLayer(crops);
                 map.zoomToExtent(crops.getDataExtent());
              }
}
 
//later:
crops.onFeatureInsert = function(feature) {
                feature.attributes.prop0 = 'new'; //This should be modified to get actual primary key
                window.alert("New crop area inserted");
 }
 
Robert

>>> "Arnd Wippermann" <arnd.wippermann at web.de> 16/10/2008 6:44 a.m. >>>
Hi Robert,
perhaps this is a way
register 'featureadded' for the vector layer
     *  - *featureadded* Triggered after a feature is added.  The event
     *      object passed to listeners will have a *feature* property with a
     *      reference to the added feature.
crop_layer.events.register('featureadded', crop_layer, regFeatureAdded);
function regFeatureAdded()
{
    this.attributes['name'] = 'name';
    this.attributes['description'] = 'description';
}
 
but I have it not tested.
Arnd Wippermann

Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im Auftrag von Robert Sanson
Gesendet: Mittwoch, 15. Oktober 2008 05:46
An: users at openlayers.org 
Betreff: [OpenLayers-Users] Adding an attribute field to a vector layer

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.
 
How can I specify one or more attribute fields?
 
I am using the following construct:
 
var crop_layer = new OpenLayers.Layer.Vector(); 
map.addLayer(crop_layer);
 
Many thanks,
 
Robert Sanson




------------------------------------------------------------------
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.
------------------------------------------------------------------



This message has been scanned for malware by SurfControl plc. www.surfcontrol.com ( http://www.surfcontrol.com/ )


Click here ( https://www.mailcontrol.com/sr/4agG!UriteLTndxI!oX7Uk5xG16jLorQQdHcnaqaSdCccDFHLAbYsv!kKJyfABBkPcDY0etAPoqtoBNtFUgrMg== ) to report this email as spam.
------------------------------------------------------------------
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.
------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081017/00c132e3/attachment.html


More information about the Users mailing list