LayerDrawingOptions (v3.1)

2695
3
04-24-2015 05:40 AM
LanceCrumbliss
Occasional Contributor II

Hello all,

It seems that the very act of creating LayerDrawingOptions is causing some issues that I can't figure out.

If DL.LayerDrawingOptions Is Nothing Then
                                               DL.LayerDrawingOptions = New LayerDrawingOptionsCollection
                                               For Each l As LayerInfo In DL.Layers
                                                   DL.LayerDrawingOptions.Add(New LayerDrawingOptions With {.ShowLabels = True, .Opacity = 1, .LayerID = l.ID})
                                               Next
                                           End If

First, it forces a legend refresh (and looks "bad" as a result).  OK, so then I sort of resolved that by not adding the layer to the legend until after the code above runs.  However, the second issue is that layers that are not on by default in the published MapService are turned on.  That is, if the MapService is published with layers :

"layers": [
  {
  "id": 0,
  "name": "Geoprobe Locations",
  "parentLayerId": -1,
  "defaultVisibility": false,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 1,
  "name": "Bubble Locations",
  "parentLayerId": -1,
  "defaultVisibility": false,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 2,
  "name": "Wells",
  "parentLayerId": -1,
  "defaultVisibility": false,
  "subLayerIds": [
  3,
  4,
  5
  ],
  "minScale": 0,
  "maxScale": 0
  },
  {
  "id": 3,
  "name": "Oil and Gas Wells",
  "parentLayerId": 2,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 4,
  "name": "Injection Wells",
  "parentLayerId": 2,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 5,
  "name": "Water Wells",
  "parentLayerId": 2,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 6,
  "name": "Whitestar Pipelines",
  "parentLayerId": -1,
  "defaultVisibility": false,
  "subLayerIds": null,
  "minScale": 577792,
  "maxScale": 0
  },
  {
  "id": 7,
  "name": "Sinkhole",
  "parentLayerId": -1,
  "defaultVisibility": true,
  "subLayerIds": [
  8,
  9
  ],
  "minScale": 0,
  "maxScale": 0
  },
  {
  "id": 8,
  "name": "Sinkhole Outline",
  "parentLayerId": 7,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 72225,
  "maxScale": 0
  },
  {
  "id": 9,
  "name": "Sinkhole",
  "parentLayerId": 7,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 72225
  },
  {
  "id": 10,
  "name": "Coastal Permits",
  "parentLayerId": -1,
  "defaultVisibility": false,
  "subLayerIds": [
  11,
  12
  ],
  "minScale": 0,
  "maxScale": 0
  },
  {
  "id": 11,
  "name": "Coastal_Permit_Lines",
  "parentLayerId": 10,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 288896,
  "maxScale": 0
  },
  {
  "id": 12,
  "name": "Coastal_Permit_Polygons",
  "parentLayerId": 10,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 288896,
  "maxScale": 0
  },
  {
  "id": 13,
  "name": "Salt Dome",
  "parentLayerId": -1,
  "defaultVisibility": true,
  "subLayerIds": [
  14,
  15
  ],
  "minScale": 0,
  "maxScale": 0
  },
  {
  "id": 14,
  "name": "Salt Dome Outline",
  "parentLayerId": 13,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 15,
  "name": "Salt Dome",
  "parentLayerId": 13,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 144449,
  "maxScale": 0
  },
  {
  "id": 16,
  "name": "Louisiana Public Land Survey",
  "parentLayerId": -1,
  "defaultVisibility": true,
  "subLayerIds": [
  17,
  18
  ],
  "minScale": 1155582,
  "maxScale": 0
  },
  {
  "id": 17,
  "name": "Township and Ranges",
  "parentLayerId": 16,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 1155582,
  "maxScale": 0
  },
  {
  "id": 18,
  "name": "Sections",
  "parentLayerId": 16,
  "defaultVisibility": true,
  "subLayerIds": null,
  "minScale": 288896,
  "maxScale": 0
  }
]

After the code at the top is executed, the body of the POST the subsequently retrieves the MapServices' exported image is show below:

