<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">You can associate custom data either to the layer or it's features.<br><br></div><div class="gmail_default" style="font-family:courier new,monospace">

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?<br></div><div class="gmail_default" style="font-family:courier new,monospace">

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

<br></div><div class="gmail_default" style="font-family:courier new,monospace">Let me know if you understood.<br><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 12, 2014 at 2:38 PM, thanili <span dir="ltr"><<a href="mailto:ailiop@ics.forth.gr" target="_blank">ailiop@ics.forth.gr</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Guys i need some help on how to add (using maybee a popup requesting info<br>
from the user) on the fly labels:<br>
<br>
/function initialiseMap(){<br>
    ...<br>
    //map image layer<br>
    imageLayer = new OpenLayers.Layer.TMS(imgURL, "", {<br>
        url : '',<br>
        serviceVersion : '.',<br>
        layername : '.',<br>
        alpha : true,<br>
        type : 'png',<br>
        getURL : overlay_getTileURL,<br>
        transitionEffect: 'resize'<br>
    });<br>
    map.addLayer(imageLayer);<br>
    //prepare vector layer upon which features can be drawn<br>
    map.addLayer(imageLayer);<br>
    var vlayer = new OpenLayers.Layer.Vector("Editable");<br>
    map.addLayer(vlayer);<br>
    //fetch previously saved layer<br>
    var previousFeatures = getJSONData();<br>
    if(previousFeatures!=null) {<br>
    vlayer.addFeatures(previousFeatures);<br>
    } else {<br>
    }<br>
    ... // draw controls - toolbar, zoom controls etc// ...<br>
    var drawRegularPolygonControl = new<br>
OpenLayers.Control.DrawFeatureOpt(vlayer, OpenLayers.Handler.RegularPolygon,<br>
            {title:'Draw a regular polygon', text: 'Regular<br>
Polygon','displayClass':'olControlDrawFeatureRegularPolygon'});<br>
    ...<br>
    drawRegularPolygonControl.events.register("featureadded", this,<br>
function(e) {<br>
        modifyFeatureControl.selectFeature(e.feature);<br>
        modifyFeatureControl.selectControl.select(e.feature);<br>
        modifyFeatureControl.activate();<br>
        drawControl.deactivate();<br>
    });<br>
    .../<br>
<br>
All features can be drawn, saved and subsequently fetched in a vector layer.<br>
I would like to have the option to actually add a label to each such<br>
feature.<br>
<br>
As far i have looked at OpenLayers examples or read OpenLayers Docs i have<br>
not found any relevant example, apart from this:<br>
<br>
<a href="http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/vector-features-with-text.html" target="_blank">http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/vector-features-with-text.html</a><br>
<br>
however this example is static. I use OpenLayers.Control,<br>
OpenLayers.Handlers to actually draw dynamically features.<br>
<br>
How could i implement controls for adding feature labels? I guess<br>
<br>
I am thinking of using a control and a corresponding event like:<br>
<br>
/var addLabelFeatureControl = new OpenLayers.Control.SelectFeature(vlayer, {<br>
    clickout: false,<br>
    toggle: false,<br>
    title: 'Add Label', text: 'Add Label to Feature',<br>
    displayClass: "olControlAddLabel"<br>
});<br>
...<br>
addLabelFeatureControl.events.register("featurelabeled", this, function(e) {<br>
    var tempfeature = modifyFeatureControl.selectFeature(e.feature);<br>
    tempfeature.<br>
    modifyFeatureControl.selectControl.select(e.feature);<br>
    modifyFeatureControl.activate();<br>
    drawControl.deactivate();<br>
});/<br>
<br>
A) Is this approach correct? and if so B) How am i going to manipulate<br>
tempfeature? Meaning of terms of displaying a popup, getting user info<br>
(feature title,description) and saving into an existing or a new layer? C)<br>
If not could somebody suggest an approach?<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://osgeo-org.1560.x6.nabble.com/Add-a-label-on-an-Open-Layers-feature-dynamically-tp5128562.html" target="_blank">http://osgeo-org.1560.x6.nabble.com/Add-a-label-on-an-Open-Layers-feature-dynamically-tp5128562.html</a><br>


Sent from the OpenLayers Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div><span style="font-family:courier new,monospace">Melhores cumprimentos / Best regards,</span><b style="font-family:courier new,monospace"><br>Ruben Oliveira</b><br>

<br></div><a href="http://www.rubenoliveira.com" target="_blank">www.rubenoliveira.com</a><br></div>
</div>