Closed mayur9785 closed 4 years ago
@mayur9785 It looks like you are overwriting any previous layer drawing options each time your showLabelPicker
method is called. Instead of:
var drawingOptions = new LayerDrawingOptions();
perhaps try getting the existing drawing options from the layer with something like this:
var drawingOptions = event.layer.layerDrawingOptions;
Hi @tmcgee Thanks you so much for reply. I tried this and first time when you click Label menu in LayerControl widget event.layer.layerDrawingOptions is undefined.
var drawingOptions = event.layer.layerDrawingOptions;
So I tried below code and its same if I turn Off first layer label and then turn off another layer label it switch the labeling.
var drawingOptions = new LayerDrawingOptions();
if (event.layer.layerDrawingOptions && event.layer.layerDrawingOptions[event.subLayer.id])
{
event.layer.layerDrawingOptions[event.subLayer.id].showLabels == true ? event.layer.layerDrawingOptions[event.subLayer.id].showLabels = false : event.layer.layerDrawingOptions[event.subLayer.id].showLabels = true
var options = [];
options[event.subLayer.id] = drawingOptions;
event.layer.setLayerDrawingOptions(options);
}
else
{
drawingOptions.showLabels = false;
var options = [];
options[event.subLayer.id] = drawingOptions;
event.layer.setLayerDrawingOptions(options);
}
Above code is working fine if I turn Off/On the same layer, e.g. turn off Manhole1 layer label and turn On the layer label its working, but If i turn off first layer (manhole1 ) and go for second layer (Parcel)to turn Off label it switch the labeling again.
Thanks,
@mayur9785 you should be able to resolve the undefined
error the first time by changing you code to this:
var drawingOptions = event.layer.layerDrawingOptions || new LayerDrawingOptions();
or by providing an initial layerDrawingOptions
when the layer is first added to the map.
Hi @tmcgee , Thanks for your reply. I tried this it is not working. Thanks,
@mayur9785 to assist further, please provide a complete example in a GitHub repo that demonstrates the issue.
Hi,
I have DynamicMapService published on server with by default labeling on for two layers (Manhole and Parcel). I have added SubLayerMenu in LayerControl widget as below :
After this I am able to see the menu Labels in all layers of LayerControl widget.
Now, I am trying with below code on topic.subscribe viewer.js file as below code.
Label is getting turn on/off but it switch the labeling for those two layers (manhole and Parcel). for example :
I have seen the LabelLayer widget here https://github.com/roemhildtg/cmv-widgets/tree/master/widgets/LabelLayer but I want option to turn on/off menu in LayerControl widget layers menu.
Is there anything am I missing in LayerControl widget menu I forgot to add ?
Thanks,