Ejemplo n.º 1
0
        /// <summary>
        /// Method to extract all image layers from a wmts capabilities document.
        /// </summary>
        /// <param name="capabilties">The capabilities document</param>
        /// <param name="tileSchemas">A set of</param>
        /// <returns></returns>
        private static IEnumerable <ITileSource> GetLayers(Capabilities capabilties, List <ITileSchema> tileSchemas)
        {
            var tileSources = new List <ITileSource>();

            foreach (var layer in capabilties.Contents.Layers)
            {
                var    identifier = layer.Identifier.Value;
                var    title      = layer.Title[0].Value;
                string @abstract  = layer.Abstract != null ? layer.Abstract[0].Value : string.Empty;

                foreach (var tileMatrixLink in layer.TileMatrixSetLink)
                {
                    foreach (var style in layer.Style)
                    {
                        foreach (var format in layer.Format)
                        {
                            if (!format.StartsWith("image/"))
                            {
                                continue;
                            }

                            IRequest wmtsRequest;

                            if (layer.ResourceURL == null)
                            {
                                wmtsRequest = new WmtsRequest(CreateResourceUrlsFromOperations(
                                                                  capabilties.OperationsMetadata.Operation,
                                                                  format,
                                                                  capabilties.ServiceIdentification.ServiceTypeVersion.First(),
                                                                  layer.Identifier.Value,
                                                                  style.Identifier.Value,
                                                                  tileMatrixLink.TileMatrixSet));
                            }
                            else
                            {
                                wmtsRequest = new WmtsRequest(CreateResourceUrlsFromResourceUrlNode(
                                                                  layer.ResourceURL,
                                                                  style.Identifier.Value,
                                                                  tileMatrixLink.TileMatrixSet));
                            }

                            var tileMatrixSet = tileMatrixLink.TileMatrixSet;
                            var tileSchema    = (WmtsTileSchema)tileSchemas.First(s => Equals(s.Name, tileMatrixSet));

                            //var layerName = layer.Identifier.Value;
                            var styleName = style.Identifier.Value;

                            var tileSource = new TileSource(new HttpTileProvider(wmtsRequest),
                                                            tileSchema.CreateSpecific(title, identifier, @abstract, tileMatrixSet, styleName, format))
                            {
                                Name = title
                            };

                            tileSources.Add(tileSource);
                        }
                    }
                }
            }
            return(tileSources);
        }
Ejemplo n.º 2
0
        private static IEnumerable <ITileSource> GetLayers(Capabilities capabilties, List <ITileSchema> tileSchemas)
        {
            var tileSources = new List <ITileSource>();

            foreach (var layer in capabilties.Contents.Layers)
            {
                foreach (var tileMatrixLink in layer.TileMatrixSetLink)
                {
                    foreach (var style in layer.Style)
                    {
                        IRequest wmtsRequest;

                        if (layer.ResourceURL == null)
                        {
                            wmtsRequest = new WmtsRequest(CreateResourceUrlsFromOperations(
                                                              capabilties.OperationsMetadata.Operation,
                                                              layer.Format.First(),
                                                              capabilties.ServiceIdentification.ServiceTypeVersion.First(),
                                                              layer.Identifier.Value,
                                                              style.Identifier.Value,
                                                              tileMatrixLink.TileMatrixSet));
                        }
                        else
                        {
                            wmtsRequest = new WmtsRequest(CreateResourceUrlsFromResourceUrlNode(
                                                              layer.ResourceURL,
                                                              style.Identifier.Value,
                                                              tileMatrixLink.TileMatrixSet));
                        }
                        var tileSchema = tileSchemas.First(s => Equals(s.Name, tileMatrixLink.TileMatrixSet));
                        var tileSource = new TileSource(new WebTileProvider(wmtsRequest), tileSchema)
                        {
                            Title = layer.Identifier.Value
                        };

                        tileSources.Add(tileSource);
                    }
                }
            }
            return(tileSources);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to extract all image layers from a wmts capabilities document.
        /// </summary>
        /// <param name="capabilties">The capabilities document</param>
        /// <param name="tileSchemas">A set of</param>
        /// <returns></returns>
        private static IEnumerable<ITileSource> GetLayers(Capabilities capabilties, List<ITileSchema> tileSchemas)
        {
            var tileSources = new List<ITileSource>();

            foreach (var layer in capabilties.Contents.Layers)
            {
                var identifier = layer.Identifier.Value;
                var title = layer.Title[0].Value;
                string @abstract = layer.Abstract != null ? layer.Abstract[0].Value : string.Empty;

                foreach (var tileMatrixLink in layer.TileMatrixSetLink)
                {
                    foreach (var style in layer.Style)
                    {
                        foreach (var format in layer.Format)
                        {
                            if (!format.StartsWith("image/")) continue;

                            IRequest wmtsRequest;

                            if (layer.ResourceURL == null)
                            {
                                wmtsRequest = new WmtsRequest(CreateResourceUrlsFromOperations(
                                    capabilties.OperationsMetadata.Operation,
                                    format,
                                    capabilties.ServiceIdentification.ServiceTypeVersion.First(),
                                    layer.Identifier.Value,
                                    style.Identifier.Value,
                                    tileMatrixLink.TileMatrixSet));
                            }
                            else
                            {
                                wmtsRequest = new WmtsRequest(CreateResourceUrlsFromResourceUrlNode(
                                    layer.ResourceURL,
                                    style.Identifier.Value,
                                    tileMatrixLink.TileMatrixSet));
                            }

                            var tileMatrixSet = tileMatrixLink.TileMatrixSet;
                            var tileSchema = (WmtsTileSchema)tileSchemas.First(s => Equals(s.Name, tileMatrixSet));

                            //var layerName = layer.Identifier.Value;
                            var styleName = style.Identifier.Value;

                            var tileSource = new TileSource(new HttpTileProvider(wmtsRequest),
                                tileSchema.CreateSpecific(title, identifier, @abstract, tileMatrixSet, styleName, format))
                                {
                                    Name = title
                                };

                            tileSources.Add(tileSource);
                        }
                    }
                }
            }
            return tileSources;
        }
Ejemplo n.º 4
0
        public void TestWmtsRequestInParallel()
        {
            // arrange
            var resourceUrls = CreateResourceUrls();
            var request = new WmtsRequest(resourceUrls);
            var urls = new ConcurrentBag<Uri>(); // List is not thread save
            var tileInfo = new TileInfo {Index = new TileIndex(8938, 5680, "14")};

            // act
            var requests = new List<Func<Uri>>();
            for (var i = 0; i < 150; i++) requests.Add(() => request.GetUri(tileInfo));
            Parallel.ForEach(requests, r => urls.Add(r()));

            // assert
            var count = urls.Count(u => u.ToString() == "http://maps1.wien.gv.at/wmts/lb/farbe/google3857/14/5680/8938.jpeg");
            Assert.True(count == 50);
        }
Ejemplo n.º 5
0
        public void TestWmtsRequest()
        {
            // arrange
            var resourceUrls = CreateResourceUrls();
            var wmtsRequest = new WmtsRequest(resourceUrls);

            // act
            var url1 = wmtsRequest.GetUri(new TileInfo { Index = new TileIndex(8938, 5680, "14") });
            var url2 = wmtsRequest.GetUri(new TileInfo { Index = new TileIndex(8938, 5680, "14") });

            // assert
            Assert.True(url1.ToString().Equals("http://maps1.wien.gv.at/wmts/lb/farbe/google3857/14/5680/8938.jpeg"));
            Assert.True(url2.ToString().Contains("maps2"));
        }