[OpenLayers-Users] Add a label on an Open Layers feature dynamically

thanili ailiop at ics.forth.gr
Wed Mar 19 09:06:27 PDT 2014


Hello Arnd,the second link you have sent really helped me and now i can
show/save/update labels (attributes) on open layers vectors. however
modifyFeature control does not seem to work anymore and it seem to be an
issue of conflicting with the select on click functionality implemented for
showing/editing labels.i am really new to OpenLayers as also not so
experienced in Jscript so any help on how to resolve this could be really
valuable!Here is some key parts in my code:/var ctrlSelectFeatures;var
aktPopup;var aktPopupFlag=false;var EditAllAtt=0;...function
initialiseMap(){    ...    map = new OpenLayers.Map(imageEditorID, options);			   
imageLayer = new OpenLayers.Layer.TMS(imgURL, "", {			url : '',		
serviceVersion : '.',			layername : '.',			alpha : true,			type : 'png',		
getURL : overlay_getTileURL,			transitionEffect: 'resize'    });   
map.addLayer(imageLayer);    var vlayer = new
OpenLayers.Layer.Vector("Editable");    map.addLayer(vlayer);    ...    //
Create the Panel to host the Custom Controls    var panel = new
OpenLayers.Control.Panel({ ....    //control for DRAW REGULAR POLYGON button   
var drawRegularPolygonControl = new
OpenLayers.Control.DrawFeatureOpt(vlayer, OpenLayers.Handler.RegularPolygon,    		
{title:'Draw a regular polygon', text:
'','displayClass':'olControlDrawFeatureRegularPolygon'});			    //control
for MODIFY button    var modifyFeatureControl = new
OpenLayers.Control.ModifyFeature(vlayer, {            clickout: true,           
toggle: false,            deleteCodes: [46, 68, 27],            title:
'Modify', text: '',            displayClass: "olControlModify"    });	   
//control for SHOW LABELS button    var addLabelFeatureControl = new
OpenLayers.Control.Button({		title: 'Toggle Labels', text: 'Toggle Labels',			
trigger: function(){						if(aktPopupFlag==false) {			aktPopupFlag=true;		
alert("Show Shape Info capability turned ON!");		}		else {  		
aktPopupFlag=false;			alert("Show Shape Info capability turned OFF!");		}	    			
}, 'displayClass': "olControlModify"	    });	    //control for ADD/UPDATE A
LABEL button    var updateLabelFeatureControl = new
OpenLayers.Control.Button({		title: 'Update Labels', text: 'Update Labels',			
trigger: function(){						if(EditAllAtt==0) {			EditAllAtt=1;		
if(aktPopupFlag==false){				aktPopupFlag=true;			}			alert("Update Shape
information capability turned ON!");		}		else {			EditAllAtt=0;		
alert("Update Shape information capability turned OFF!");		}	    				},
'displayClass': "olControlModify"	    });    ...    ...    ...    //Create
actions for drawing a regular Polygon
drawRegularPolygonControl.events.register("featureadded", this, function(e)
{		drawRegularPolygonControl.selectFeature(e.feature);	
drawRegularPolygonControl.selectControl.select(e.feature);	
drawRegularPolygonControl.activate();	
drawRegularPolygonControl.deactivate();    });    ...    //Create actions
for adding a label ?   
addLabelFeatureControl.events.register("featurelabeled", this, function(e) {    
aktPopupFlag=true;    	alert(aktPopupFlag);    });        //Create actions
for adding a label ?   
updateLabelFeatureControl.events.register("featureupdatelabel", this,
function(e) {    	EditAllAtt=1;    });    ...    //  select on click   
ctrlSelectFeatures = new OpenLayers.Control.SelectFeature(     		vlayer,            
{                 clickout: true, toggle: false,                 multiple:
false, hover: false,                 toggleKey: "ctrlKey", // ctrl key
removes from selection                 multipleKey: "shiftKey" // shift key
adds to selection             }     )    
map.addControl(ctrlSelectFeatures);     ctrlSelectFeatures.activate();         
vlayer.events.register('featureselected',   vlayer, regFeatureSelected);    
vlayer.events.register('featureunselected', vlayer, regFeatureUnselected);   
...    ...    ...    function regFeatureSelected()     {         aktPopup =
create_Popup();         var objF = this.selectedFeatures[0];         var
desc   = objF.attributes['description'] ? objF.attributes['description'] :
"about:blank";         document.getElementById("featDesc").innerHTML =
objF.attributes.name + ", " + objF.attributes.description;     }    
function regFeatureUnselected()     {         if(aktPopup)            
map.removePopup(aktPopup.popup);        
document.getElementById("featDesc").innerHTML = "selected feature
description";     }    ...    ...    ...    panel.addControls([
..../Something is conflicting or missing and modifyFeature control does not
work anymore! I can select (on click) a feature but when i try to activate
modifyControl it seems to be dead ...        



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Add-a-label-on-an-Open-Layers-feature-dynamically-tp5128562p5129907.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140319/40c4fb71/attachment-0001.html>


More information about the Users mailing list