コード例 #1
0
        public void CopyToAfterRemovingItem()
        {
            // arrange
            var layerCollection = new LayerCollection();
            var layer1          = new MemoryLayer();
            var layer2          = new MemoryLayer();

            layerCollection.Add(layer1);
            layerCollection.Add(layer2);

            var size  = layerCollection.Count();
            var array = new ILayer[size];

            layerCollection.Remove(layer1);

            // act
            layerCollection.CopyTo(array, 0);

            // assert
            Assert.AreEqual(2, array.Length);
            Assert.NotNull(array[0], "first element not null");
            // We have no crash but the seconds element is null.
            // This might have unpleasant consequences.
            Assert.Null(array[1], "second element IS null");
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: cugkgq/Project
        /// <summary>
        /// Renders the map using the provided <see cref="Graphics"/> object.
        /// </summary>
        /// <param name="g">the <see cref="Graphics"/> object to use</param>
        /// <param name="layerCollectionType">the <see cref="LayerCollectionType"/> to use</param>
        /// <exception cref="ArgumentNullException">if <see cref="Graphics"/> object is null.</exception>
        /// <exception cref="InvalidOperationException">if there are no layers to render.</exception>
        public void RenderMap(Graphics g, LayerCollectionType layerCollectionType)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g", "Cannot render map with null graphics object!");
            }

            VariableLayerCollection.Pause = true;

            LayerCollection lc = null;

            switch (layerCollectionType)
            {
            case LayerCollectionType.Static:
                lc = Layers;
                break;

            case LayerCollectionType.Variable:
                lc = VariableLayers;
                break;

            case LayerCollectionType.Background:
                lc = BackgroundLayer;
                break;
            }

            if (lc == null || lc.Count == 0)
            {
                throw new InvalidOperationException("No layers to render");
            }

            Matrix transform = g.Transform;

            g.Transform = MapTransform;
            g.Clear(BackColor);
            g.PageUnit = GraphicsUnit.Pixel;


            //int srid = (Layers.Count > 0 ? Layers[0].SRID : -1); //Get the SRID of the first layer
            ILayer[] layerList = new ILayer[lc.Count];
            lc.CopyTo(layerList, 0);

            //int srid = (Layers.Count > 0 ? Layers[0].SRID : -1); //Get the SRID of the first layer
            foreach (ILayer layer in layerList)
            {
                if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                {
                    layer.Render(g, this);
                }
            }

            g.Transform = transform;
            if (layerCollectionType == LayerCollectionType.Static)
            {
                RenderDisclaimer(g);
            }

            VariableLayerCollection.Pause = false;
        }
コード例 #3
0
        public void CopyToWithNormalConditions()
        {
            // arrange
            var layerCollection = new LayerCollection();
            var layer1          = new MemoryLayer();
            var layer2          = new MemoryLayer();

            layerCollection.Add(layer1);
            layerCollection.Add(layer2);

            var size  = layerCollection.Count();
            var array = new ILayer[size];

            // act
            layerCollection.CopyTo(array, 0);

            // assert
            Assert.AreEqual(2, array.Length);
            Assert.NotNull(array[0]);
            Assert.NotNull(array[1]);
        }
