Ejemplo n.º 1
0
        public override byte[] GetTile(Capabilities capabilities, string path, GetTile getTile)
        {
            byte[] buffer = null;
            if (capabilities == null || string.IsNullOrWhiteSpace(path) || getTile == null)
            {
                return(buffer);
            }
            IMapLayer mapLayer = DataHelper.GetMapLayer(path);

            if (mapLayer != null)
            {
                LayerType layerType = capabilities.Contents?.DatasetDescriptionSummary?.FirstOrDefault(x => x.Identifier?.Value == getTile.Layer && x is LayerType) as LayerType;
                if (layerType != null)
                {
                    BoundingBoxType boundingBoxType       = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null;
                    string          layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet;
                    TileMatrixSet   layerTileMatrixSet    = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr);
                    TileMatrix      layerTileMatrix       = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix);

                    if (layerTileMatrix != null)
                    {
                        bool ret = WmtsHelper.ComputeTileBoundary(layerType, layerTileMatrix, getTile.TileCol, getTile.TileRow, out double tileXMin, out double tileYMin, out double tileXMax, out double tileYMax);
                        if (ret)
                        {
                            Extent    extent     = new Extent(tileXMin, tileYMin, tileXMax, tileYMax);
                            int       tileWidth  = Convert.ToInt32(layerTileMatrix.TileWidth);
                            int       tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight);
                            Rectangle rectangle  = new Rectangle(0, 0, tileWidth, tileHeight);
                            using (Bitmap bmp = GetBitmap(mapLayer, extent, rectangle))
                            {
                                ImageFormat imageFormat = null;
                                if (string.IsNullOrWhiteSpace(getTile.Format) || !getTile.Format.Contains('/'))
                                {
                                    imageFormat = ImageFormat.Png;
                                }
                                else
                                {
                                    string[] formatMimeArray = getTile.Format.Split('/');
                                    switch (formatMimeArray[1])
                                    {
                                    case "jpg":
                                        imageFormat = ImageFormat.Jpeg;
                                        break;

                                    default:
                                        imageFormat = ImageFormat.Png;
                                        break;
                                    }
                                }
                                buffer = GetBitmapBuffer(bmp, imageFormat);
                            }
                        }
                    }
                }
                mapLayer.Dispose();
            }
            return(buffer);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void DeleteMapLayer(int id)
        {
            IMapLayer layer = this.GetMapLayer(id);

            if (layer == null)
            {
                return;
            }

            layer.Dispose();
            this._layers.Remove(layer);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public void DeleteMapLayer(int id)
        {
            IMapLayer layer = this.GetMapLayer(id);

            if (layer == null)
            {
                return;
            }

            this._layerLock.EnterWriteLock();

            try
            {
                layer.Dispose();
                this._layers.Remove(layer);
            }
            finally
            {
                this._layerLock.ExitWriteLock();
            }
        }