${REST_ThemeUnique_Title}

${REST_ThemeUnique_Description}

Наследование: Theme
Пример #1
0
        private static string GetThemeInfoJson(ThemeUnique themeUnique)
        {
            if (themeUnique == null)
            {
                return null;
            }

            string themeInfoJson = "{";
            List<string> themeInfoJsonList = new List<string>();

            if (themeUnique.Items != null && themeUnique.Items.Count > 0)
            {
                themeInfoJsonList.Add(string.Format("\"items\":[{0}]", GetThemeItemsJson(themeUnique.Items)));
            }
            else
            {
                themeInfoJsonList.Add("\"items\":[]");
            }

            if (!string.IsNullOrEmpty(themeUnique.UniqueExpression))
            {
                themeInfoJsonList.Add(string.Format("\"uniqueExpression\":\"{0}\"", themeUnique.UniqueExpression));
            }
            else
            {
                themeInfoJsonList.Add("\"uniqueExpression\":\"\"");
            }

            themeInfoJsonList.Add(string.Format("\"colorGradientType\":\"{0}\"", themeUnique.ColorGradientType.ToString()));

            if (themeUnique.DefaultStyle != null)
            {
                themeInfoJsonList.Add(string.Format("\"defaultStyle\":{0}", ServerStyle.ToJson(themeUnique.DefaultStyle)));
            }
            else
            {
                themeInfoJsonList.Add(string.Format("\"defaultStyle\":{0}", ServerStyle.ToJson(new ServerStyle())));
            }
            //添加专题图请求体必须的但不开放给用户的字段
            themeInfoJsonList.Add("\"type\":\"UNIQUE\"");
            if (themeUnique.MemoryData != null)
            {
                themeInfoJsonList.Add("\"memoryData\":" + themeUnique.ToJson(themeUnique.MemoryData));
            }
            else
            {
                themeInfoJsonList.Add("\"memoryData\":null");
            }
            themeInfoJson += string.Join(",", themeInfoJsonList.ToArray());
            themeInfoJson += "}";
            return themeInfoJson;
        }
Пример #2
0
 internal static string ToJson(ThemeUnique themeUnique)
 {
     string json = GetThemeInfoJson(themeUnique);
     return json;
 }
        private async void commit_Click(object sender, RoutedEventArgs e)
        {
            //专题图子项数组
            List<ThemeUniqueItem> items = new List<ThemeUniqueItem> 
            {
                //专题图子项
                 new ThemeUniqueItem
                 {
                     //SmID字段值
                     Unique="1", 
                     Style=new ServerStyle
                     {
                         FillForeColor = new Color {R=1,G=128,B=171},
                         LineWidth = 0.1                       
                     },
                     Visible=true,
                 },
                 new ThemeUniqueItem
                 {
                     //SmID字段值
                     Unique="247",
                     Style=new ServerStyle
                     {
                         FillForeColor= new Color {R=192,G=214,B=54},
                         LineWidth = 0.1
                     },
                     Visible=true,
                 }
            };
            //设置其他 SmID 字段显示风格
            ThemeUnique themeUnique = new ThemeUnique
            {
                Items = items,
                UniqueExpression = "SmID",
                DefaultStyle = new ServerStyle
                {
                    FillOpaqueRate = 100,
                    FillForeColor = new Color { R = 250, G = 237, B = 195 },
                    LineWidth = 0.1,
                    FillBackOpaque = true,
                    FillBackColor = Colors.Transparent
                }
            };

            ThemeDotDensity themeDotDensity = new ThemeDotDensity
            {
                //专题图中每一个点所代表的数值
                Value = 10000000,
                //1994年人口字段
                DotExpression = "Pop_1994",
                Style = new ServerStyle
                {
                    //设置点符号
                    MarkerSize = 2,
                    MarkerSymbolID = 1,
                    FillForeColor = Color.FromArgb(255, 0, 180, 150),
                }
            };
            //专题图参数设置
            ThemeParameters compostionThemeParameters = new ThemeParameters
            {
                DatasetName = "Countries",
                DataSourceName = "World",
                Themes = new List<Theme> { themeDotDensity, themeUnique }
            };
            // //与服务器交互成功
            try
            {
                ThemeService compositeService = new ThemeService(url);
                var result =  await compositeService.ProcessAsync(compostionThemeParameters);
                //显示专题图。专题图在服务端为一个资源,每个资源都有一个 ID 号和一个 url
                //要显示专题图即将资源结果的 ID 号赋值给图层的 layersID 属性即可
               
                themeLayer.LayersID = result.ResourceInfo.NewResourceID;
                if (!this.MyMap.Layers.Contains(themeLayer))
                {
                    //加载专题图图层
                    this.MyMap.Layers.Add(themeLayer);
                }
                if (!themeLayer.IsVisible)
                {
                    themeLayer.IsVisible = true;
                }
            }
            //与服务器交互失败
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            } 
        }
