AnsweredAssumed Answered

Last layer added to the Maps operational layers constrains the viewport

Question asked by tariston on Apr 11, 2018
Latest reply on May 23, 2018 by tariston

It looks as though the last layer added to the Maps operational layers will constrain the MapViews viewport. Is this a bug or working as intended?

If it is working as intended, how would you then set the extent of your viewport programmatically?


I've added a bit of code to show what I mean:

Similar questions have been asked here and here, however, neither of those questions have any answers.


Attached is some code to show what I mean

public partial class MainWindow : Window
        public MainWindow()
            spatialReference = new SpatialReference(3395);
            smallEnvelope = new Envelope(-500, -500, 500, 500, spatialReference);
            centerEnvelope = new Envelope(-1, -1, 1, 1, spatialReference);
            largeEnvelope = new Envelope(-1000, -1000, 1000, 1000, spatialReference);
            Loaded += MainWindow_Loaded;

        private readonly SpatialReference spatialReference;
        private readonly Envelope centerEnvelope;
        private readonly Envelope smallEnvelope;
        private readonly Envelope largeEnvelope;

        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
            var leftFirst = await CreateLayer("large", largeEnvelope, SimpleMarkerSymbolStyle.Circle, Colors.Maroon);
            var leftCenter = await CreateLayer("center", centerEnvelope, SimpleMarkerSymbolStyle.X, Colors.BlueViolet);
            var leftLast = await CreateLayer("small", smallEnvelope, SimpleMarkerSymbolStyle.Cross, Colors.HotPink);
            // Set up the left map
            InitializeMapView(mv_LeftMap, new List<Layer>() { leftFirst, leftCenter, leftLast });

            // Reverse the order they're added
            var rightFirst = leftLast.Clone();
            var rightCenter = leftCenter.Clone();
            var rightLast = leftFirst.Clone();
            // Set up the right map
            InitializeMapView(mv_RightMap, new List<Layer>() { rightFirst, rightCenter, rightLast });

        private void InitializeMapView(MapView view, List<Layer> layers)
            var map = new Map()
                Basemap = new Basemap(),
                MinScale = 5000000,
                MaxScale = 0
            foreach (var layer in layers)
            view.Map = map;

        private async Task<Layer> CreateLayer(string layerName, Envelope envelope, SimpleMarkerSymbolStyle style, Color color)
            var fields = new List<Field>();
            var featureCollectionTable = new FeatureCollectionTable(fields, GeometryType.Point, envelope.SpatialReference)
                Renderer = new SimpleRenderer(new SimpleMarkerSymbol(style, color, 50))
            var topLeft = featureCollectionTable.CreateFeature();
            var topRight = featureCollectionTable.CreateFeature();
            var bottomLeft = featureCollectionTable.CreateFeature();
            var bottomRight = featureCollectionTable.CreateFeature();

            topLeft.Geometry = new MapPoint(envelope.XMin, envelope.YMax, spatialReference);
            topRight.Geometry = new MapPoint(envelope.XMax, envelope.YMax, spatialReference);
            bottomLeft.Geometry = new MapPoint(envelope.XMin, envelope.YMin, spatialReference);
            bottomRight.Geometry = new MapPoint(envelope.XMax, envelope.YMin, spatialReference);

            await featureCollectionTable.AddFeaturesAsync(new[] { topLeft, topRight, bottomLeft, bottomRight });

            var featureCollection = new FeatureCollection(new[] { featureCollectionTable });
            var featureCollectionLayer = new FeatureCollectionLayer(featureCollection);
            return featureCollectionLayer;


            <RowDefinition />
            <RowDefinition Height="Auto" />
            <ColumnDefinition />
            <ColumnDefinition />
        <esri:MapView x:Name="mv_LeftMap"
                      Grid.Column="0" />

        <esri:MapView x:Name="mv_RightMap"
                      Grid.Column="1" />

        <TextBlock Text="Larger viewport"
                   Grid.Row="1" />

        <TextBlock Text="Smaller viewport"
                   Grid.Column="1" />