private void wmtsManager_ProcessComplated(GetWMTSCapabilitiesResult e) { Rectangle2D bbox; double[] resolutions; WMTSManagerResult result = e as WMTSManagerResult; if (result != null) { if (result != null && result.MatrixSetInfo != null && result.MatrixSetInfo.TileMatrixs != null && result.MatrixSetInfo.TileMatrixs.Count > 0) { tileMatrixs = result.MatrixSetInfo.TileMatrixs.ToArray(); //已经定义了WellKnownScaleSet值:GlobalCRS84Scale if ((!string.IsNullOrEmpty(result.MatrixSetInfo.WellKnownScaleSet) && (result.MatrixSetInfo.WellKnownScaleSet == "GlobalCRS84Scale" || result.MatrixSetInfo.WellKnownScaleSet.Contains("GlobalCRS84Scale"))) || (!string.IsNullOrEmpty(this.WellKnownScaleSet) && (this.WellKnownScaleSet == "GlobalCRS84Scale" || this.WellKnownScaleSet.Contains("GlobalCRS84Scale")))) { bbox = new Core.Rectangle2D(-180, -90, 180, 90); resolutions = preDefResScale; } //已经定义了WellKnownScaleSet值:GlobalCRS84Pixel else if ((!string.IsNullOrEmpty(result.MatrixSetInfo.WellKnownScaleSet) && (result.MatrixSetInfo.WellKnownScaleSet == "GlobalCRS84Pixel" || result.MatrixSetInfo.WellKnownScaleSet.Contains("GlobalCRS84Pixel"))) || (!string.IsNullOrEmpty(this.WellKnownScaleSet) && (this.WellKnownScaleSet == "GlobalCRS84Pixel" || this.WellKnownScaleSet.Contains("GlobalCRS84Pixel")))) { bbox = new Core.Rectangle2D(-180, -90, 180, 90); resolutions = preDefResPixel; } //已经定义了WellKnownScaleSet值:GoogleCRS84Quad else if ((!string.IsNullOrEmpty(result.MatrixSetInfo.WellKnownScaleSet) && (result.MatrixSetInfo.WellKnownScaleSet == "GoogleCRS84Quad" || result.MatrixSetInfo.WellKnownScaleSet.Contains("GoogleCRS84Quad"))) || (!string.IsNullOrEmpty(this.WellKnownScaleSet) && (this.WellKnownScaleSet == "GoogleCRS84Quad" || this.WellKnownScaleSet.Contains("GoogleCRS84Quad")))) { bbox = new Core.Rectangle2D(-180, -90, 180, 90); resolutions = preDefGoogleCRS84Quad; } //已经定义了WellKnownScaleSet值:GoogleMapsCompatible else if ((!string.IsNullOrEmpty(result.MatrixSetInfo.WellKnownScaleSet) && (result.MatrixSetInfo.WellKnownScaleSet == "GoogleMapsCompatible" || result.MatrixSetInfo.WellKnownScaleSet.Contains("GoogleMapsCompatible"))) || (!string.IsNullOrEmpty(this.WellKnownScaleSet) && (this.WellKnownScaleSet == "GoogleMapsCompatible" || this.WellKnownScaleSet.Contains("GoogleMapsCompatible")))) { bbox = new Core.Rectangle2D(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892); resolutions = preDefGoogleMapsCompatible; } //已经定义了WellKnownScaleSet值:custom else if (((!string.IsNullOrEmpty(result.MatrixSetInfo.WellKnownScaleSet) && result.MatrixSetInfo.WellKnownScaleSet == "custom") || (!string.IsNullOrEmpty(this.WellKnownScaleSet) && this.WellKnownScaleSet == "custom"))) { bbox = new Core.Rectangle2D(-180, -90, 180, 90); resolutions = preDefResChina; } //若WellKnownScaleSet为空或者其他非法值,则默认使用GlobalCRS84Scale else { bbox = new Core.Rectangle2D(-180, -90, 180, 90); resolutions = preDefResScale; } GetTileUrl(); //若用户未定义Bounds值,则使用默认Bounds if (Rectangle2D.IsNullOrEmpty(this.Bounds)) { this.Bounds = bbox; } //若用户未定义Resolutions值,则使用默认resolutions if (this.Resolutions == null) { //如果tileMatrixs的长度与预定义的resolutions的长度不同,则返回 if (tileMatrixs.Length != resolutions.Length) return; this.Resolutions = resolutions; } this.CRS = result.MatrixSetInfo.SupportedCRS; } } base.Initialize(); }
/// <summary>${mapping_GetWMTSCapabilities_method_ParseCapabilities_D}</summary> public virtual GetWMTSCapabilitiesResult ParseCapabilities(XDocument document) { GetWMTSCapabilitiesResult result = new GetWMTSCapabilitiesResult(); if (document != null && document.Root != null) { string nsName = document.Root.Name.NamespaceName; XNamespace ns = document.Root.Name.Namespace; XAttribute versionAttr = document.Root.Attribute("version"); if (versionAttr != null) { result.Version = versionAttr.Value; } foreach (var layer in (from xmlLayer in document.Descendants(XName.Get("Layer", nsName)) select new WMTSLayerInfo { Name = xmlLayer.Element(((XElement)xmlLayer.FirstNode).Name.Namespace + "Identifier") == null ? string.Empty : xmlLayer.Element(((XElement)xmlLayer.FirstNode).Name.Namespace + "Identifier").Value, ////哪个值是有效的?Bounds值并不是WGS84BoundingBox值 //Bounds = GetBounds(xmlLayer.Element(((XElement)xmlLayer.FirstNode).Name.Namespace + "WGS84BoundingBox")), ImageFormat = GetSupportFormats(xmlLayer.Elements(XName.Get("Format", nsName)).ToList()), Style = GetSupportStyle(xmlLayer.Elements(XName.Get("Style", nsName)).ToList()), TileMatrixSetLinks = GetSupportLinks(xmlLayer.Elements(XName.Get("TileMatrixSetLink", nsName)).ToList()) })) { result.LayerInfos.Add(layer); }; foreach (var tileMatrixSet in (from xmlTileMatrixSet in document.Root.Element(XName.Get("Contents", nsName)).Elements(XName.Get("TileMatrixSet", nsName)) select new WMTSTileMatrixSetInfo { Name = xmlTileMatrixSet.Element(((XElement)xmlTileMatrixSet.FirstNode).Name.Namespace + "Identifier") == null ? string.Empty : xmlTileMatrixSet.Element(((XElement)xmlTileMatrixSet.FirstNode).Name.Namespace + "Identifier").Value, WellKnownScaleSet = xmlTileMatrixSet.Element(XName.Get("WellKnownScaleSet", nsName)) == null ? string.Empty : xmlTileMatrixSet.Element(XName.Get("WellKnownScaleSet", nsName)).Value, SupportedCRS = GetCRS(xmlTileMatrixSet.Element(((XElement)xmlTileMatrixSet.FirstNode).Name.Namespace + "SupportedCRS")), //获取级数 TileMatrixs = (from xmlTileMatrix in xmlTileMatrixSet.Elements(XName.Get("TileMatrix", nsName)) select new TileMatrix { Name = xmlTileMatrix.Element(((XElement)xmlTileMatrix.FirstNode).Name.Namespace + "Identifier").Value, ScaleDenominator = double.Parse(xmlTileMatrix.Element(XName.Get("ScaleDenominator", nsName)).Value, CultureInfo.InvariantCulture), MatrixWidth = int.Parse(xmlTileMatrix.Element(XName.Get("MatrixWidth", nsName)).Value, CultureInfo.InvariantCulture), TileWidth = int.Parse(xmlTileMatrix.Element(XName.Get("TileWidth", nsName)).Value, CultureInfo.InvariantCulture), MatrixHeight = int.Parse(xmlTileMatrix.Element(XName.Get("MatrixHeight", nsName)).Value, CultureInfo.InvariantCulture), TileHeight = int.Parse(xmlTileMatrix.Element(XName.Get("TileHeight", nsName)).Value, CultureInfo.InvariantCulture), }).ToList(), })) { result.WMTSTileMatrixSetInfo.Add(tileMatrixSet); }; } return result; }