Example #1
0
        /// <summary>
        /// Creates and initializes an instance of MapRectangleByTile.
        /// </summary>
        /// <param name="x">X-coordinate of the tile</param>
        /// <param name="y">Y-coordinate of the tile</param>
        /// <param name="z">Z-coordinate of the tile</param>
        public TileMapRectangle(int x, int y, int z)
        {
            var rect = ReprojectionProvider.TileToSphereMercator(X = x, Y = y, Z = z, 6371000);

            West  = Math.Min(rect.Left, rect.Right);
            East  = Math.Max(rect.Left, rect.Right);
            North = Math.Max(rect.Top, rect.Bottom);
            South = Math.Min(rect.Top, rect.Bottom);
        }
        /// <inheritdoc/>
        public Stream GetImageStream(int x, int y, int zoom)
        {
            // get tile bounds in mercator units
            var rect    = ReprojectionProvider.TileToSphereMercator(x, y, zoom, 6371000);
            var mapRect = new Tools.Reprojection.MapRectangle(rect.Left, rect.Bottom, rect.Right, rect.Top);

            // Request the map tile from the ReprojectionService. The returned image stream may be
            // null, e.g. when the requested tile is out of bounds regarding the inner MapServer configuration.
            // In that case return a default  tile preventing the map from displaying enlarged images from other
            // zoom levels (> avoids "zoom artifacts").
            return((ReprojectionService.GetImageStream(mapRect, new Size(256, 256)) ?? new MemoryStream(defaultTile)).Reset());
        }
Example #3
0
        /// <summary> Creates and initializes a new layer which integrates the images provided by Web Map Services into the map control.  </summary>
        /// <param name="urlTemplate">URL needed for retrieving images from the corresponding Web Map Service. The layout of this URL must
        /// achieve the requirements according the OpenGIS Specification, details can be found in http://www.opengeospatial.org/standards/wms .
        /// <br />
        /// Because the visible region of a map control changes during a user session, and the size in pixel may vary, some parameters in the URL
        /// query string have to be parameterized. I.e. the parameters 'BBOX', 'WIDTH' and 'HEIGHT' must be used in a parameterized way: They have to
        /// look like: ..&amp;BBOX=${boundingbox}&amp;WIDTH=${width}&amp;HEIGHT=${height}.."
        /// </param>
        /// <param name="isTiled"> Indicating if a tiled variant is used for filling the map control with content, or not. </param>
        /// <param name="isBaseMap"> Indicating if the content represents a background information which completely fills the drawing area of the map control
        /// (= true), or only punctual information is shown (= false). This value influences the sequence order when the different layers are drawn. </param>
        /// <param name="name"> Name of the layer in the internal layer management. </param>
        /// <param name="copyRight">Copyright text visible in the lower right corner of the map control. </param>
        /// <param name="timeout">Longest time waiting for WMS request.</param>
        public WmsLayer(string urlTemplate, bool isTiled, bool isBaseMap, string name, string copyRight = null, int timeout = 8000)
        {
            var canvasCategories = new[] { isBaseMap?CanvasCategory.BaseMap : CanvasCategory.Content };

            ReprojectionProvider = new ReprojectionProvider(urlTemplate, timeout);
            wrappedLayer         = isTiled
                ? (ILayer) new TiledLayer(name)
            {
                TiledProvider = ReprojectionProvider, Copyright = copyRight, CanvasCategories = canvasCategories
            }
                : new UntiledLayer(name)
            {
                UntiledProvider = ReprojectionProvider, Copyright = copyRight, CanvasCategories = canvasCategories
            };

            // In LayerCollection the first parameter of PropertyChanged method is determined by class BaseLayer, which is equal to the wrapper layer.
            // But this layer wasn't inserted in the LayerCollection, so the sender has to be corrected.
            wrappedLayer.PropertyChanged += (_, e) => PropertyChanged?.Invoke(this, e);
        }