# Labels.VisibilityExpression

**URL:** <https://mapwindow.discourse.group/t/labels-visibilityexpression/340>\
**Category:** MapWinGIS\
**Created:** [November 13, 2019, 6:06pm UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340 "2019-11-13T18:06:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luis](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@Luis](https://mapwindow.discourse.group/u/Luis)\
**Post date:** [November 13, 2019, 6:06pm UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/1 "2019-11-13T18:06:00Z")

</div>

Hello.  
I have a problem with Labels.VisibilityExpression. the expression with the shapefile works, but with the labels dosn`t work, any idea?  
Thanks  
My code.

> Private Sub CheckedNode\_CollectionChanged(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs)  
> Dim query As String = “”  
> ShapeMarcasIncidencia.DefaultDrawingOptions.Visible = True  
> ShapeMarcasIncidencia.Labels.Visible = True  
> For x = 0 To checkedNode.Count - 1  
> If checkedNode.Item(x).Tag IsNot Nothing Then  
> If x = 0 Then  
> query = "[MWShapeID] = " + checkedNode.Item(x).Tag.ToString + “”  
> Else  
> query += " OR [MWShapeID] = " + checkedNode.Item(x).Tag.ToString + “”  
> End If  
> End If  
> Next  
> If checkedNode.Count = 0 Then  
> ShapeMarcasIncidencia.DefaultDrawingOptions.Visible = False  
> ShapeMarcasIncidencia.Labels.Visible = False  
> Else  
> ShapeMarcasIncidencia.VisibilityExpression = query  
> ShapeMarcasIncidencia.Labels.VisibilityExpression = query  
> End If  
> AxMap1.Redraw()  
> End Sub

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [November 18, 2019, 1:30pm UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/2 "2019-11-18T13:30:33Z")

</div>

What is the value of `query`?

I haven’t used this myself, but looking at the documentation: [Labels.VisibilityExpression](https://www.mapwindow.org/documentation/mapwingis4.9/group __labels__ visibility.html#ga40e07aa272f371f1ca4193300187a5c5) it should work.

---

<div class="post-metadata">

**Author:** ![Luis](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@Luis](https://mapwindow.discourse.group/u/Luis)\
**Post date:** [November 20, 2019, 6:33pm UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/3 "2019-11-20T18:33:49Z")

</div>

Hello @pmeems the value of query is:

 ![q1](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/5b1dfe777f6e0aa1f7ae34b6aa80a10b8097b488.png) ![q2](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/ca36e7d173dda03c9b5f9168faaf8c2dfbc03a2a.png)  
 ![id](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/50d3ce5bd0f9b0675a14d15b4484333f0052e4b5.png)

With the shape works but with the labels dosen`t work  
this my code for add the labels and shapes.

 ![label](https://global.discourse-cdn.com/free1/uploads/mapwindow1/original/1X/aece2fddbc4990ef996014a19334395bf62db1ab.png)

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [November 20, 2019, 8:17pm UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/4 "2019-11-20T20:17:06Z")

</div>

Hello @Luis

It looks like your last parameter to the [AddLabel method](https://www.mapwindow.org/documentation/mapwingis4.9/group __labels__ management.html#ga1f4a8cd49d6abb99e47883a6517e0a25) is incorrect.

The last parameter should specify the Label Category index, not the Shape or Label index. Since you are not using label categories, you should just let that default to -1.

Regards,  
Jerry.

---

<div class="post-metadata">

**Author:** ![Luis](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@Luis](https://mapwindow.discourse.group/u/Luis)\
**Post date:** [November 20, 2019, 10:44pm UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/5 "2019-11-20T22:44:19Z")

</div>

Hello @jerryfaust  
Thanks i only was trying,  
But with -1 is the same result, i don’t know why.  
I can`t apply the visibility expression at labels, but in the shapes works very well.  
Regards.  
Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Luis](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@Luis](https://mapwindow.discourse.group/u/Luis)\
**Post date:** [November 21, 2019, 1:45am UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/6 "2019-11-21T01:45:24Z")

</div>

I did this, added the information the label in a column of the table, idon’t know it’s OK, but works.

> ```
> ShapeMarcasIncidencia.VisibilityExpression = query
> ShapeMarcasIncidencia.Labels.Clear()
> ShapeMarcasIncidencia.Labels.VisibilityExpression = query
> ShapeMarcasIncidencia.Labels.Generate("[Label]", tkLabelPositioning.lpCenter, True)
> 
> ```

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [November 21, 2019, 3:40am UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/7 "2019-11-21T03:40:17Z")

</div>

Very good. That’s the ideal solution, and the more traditional way you would add shape-based labels.

Rather than adding what might be considered ad-hoc labels, the Generate command creates labels specifically associated with each shape. In this case, I don’t think you need the “Labels.VisibilityExpression”, since the Label visibility should now follow the Shape visibility.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [December 11, 2019, 3:40am UTC](https://mapwindow.discourse.group/t/labels-visibilityexpression/340/8 "2019-12-11T03:40:17Z")

</div>

Closed on December 11, 2019, 3:40am UTC

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