Пример #4
0
        internal static ThemeUnique FromJson(JsonObject json)
        {
            if (json == null) { return null; }
            ThemeUnique themeUnique = new ThemeUnique();

            if (json["defaultStyle"].ValueType != JsonValueType.Null)
            {
                themeUnique.DefaultStyle = ServerStyle.FromJson(json["defaultStyle"].GetObjectEx());
            }

            if (json["colorGradientType"].ValueType!= JsonValueType.Null)
            {
                themeUnique.ColorGradientType = (ColorGradientType)Enum.Parse(typeof(ColorGradientType), json["colorGradientType"].GetStringEx(), true);
            }
            else
            {
                //这里不处理为空时的情况
            }
            List<ThemeUniqueItem> items = new List<ThemeUniqueItem>();
            if (json["items"].ValueType != JsonValueType.Null && json["items"].GetArray().Count > 0)
            {
                for (int i = 0; i < json["items"].GetArray().Count; i++)
                {
                    items.Add(ThemeUniqueItem.FromJson((JsonValue)json["items"].GetArray()[i]));
                }
            }
            themeUnique.Items = items;
            themeUnique.UniqueExpression = json["uniqueExpression"].GetStringEx();
            return themeUnique;
        }
        //点击生成专题图触发事件
        private async void commit_Click(object sender, RoutedEventArgs e)
        {
            //专题图子项数组
            List<ThemeUniqueItem> items = new List<ThemeUniqueItem>
            {
                //专题图子项
                new ThemeUniqueItem
                {
                    Unique = "城市",
                    Visible = true,
                    Style = new ServerStyle 
                    {
                        FillForeColor = new Color {R=157,G=127,B=255},
                        LineWidth = 0.05   
                    }
                },

                new ThemeUniqueItem
                {
                    Unique = "旱地",
                    Visible = true,
                    Style = new ServerStyle 
                    {
                        FillForeColor = new Color {R=250,G=237,B=195},
                        LineWidth = 0.05
                    }
                },

                new ThemeUniqueItem
                {
                    Unique="水浇地",
                    Visible=true,
                    Style=new ServerStyle 
                    {
                        FillForeColor = new Color {R=59,G=188,B=230},
                        LineWidth = 0.05
                    }
                },

                new ThemeUniqueItem
                {
                    Unique = "湖泊水库",
                    Visible = true,
                    Style = new ServerStyle 
                    {
                        FillForeColor = new Color {R=1,G=128,B=171},
                        LineWidth = 0.05
                    }
                },

                new ThemeUniqueItem
                {
                    Unique = "水田",
                    Visible = true ,
                    Style = new ServerStyle 
                    {
                       FillForeColor = new Color {R=167,G=219,B=232},
                       LineWidth = 0.05
                    }
                },

                new ThemeUniqueItem
                {
                    Unique = "草地",
                    Visible = true,
                    Style = new ServerStyle 
                    {
                        FillForeColor = new Color {R=192,G=214,B=54},
                        LineWidth = 0.05
                    }
                },
            };
            //设置其他土地利用类型显示风格
            ThemeUnique themeUnique = new ThemeUnique
            {
                Items = items,
                UniqueExpression = "LandType",
                DefaultStyle = new ServerStyle
                {
                    FillOpaqueRate = 100,
                    FillForeColor = new Color
                    {
                        R = 80,
                        G = 130,
                        B = 255
                    },
                    FillBackOpaque = true,
                    LineWidth = 0.05,

                }
            };
            //专题图参数对象
            ThemeParameters themeUniqueParameters = new ThemeParameters
            {
                Themes = new List<Theme> { themeUnique },
                //数据集名称
                DatasetName = "Landuse_R",
                //数据源名称
                DataSourceName = "Jingjin"
            };

            //与服务器交互
            try
            {
                ThemeService themeUniqueService = new ThemeService(url);
                var result = await themeUniqueService.ProcessAsync(themeUniqueParameters);

                //显示专题图。专题图在服务端为一个资源,每个资源都有一个 ID 号和一个 url
                //要显示专题图即将资源结果的 ID 号赋值给图层的 layersID 属性即可
                themeLayer.LayersID = result.ResourceInfo.NewResourceID;
                if (!this.MyMap.Layers.Contains(themeLayer))
                {
                    //加载专题图图层
                    this.MyMap.Layers.Add(themeLayer);
                }
                if (!themeLayer.IsVisible)
                {
                    themeLayer.IsVisible = true;
                }

            }
            //交互失败
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }