With my GeoExt code, it looks like that (there is also something for the font size):

var labelForm = new Ext.form.FormPanel({
                        items:[{
                                xtype: "textarea",
                                name: "label",
                                value: "",
                                fieldLabel: "Text "
                        },{
                                xtype: "combo",
                                store: [10,12,14,16,18,20,22,24,26,28,30],
                                displayField: "fontsize",
                                fieldLabel: "Font size ",
                                typeAhead: true,
                                mode: "local",
                                triggerAction: "all",
                                editable: false,
                        }],
                        buttons: [{
                                text: "Validate",
                                handler: function() {
var labelValue = labelForm.items.items[0].getValue(); //get the typed text var fontSize = labelForm.items.items[1].getValue(); /:get the selected font size e.feature.style = {label: labelValue, labelSelect: true, fontSize: fontSize}; //labelSelect allows to drag the text
                                        labelWindow.close(); //The labelForm is 
shown in an Ext.Window
                                        drawLayer.redraw(); //Refresh needed to 
apply the label
                                }
                        }]
});

This code is inserted in a drawFeature control, on "featureAdded". The drag property works if you have and activate an OpenLayers control allowing to drag a feature on the same layer (like a dragFeature or modifyFeature control). In this case, you can select directly the text without displaying any point.

If you adapt the code for OpenLayers, it should work without GeoExt.

Geoffrey


On Tue, 30 Aug 2011 15:03:30 +0200, Tobias Reinicke <[email protected]> wrote:

Any chance you could share your code / show an example? would be
interested to see the dragging functionality.

THanks,

Toby

On 30 August 2011 13:39, gbrun <[email protected]> wrote:
Thanks! That's just what I have done! It works great! But I didn't use the attributes property: I don't need to save the label text in a database. I
store the written text directly inside the 'label' property. It's also
useful to add a 'labelSelect' property with 'true' to drag the text once
written. It could be interesting to create an OpenLayers example about this.
It is a very simple tip, but quite useful.

PS: it works also with GeoExt and a FormPanel to write the text.

Geoffrey


On Tue, 30 Aug 2011 13:50:38 +0200, Frost89 <[email protected]>
wrote:

Try adding a drawfeature control, that prompts for a text and sets it as
the
label. Should be something like this this:

var control = new OpenLayers.Control.DrawFeature(
 layer,
 OpenLayers.Handler.Point, {
   featureAdded: function(feature) {
     feature.attributes.text = prompt('Write here:', '');
     feature.style.label = feature.attributes.text;
     feature.layer.drawFeature(feature);
   }
 }
);

-----
Best regards,
Kristian Frost
Webintegrator
Orbicon Informatik
--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/Write-text-on-a-map-tp6741079p6741765.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


--
Using Opera's revolutionary email client: http://www.opera.com/mail/
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users



--
Using Opera's revolutionary email client: http://www.opera.com/mail/
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to