<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>Re: [OpenLayers-Users] Draw a point and assign a dynamic label to it</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>On 03/24/2010 01:52 PM, Frost89 wrote:<BR>
> Hi list<BR>
><BR>
> In my map I have added a vector layer and a drawFeature control.<BR>
> The drawFeature is set to draw points, and works without problems.<BR>
><BR>
> Now, I would like to assign a text-label to the point's style.<BR>
> The text in the label should be defined by the user (through a prompt() or<BR>
> other alternatives).<BR>
> <BR>
<BR>
Try and set the text in the feature's properties:<BR>
feature.properties.text = mytext;<BR>
<BR>
and then add a style to the layer you place the feature in:<BR>
<BR>
var style = new OpenLayers.Style({<BR>
label: "${text}",<BR>
});<BR>
<BR>
(a bit confused about your code snippet, is the event in featureAdded<BR>
indeed the created feature?)<BR>
<BR>
-atle<BR>
> So I was thinking about settings this value in the "featureAdded" event of<BR>
> the drawFeature control, but I can't quite figure out how to do this.<BR>
> When I try to do it like this...<BR>
> var point = new OpenLayers.Control.DrawFeature(<BR>
> vectorLayer,<BR>
> OpenLayers.Handler.Point,<BR>
> {<BR>
> type: OpenLayers.Control.TYPE_TOOL,<BR>
> featureAdded: function(event) {<BR>
> event.style.label = 'test';<BR>
> redliningLayer.drawFeature(event);<BR>
> }<BR>
> }<BR>
> );<BR>
> <BR>
> ... I just get an error message:<BR>
> event.style is null<BR>
> So if anyone has an idea of how to do this, it would be appreciated :)<BR>
><BR>
> - Kristian Frost<BR>
> <BR>
<BR>
<BR>
--<BR>
Atle Frenvik Sveen<BR>
GIS Konsulent<BR>
Geomatikk IKT AS<BR>
tlf: 45 27 86 89<BR>
atle.frenvik.sveen@geomatikk.no<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>