コード例 #4
0
ファイル: Map.cs プロジェクト: cugkgq/Project
        /// <summary>
        /// Renders the map using the provided <see cref="Graphics"/> object.
        /// </summary>
        /// <param name="g">the <see cref="Graphics"/> object to use</param>
        /// <param name="layerCollectionType">the <see cref="LayerCollectionType"/> to use</param>
        /// <param name="drawMapDecorations">Set whether to draw map decorations on the map (if such are set)</param>
        /// <param name="drawTransparent">Set wether to draw with transparent background or with BackColor as background</param>
        /// <exception cref="ArgumentNullException">if <see cref="Graphics"/> object is null.</exception>
        /// <exception cref="InvalidOperationException">if there are no layers to render.</exception>
        public void RenderMap(Graphics g, LayerCollectionType layerCollectionType, bool drawMapDecorations, bool drawTransparent)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g", "Cannot render map with null graphics object!");
            }

            VariableLayerCollection.Pause = true;

            LayerCollection lc = null;

            switch (layerCollectionType)
            {
            case LayerCollectionType.Static:
                lc = Layers;
                break;

            case LayerCollectionType.Variable:
                lc = VariableLayers;
                break;

            case LayerCollectionType.Background:
                lc = BackgroundLayer;
                break;
            }

            if (lc == null || lc.Count == 0)
            {
                throw new InvalidOperationException("No layers to render");
            }

            Matrix transform = g.Transform;

            lock (MapTransform)
            {
                g.Transform = MapTransform.Clone();
            }
            if (!drawTransparent)
            {
                g.Clear(BackColor);
            }

            g.PageUnit = GraphicsUnit.Pixel;


            ILayer[] layerList = new ILayer[lc.Count];
            lc.CopyTo(layerList, 0);

            foreach (ILayer layer in layerList)
            {
                if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                {
                    layer.Render(g, this);
                }
            }

            if (drawTransparent)
            {
                g.Transform = transform;
            }
            if (layerCollectionType == LayerCollectionType.Static)
            {
#pragma warning disable 612,618
                RenderDisclaimer(g);
#pragma warning restore 612,618
                if (drawMapDecorations)
                {
                    foreach (var mapDecoration in Decorations)
                    {
                        mapDecoration.Render(g, this);
                    }
                }
            }



            VariableLayerCollection.Pause = false;
        }
コード例 #5
0
ファイル: Map.cs プロジェクト: cugkgq/Project
        /// <summary>
        /// Renders the map using the provided <see cref="Graphics"/> object.
        /// </summary>
        /// <param name="g">the <see cref="Graphics"/> object to use</param>
        /// <exception cref="ArgumentNullException">if <see cref="Graphics"/> object is null.</exception>
        /// <exception cref="InvalidOperationException">if there are no layers to render.</exception>
        public void RenderMap(Graphics g)
        {
            OnMapRendering(g);

            if (g == null)
            {
                throw new ArgumentNullException("g", "Cannot render map with null graphics object!");
            }

            //Pauses the timer for VariableLayer
            VariableLayerCollection.Pause = true;

            if ((Layers == null || Layers.Count == 0) && (BackgroundLayer == null || BackgroundLayer.Count == 0) && (_variableLayers == null || _variableLayers.Count == 0))
            {
                throw new InvalidOperationException("No layers to render");
            }

            lock (MapTransform)
            {
                g.Transform = MapTransform.Clone();
            }
            g.Clear(BackColor);
            g.PageUnit = GraphicsUnit.Pixel;


            //int srid = (Layers.Count > 0 ? Layers[0].SRID : -1); //Get the SRID of the first layer
            ILayer[] layerList;
            if (_backgroundLayers != null && _backgroundLayers.Count > 0)
            {
                layerList = new ILayer[_backgroundLayers.Count];
                _backgroundLayers.CopyTo(layerList, 0);
                foreach (ILayer layer in layerList)
                {
                    OnLayerRendering(layer, LayerCollectionType.Background);
                    if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                    {
                        layer.Render(g, this);
                    }
                    OnLayerRendered(layer, LayerCollectionType.Background);
                }
            }

            if (_layers != null && _layers.Count > 0)
            {
                layerList = new ILayer[_layers.Count];
                _layers.CopyTo(layerList, 0);

                //int srid = (Layers.Count > 0 ? Layers[0].SRID : -1); //Get the SRID of the first layer
                foreach (ILayer layer in layerList)
                {
                    OnLayerRendering(layer, LayerCollectionType.Static);
                    if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                    {
                        layer.Render(g, this);
                    }
                    OnLayerRendered(layer, LayerCollectionType.Static);
                }
            }

            if (_variableLayers != null && _variableLayers.Count > 0)
            {
                layerList = new ILayer[_variableLayers.Count];
                _variableLayers.CopyTo(layerList, 0);
                foreach (ILayer layer in layerList)
                {
                    if (layer.Enabled && layer.MaxVisible >= Zoom && layer.MinVisible < Zoom)
                    {
                        layer.Render(g, this);
                    }
                }
            }

#pragma warning disable 612,618
            RenderDisclaimer(g);
#pragma warning restore 612,618

            // Render all map decorations
            foreach (var mapDecoration in _decorations)
            {
                mapDecoration.Render(g, this);
            }
            //Resets the timer for VariableLayer
            VariableLayerCollection.Pause = false;

            OnMapRendered(g);
        }