private async void getWFS_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                featuresLayer.ClearFeatures();
                GetWFSCapabilities getCapabilities = new GetWFSCapabilities(url);
                List<WFSFeatureType> featureTypes = await getCapabilities.ProcessAsync();

                if (featureTypes.Count > 9)
                {
                    GetWFSDescribeFeatureType featureType = new GetWFSDescribeFeatureType(url);
                    var featureInfo=featureTypes.Where(c=>c.Title=="Capitals").FirstOrDefault();
                    featureType.TypeNames.Add(featureInfo.TypeName);
                    Dictionary<string, List<WFSFeatureDescription>> dicFeatureDesp = await featureType.ProcessAsync();

                    SuperMap.WinRT.Core.PredefinedMarkerStyle markerStyle = new PredefinedMarkerStyle() { Symbol = PredefinedMarkerStyle.MarkerSymbol.Star,Size=15};
                   
                    foreach (var item in dicFeatureDesp)
                    {
                        if (item.Key == "http://www.supermap.com/World")
                        {
                            GetWFSFeature getWFSFeature = new GetWFSFeature(url)
                            {
                                MaxFeatures = 30,
                                FeatureNS = item.Key
                            };
                            WFSFeatureDescription typeCountries = new WFSFeatureDescription
                            {
                                TypeName = item.Value[0].TypeName,
                                SpatialProperty = item.Value[0].SpatialProperty,
                            };
                            typeCountries.Properties.Add(item.Value[0].Properties[0]);
                            typeCountries.Properties.Add(item.Value[0].Properties[1]);
                            getWFSFeature.FeatureDescriptions.Add(typeCountries);
                            GetWFSFeatureResult featureRes = await getWFSFeature.ProcessAsync();

                            foreach (var key in featureRes.FeaturePair)
                            {
                                featuresLayer.AddFeatureSet(key.Value, markerStyle);
                                foreach (Feature feature in key.Value)
                                {
                                    feature.ToolTip = new TextBlock
                                    {
                                        Text = "坐标:"+ "\n" + "X: " + feature.Attributes["SMX"] + "\n" + "Y: " + feature.Attributes["SMY"],
                                        Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Colors.Black),
                                        FontSize = 16
                                    };
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        internal List<string> GetFullPropertyName(WFSFeatureDescription layer)
        {
            List<string> newList = new List<string>();
            if (layer.Properties != null && layer.Properties.Count > 0)
            {
                //foreach (string item in layer.Properties)
                //{
                //    newList.Add(layer.TypeName + "/" + item);
                //}
                ////空间数据的属性
                //newList.Add(layer.TypeName + "/" + layer.SpatialProperty);
                foreach (string item in layer.Properties)
                {
                    newList.Add(item);
                }
                //空间数据的属性
                newList.Add(layer.SpatialProperty);
            }
            else
            {

            }

            return newList;
        }
        private Dictionary<string, List<WFSFeatureDescription>> ParseImportResult(XDocument doc, string targetNS)
        {
            List<WFSFeatureDescription> types = new List<WFSFeatureDescription>();
            Dictionary<string, List<WFSFeatureDescription>> typesDic = new Dictionary<string, List<WFSFeatureDescription>>();
            string namesp = doc.Root.Name.NamespaceName;

            foreach (var ele in doc.Root.Elements(XName.Get("element", namesp)))
            {
                string type = string.Empty;
                string typeValue = string.Empty;
                XAttribute eleNameAttribute = ele.Attribute("name");
                XAttribute eleTypeAttribute = ele.Attribute("type");
                if (eleNameAttribute == null || eleTypeAttribute == null)
                {
                    continue;
                }

                if (this.TypeNames == null || (this.TypeNames != null && this.TypeNames.Count <= 0))
                {
                    GetHeaderName(eleNameAttribute.Value, eleTypeAttribute.Value, out type, out typeValue);
                    nameDic.Add(type, typeValue);
                }
                else
                {
                    foreach (var item in this.TypeNames)
                    {
                        if (!string.IsNullOrEmpty(eleNameAttribute.Value) && (eleNameAttribute.Value == GetSimpleName(item)))
                        {
                            nameDic.Add(item, eleTypeAttribute.Value);
                        }
                    }
                }
            }

            IEnumerable<XElement> coplexTypes = doc.Root.Elements(XName.Get("complexType", namesp));
            foreach (var type in coplexTypes)
            {
                WFSFeatureDescription typeObject = new WFSFeatureDescription();
                foreach (var namepair in nameDic)
                {
                    XAttribute typeNameAttribute = type.Attribute(XName.Get("name"));
                    if (typeNameAttribute != null && GetSimpleName(namepair.Value) == typeNameAttribute.Value)
                    {
                        typeObject.TypeName = namepair.Key;
                    }
                }

                if (string.IsNullOrEmpty(typeObject.TypeName))
                {
                    continue;
                }
                foreach (var element in type.Descendants(XName.Get("element", namesp)))
                {
                    XAttribute nameAttribute = element.Attribute(XName.Get("name"));
                    XAttribute typeAttribute = element.Attribute(XName.Get("type"));
                    if (nameAttribute != null)
                    {
                        if (typeAttribute != null && !string.IsNullOrEmpty(typeAttribute.Value) && typeAttribute.Value.Contains("gml:"))
                        {
                            typeObject.SpatialProperty = nameAttribute.Value;
                        }
                        else
                        {
                            typeObject.Properties.Add(nameAttribute.Value);
                        }
                    }
                }

                types.Add(typeObject);
            }

            typesDic.Add(targetNS, types);
            return typesDic;
        }