AnsweredAssumed Answered

Using ArcGIS Runtime SDK for .NET, how can I display the legend or symbology of an image, along with the image, on a map?

Question asked by reneecammarere on Jun 2, 2017

Using ArcGIS Runtime SDK for .NET, how can I display the legend or symbology of an image, along with the image, on a map? I have an ArcGIS runtime program written in C#, which generates a series of rasters, and displays them on a map using the following code snippit . . .

private void AddRasterLayer(string rasterPath, string id, bool isVisible, double[,] rasterArray)

{

var newRaster = new Raster(rasterPath); // create the raster object from the image file var newRasterLayer = new RasterLayer(newRaster); // create the raster layer object from the raster

newRasterLayer.Id = id;

if (id == "DEMMosaic")// if the image is the DEM

{

   double max = SoilMoisturePreprocessing.Max2d(rasterArray); // get the maximum value in the array

   double min = SoilMoisturePreprocessing.Min2d(rasterArray); // get the minimum value in the array

   double[] minVals = { min }; // minimum value for stretch parameters input

   double[] maxVals = { max }; // maximum value for stretch parameters input MinMaxStretchParameters

   minMaxParams = new MinMaxStretchParameters(minVals, maxVals); // create stretch parameters object ColorRamp    elevationColorRamp = ColorRamp.Create(PresetColorRampType.Elevation); // create the color ramp

   var rendrr = new StretchRenderer(minMaxParams, null, true, elevationColorRamp); // create the renderer 

   newRasterLayer.Renderer = rendrr; // apply the renderer to the raster layer

}

newRasterLayer.Opacity = 0.6; // set the opacity

newRasterLayer.IsVisible = isVisible; // visibility setting var mapViewModel = ServiceLocator.Current.GetInstance<MapViewModel>(); // get the map view model mapViewModel.Map.OperationalLayers.Add(newRasterLayer); // add the raster layer to the map

}

 

Is there a way that I could incorporate into the above code, a method that would display a legend for the raster along with the raster?

Outcomes