[{"id":3,"source":{"type":"mapLayer","mapLayerId":3},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":4,"source":{"type":"mapLayer","mapLayerId":4},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":5,"source":{"type":"mapLayer","mapLayerId":5},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":7,"source":{"type":"mapLayer","mapLayerId":7},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":8,"source":{"type":"mapLayer","mapLayerId":8},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":11,"source":{"type":"mapLayer","mapLayerId":11},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":12,"source":{"type":"mapLayer","mapLayerId":12},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":13,"source":{"type":"mapLayer","mapLayerId":13},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":14,"source":{"type":"mapLayer","mapLayerId":14},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":15,"source":{"type":"mapLayer","mapLayerId":15},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":16,"source":{"type":"mapLayer","mapLayerId":16},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":17,"source":{"type":"mapLayer","mapLayerId":17},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}},{"id":18,"source":{"type":"mapLayer","mapLayerId":18},"drawingInfo":{"transparency":0,"scaleSymbols":false,"showLabels":true}}]

This seems to turn on layers that are defined as visibile by default, but that are children of grouplayers that are defined as NOT visible by default.  For example, Layers 11 and 12 are then visible despite their parent (layer 10) not being visible. It is also odd that the transparency is "0" when I've set it to 1 in the code at the top.

0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor

If you don't want to see the sublayers that are not viisble by default, you should not add them in LayerDrawingOptions.

LayerDrawingOptions is used to override what is defined at server side and allows getting viisble sublayers that are not visible by default.

Concerning the legend, it's normal that the legend is refreshed. What is 'bad' in your result? (do you mean that the legend doesn't look like the symbols displayed in the map?)

It is also odd that the transparency is "0" when I've set it to 1 in the code at the top.

REST API uses 'transparency' while it's exposed as 'opacity' in the API --> reversed

0 Kudos
LanceCrumbliss
Occasional Contributor II
REST API uses 'transparency' while it's exposed as 'opacity' in the API --> reversed

ah, ok.  didn't even notice that one was "transparency" and the other was "opacity".  duh!

Concerning the legend, it's normal that the legend is refreshed. What is 'bad' in your result? (do you mean that the legend doesn't look like the symbols displayed in the map?)

I just mean it looks bad from a UI experience.  The legend completely collapses and then the tree repopulates.  However, it doesn't maintain the collapsed/uncollapsed states of the branches.  The latter part was really more of an issue initially when I was creating the LayerDrawingOptions after adding the layer to the legend though (and the legend may have been interacted with by the user).  It also meant that the context menu that was aligned with the LegendItem that was clicked (and thus triggered the LayerDrawingOptions creation) was suddenly no longer aligned with the LegendItem (at least temporarily at best).  But as I indicated, calling the LayerDrawingOptions before the layer is added to the legend alleviates that problem.

If you don't want to see the sublayers that are not viisble by default, you should not add them in LayerDrawingOptions.

LayerDrawingOptions is used to override what is defined at server side and allows getting viisble sublayers that are not visible by default.

Do you happen to have code that determines if a visible childayer is actually not visible because it's parent isn't?  I imagine it would need to be recursive since a grouplayer can contain grouplayers.  Or am I overthinking it?

0 Kudos
DominiqueBroux
Esri Frequent Contributor

The legend completely collapses and then the tree repopulates.

OK I see. The problem is that by changing dynamically the sublayers it's very likely that the items in the legend trees are no more the same (may have new sublayers, some may disappear, ...), so it's difficult to keep the sublayers legend state (I guess this might be enhanced in legend control though).

Do you happen to have code that determines if a visible childayer is actually not visible because it's parent isn't?  I imagine it would need to be recursive since a grouplayer can contain grouplayers.  Or am I overthinking it?

Yes you need to go through the sublayer hierarchy (one weird trick without any guarantee might be to toggle twice a sublayer visibility (using ArcGISDynamicMapServiceLayer.SetLayerVisibility) then VisibleLayers should be populated with the list of visible sublayer leaves.)

0 Kudos