[OpenLayers-Users] Add a label on an Open Layers feature dynamically
Arnd Wippermann
arnd.wippermann at web.de
Wed Mar 12 10:08:19 PDT 2014
Hi,
Perhaps this examples will you get further:
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL210/Map_mit_Marker.asp
http://gis.ibbeck.de/ginfo/apps/OLExamples/OL210/styles_unique_with_group.as
p
Arnd
-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von thanili
Gesendet: Mittwoch, 12. März 2014 15:39
An: openlayers-users at lists.osgeo.org
Betreff: [OpenLayers-Users] Add a label on an Open Layers feature
dynamically
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-feature
s-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-dy
namically-tp5128562.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
More information about the Users
mailing list