Select to view content in your preferred language

Beta 2.1 - New Legend Feature Questions - using Aliases For Layer Names

767
3
11-18-2010 04:05 AM
SpencerWilliams
Deactivated User
Hello,

I am currently working on getting a very large project built using the Silverlight API to fit into MVVM with the Prism Framework.  I like the easy of use (I can see you are using viewModel constructs as well) of the new Legend feature and the databinding.  I think this question will apply to many people that want to use the legend in 2.1 as the legend they use going forward.  (Althought I spent a lot of time tweaking the SharpGIS legend to suit my needs 😞 ).

The question: 

What would be the best way (with MVVM in mind) to "inject" aliases for layers into the legend?

IE:  "WORLD_TRANSPORTATION" becomes "Streets Overlay"

One of the main issues I have with binding to the actual name of the layer is that we use the name of the layer for identification elsewhere (identifying a project in an external database by numeric ID).

Should I create my own layer class?
Should I use a data template? (doesn't seem to be too much info on what the legend control supports)
Something else?

Because this ties to ArcGIS server services now, I really want to use it going forward in my application.  My guess is that it will tie to other things later (printing anyone?)  🙂 .



Thanks,

Spencer Williams

Forestar Group, Inc.
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
For sure, you could do that by code. On the 'Refreshed' event of the legend, you can change the label of the LayerItem from the layername to the alias name. Now that's probably not the best way with MVVM in mind 🙂

Where are coming your aliases from? I don't think there is any layer alias returned by the REST API.
0 Kudos
SpencerWilliams
Deactivated User
Aliases are coming from an external DB table that I am using to populate a menu with projects.  A project is selected and then added as a feature layer to the map.  We also do this with external overlays (data from various sources) all information about the layer is stored in a database, along with the URL that points to the service:

http://raustpsw0792/ArcGIS/rest/services/100YearFloodPlain/MapServer

So we will be storing an abstract, date gathered, user that added it to the repository, date of data in the layer, etc in an external DB that ties to a web application that allows users to upload data for a GIS resource to add into ArcGIS server as a layer.  So I will have a data structure for each layer in the application already - but I want to have a way to bind it (somehow) to the layer data that the legend uses as soon as it is displayed on the map - that way I don't hard code aliases in the app.

Thanks for the quick response 🙂

-Spencer
0 Kudos
DominiqueBroux
Esri Frequent Contributor
One option is you to develop a value converter (e.g. 'AliasConverter') which is returning the alias from one of the LayerItemViewModel or Layer property.

So you could use a maplayertemplate which looks like:
 
<esri:Legend.MapLayerTemplate>
  <DataTemplate>
    <StackPanel Orientation="Horizontal">
      <CheckBox Content="{Binding Layer.ID, Converter=AliasConverter}"
           IsChecked="{Binding IsEnabled, Mode=TwoWay}"
           IsEnabled="{Binding IsInScaleRange}" >
       </CheckBox>
      <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
    </StackPanel>
  </DataTemplate>
</esri:Legend.MapLayerTemplate>


Or more generally:  "{Binding Layer.ID, Converter=LayerConverter, ConverterParameter=Alias}" if you want to use the same converter to retrieve Url, Description, Copyright, ....
0 Kudos