You can associate custom data either to the layer or it's features. If you use the layer, my advice is to use the metadata attribute that comes with the Layer object. However, if I understood correctly, you want to associate data to a feature vector, right? In that case, you can use the attribute named "attributes" that comes in each feature vector object (I've done it that way). Remember that this attribute is used by the layers render intent to render (or not) it's values. So if you want to make your changes visible you will need to call the redraw method on the layer that contains you feature vectors.
Let me know if you understood. On Wed, Mar 12, 2014 at 2:38 PM, thanili <ail...@ics.forth.gr> wrote: > Guys i need some help on how to add (using maybee a popup requesting info > from the user) on the fly labels: > > /function initialiseMap(){ > ... > //map image layer > imageLayer = new OpenLayers.Layer.TMS(imgURL, "", { > url : '', > serviceVersion : '.', > layername : '.', > alpha : true, > type : 'png', > getURL : overlay_getTileURL, > transitionEffect: 'resize' > }); > map.addLayer(imageLayer); > //prepare vector layer upon which features can be drawn > map.addLayer(imageLayer); > var vlayer = new OpenLayers.Layer.Vector("Editable"); > map.addLayer(vlayer); > //fetch previously saved layer > var previousFeatures = getJSONData(); > if(previousFeatures!=null) { > vlayer.addFeatures(previousFeatures); > } else { > } > ... // draw controls - toolbar, zoom controls etc// ... > var drawRegularPolygonControl = new > OpenLayers.Control.DrawFeatureOpt(vlayer, > OpenLayers.Handler.RegularPolygon, > {title:'Draw a regular polygon', text: 'Regular > Polygon','displayClass':'olControlDrawFeatureRegularPolygon'}); > ... > drawRegularPolygonControl.events.register("featureadded", this, > function(e) { > modifyFeatureControl.selectFeature(e.feature); > modifyFeatureControl.selectControl.select(e.feature); > modifyFeatureControl.activate(); > drawControl.deactivate(); > }); > .../ > > All features can be drawn, saved and subsequently fetched in a vector > layer. > I would like to have the option to actually add a label to each such > feature. > > As far i have looked at OpenLayers examples or read OpenLayers Docs i have > not found any relevant example, apart from this: > > > http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/vector-features-with-text.html > > however this example is static. I use OpenLayers.Control, > OpenLayers.Handlers to actually draw dynamically features. > > How could i implement controls for adding feature labels? I guess > > I am thinking of using a control and a corresponding event like: > > /var addLabelFeatureControl = new OpenLayers.Control.SelectFeature(vlayer, > { > clickout: false, > toggle: false, > title: 'Add Label', text: 'Add Label to Feature', > displayClass: "olControlAddLabel" > }); > ... > addLabelFeatureControl.events.register("featurelabeled", this, function(e) > { > var tempfeature = modifyFeatureControl.selectFeature(e.feature); > tempfeature. > modifyFeatureControl.selectControl.select(e.feature); > modifyFeatureControl.activate(); > drawControl.deactivate(); > });/ > > A) Is this approach correct? and if so B) How am i going to manipulate > tempfeature? Meaning of terms of displaying a popup, getting user info > (feature title,description) and saving into an existing or a new layer? C) > If not could somebody suggest an approach? > > > > -- > View this message in context: > http://osgeo-org.1560.x6.nabble.com/Add-a-label-on-an-Open-Layers-feature-dynamically-tp5128562.html > Sent from the OpenLayers Users mailing list archive at Nabble.com. > _______________________________________________ > Users mailing list > us...@lists.osgeo.org > http://lists.osgeo.org/mailman/listinfo/openlayers-users > -- Melhores cumprimentos / Best regards, *Ruben Oliveira* www.rubenoliveira.com
_______________________________________________ Users mailing list us...@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/openlayers-users