Inheritance: Geometry
        protected override Feature OnCreateFeature(FeatureCollection cluster, GeoPoint center, int maxClusterCount)
        {
            double sum = 0;
            Feature feature = null;
            foreach (Feature item in cluster)
            {
                if (item.Attributes.ContainsKey(AggregateColumn))
                {
                    sum += Convert.ToDouble(item.Attributes[AggregateColumn]);
                }
            }
            double size = (sum + 450) / 30;
            size = Math.Log(sum * StyleScale / 10) * 10 + 20;
            if (size < 12)
            {
                size = 12;
            }
            CustomClusterStyle s = new CustomClusterStyle();
            feature = new Feature() { Style = new CustomClusterStyle() { Size = size }, Geometry = center };
            feature.Attributes.Add("Color", InterPlateColor(size - 12, 100));
            feature.Attributes.Add("Size", size);
            feature.Attributes.Add("Count", cluster.Count);

            return feature;
        }
Ejemplo n.º 2
0
 /// <summary>${utility_JsonHelper_method_FromGeoPoint_D}</summary>
 public static string FromGeoPoint(GeoPoint point)
 {
     if (point == null)
     {
         return "{}";
     }
     return string.Format(CultureInfo.InvariantCulture, "{{\"x\":{0},\"y\":{1}}}", point.X, point.Y);
 }
        public override void OnMouseMove(MouseEventArgs e)
        {
            if (isDrawing)
            {
                Point2D item = Map.ScreenToMap(e.GetPosition(Map));
                if (Math.Round(item.X, 4) == Math.Round(ps[0].X, 4) && Math.Round(item.Y, 4) == Math.Round(ps[0].Y, 4))
                {
                    return;
                }
                Point2D last = points[points.Count - 1];
                points.Remove(last);
                points.Add(item);

                //获取移动中的点
                Point2D movePoint = Map.ScreenToMap(e.GetPosition(Map));
                GeoPoint moveP = new GeoPoint(movePoint.X, movePoint.Y);

                //算出两点距离
                //double moveDistance = Math.Sqrt(Math.Abs(moveP.X - startP.X) + Math.Abs(moveP.Y - startP.Y));
                double moveDistance = Math.Sqrt((moveP.X - startP.X) * (moveP.X - startP.X) + (moveP.Y - startP.Y) * (moveP.Y - startP.Y));

                // measureMiddleResult.Text = moveDistance.ToString();
                measureMiddleResult.Text = string.Format("{0:0.0000}", moveDistance);

                Point2D middle = new Point2D((movePoint.X + startPoint.X) / 2, (movePoint.Y + startPoint.Y) / 2);

                // 清除临时TextBlocks,在这里清除能提高效率。
                tempLayer.Children.Clear();
                tempLayer.AddChild(measureMiddleResult, middle);

                sumLast = sum + moveDistance;

                // measureFinallyResult.Text = "总长度:" + s.ToString() + "km";
                measureFinallyResult.Text = "总长度:" + string.Format("{0:0.0000}", sumLast) + "km";
            }

            base.OnMouseMove(e);
        }
        public override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            startPoint = Map.ScreenToMap(e.GetPosition(Map));

            if (!isActivated)
            {
                Activate(startPoint);
            }
            else
            {
                points.Add(startPoint);
            }

            startP = new GeoPoint(startPoint.X, startPoint.Y);
            //每段分别计算
            measureMiddleResult = new TextBlock();
            measureMiddleResult.FontWeight = FontWeights.ExtraBlack;
            measureMiddleResult.Foreground = new SolidColorBrush(Colors.Green);

            textBlockContainer.Add(measureMiddleResult);

            for (int k = clickeds; k < textBlockContainer.Count; k++)
            {
                if (clickeds == 0)
                {
                    break;
                }
                if (textBlockContainer[k - 1].Text == "")
                {
                    return;
                }
                sum = sum + Convert.ToDouble(textBlockContainer[k - 1].Text);
            }

            clickeds++;

            //记录每个点
            ps.Add(startPoint);
            //第一次开始或者是双击后继续
            if (isOver || clickeds <= 1)
            {
                sum = 0;
                DrawLayer.AddChild(measureFinallyResult, startPoint);
                isOver = false;
            }

            if (DrawLayer != null && clickeds > 1)
            {
                //重新算中点坐标和距离
                Point2D middlePoints = new Point2D((startPoint.X + ps[ps.Count - 2].X) / 2, (startPoint.Y + ps[ps.Count - 2].Y) / 2);
                double middleDistance = Math.Sqrt((startPoint.X - ps[ps.Count - 2].X) * (startPoint.X - ps[ps.Count - 2].X) + (startPoint.Y - ps[ps.Count - 2].Y) * (startPoint.Y - ps[ps.Count - 2].Y));

                TextBlock tb = new TextBlock();
                tb.FontWeight = FontWeights.ExtraBlack;
                tb.Foreground = new SolidColorBrush(Colors.Green);

                tb.Text = string.Format("{0:0.0000}", middleDistance);
                DrawLayer.AddChild(tb, middlePoints);
            }

            e.Handled = true;
            base.OnMouseLeftButtonDown(e);
        }
Ejemplo n.º 5
0
 //预留接口
 private static GeoPoint ToGeoPoint(XElement xe)
 {
     GeoPoint point = new GeoPoint();
     return point;
 }
        public override void OnMouseMove(MouseEventArgs e)
        {
            if (isDrawing)
            {
                Point2D item = Map.ScreenToMap(e.GetPosition(Map));

                Point2D last = points[points.Count - 1];
                if (Math.Round(item.X, 4) == Math.Round(ps[0].X, 4) && Math.Round(item.Y, 4) == Math.Round(ps[0].Y, 4))
                {
                    return;
                }
                points.Remove(last);
                points.Add(item);

                Point2D movePoint = Map.ScreenToMap(e.GetPosition(Map));
                GeoPoint moveP = new GeoPoint(movePoint.X, movePoint.Y);
                double moveDistance = Math.Sqrt((moveP.X - startP.X) * (moveP.X - startP.X) + (moveP.Y - startP.Y) * (moveP.Y - startP.Y));
                measureMiddleResult.Text = string.Format("{0:0.0000}", moveDistance / 1000);
                Point2D middle = new Point2D((movePoint.X + startPoint.X) / 2, (movePoint.Y + startPoint.Y) / 2);

                tempLayer.Children.Clear();
                tempLayer.AddChild(measureMiddleResult, middle);

                double a = GetArea(points);
                areaTextBlock.Text = a.ToString();
                this.tempLayer.AddChild(areaTextBlock, polygon.Bounds.Center);
                //得到最后一点和第一个点之间的TextBlock
                if (points.Count > 2)
                {
                    double lastToFirst = Math.Sqrt(Math.Abs(points[points.Count - 1].X - points[0].X) * Math.Abs(points[points.Count - 1].X - points[0].X) + Math.Abs(points[points.Count - 1].Y - points[0].Y) * Math.Abs(points[points.Count - 1].Y - points[0].Y));
                    lastTextBlock.Text = string.Format("{0:0.0000}", lastToFirst / 1000);
                    Point2D lastToFirstMiddle = new Point2D((points[points.Count - 1].X + points[0].X) / 2, (points[points.Count - 1].Y + points[0].Y) / 2);
                    this.tempLayer.AddChild(lastTextBlock, lastToFirstMiddle);
                }
            }
            base.OnMouseMove(e);
        }
        public override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            startPoint = Map.ScreenToMap(e.GetPosition(Map));

            if (!isActivated)
            {
                Activate(startPoint);
            }
            else
            {
                points.Add(startPoint);
            }

            startP = new GeoPoint(startPoint.X, startPoint.Y);

            measureMiddleResult = new TextBlock();
            measureMiddleResult.FontWeight = FontWeights.ExtraBlack;
            measureMiddleResult.Foreground = new SolidColorBrush(Colors.Green);

            textBlockContainer.Add(measureMiddleResult);
            clickeds++;
            ps.Add(startPoint);

            if (DrawLayer != null && clickeds > 1)
            {
                Point2D middlePoints = new Point2D((startPoint.X + ps[ps.Count - 2].X) / 2, (startPoint.Y + ps[ps.Count - 2].Y) / 2);
                double middleDistance = Math.Sqrt((startPoint.X - ps[ps.Count - 2].X) * (startPoint.X - ps[ps.Count - 2].X) + (startPoint.Y - ps[ps.Count - 2].Y) * (startPoint.Y - ps[ps.Count - 2].Y));

                TextBlock tb = new TextBlock();
                tb.FontWeight = FontWeights.ExtraBlack;
                tb.Foreground = new SolidColorBrush(Colors.Green);

                tb.Text = string.Format("{0:0.0000}", middleDistance / 1000);
                DrawLayer.AddChild(tb, middlePoints);
            }
            e.Handled = true;
            base.OnMouseLeftButtonDown(e);
        }
 private static string convertToString(GeoPoint value)
 {
     CultureInfo invariantCulture = CultureInfo.InvariantCulture;
     string listSeparator = invariantCulture.TextInfo.ListSeparator;
     return string.Format(invariantCulture, "{0}{2}{1}", new object[] { value.X, value.Y, listSeparator });
 }
Ejemplo n.º 9
0
 //添加虚拟顶点;
 private Feature addHoverVertex(Feature feature , GeoPoint p , int index , int partIndex)
 {
     Feature hoverVertex = new Feature() { Geometry = p , Style = HoverVertexStyle };
     hoverVertex.SetZIndex(2);
     hoverLayer.Features.Add(hoverVertex);
     hoverVertex.Attributes.Add("Feature" , feature);
     hoverVertex.Attributes.Add("Index" , index);
     hoverVertex.Attributes.Add("PartIndex" , partIndex);
     hoverVertex.AddDoubleClick((s , e) => { deleteOneVertex(s as Feature); });//双击删除某个顶点,线和面。
     return hoverVertex;
 }
Ejemplo n.º 10
0
 //当线对象时,显示bounds的中心点;
 private void addCenterFeature(Feature feature)
 {
     GeoPoint center = new GeoPoint(feature.Geometry.Bounds.Center.X , feature.Geometry.Bounds.Center.Y);
     hoverCenterFeature = new Feature { Geometry = center , Style = HoverCenterStyle };
     hoverCenterFeature.SetZIndex(3);
     hoverLayer.AddFeature(hoverCenterFeature);
 }
        private static Dictionary<int, Cluster> MergeOverlappingClusters(double diameter, Dictionary<int, Cluster> orig, GeoPoint lowerLeft, out bool overlapExists, BackgroundWorker worker)
        {
            overlapExists = false;
            Dictionary<int, Cluster> dictionary = new Dictionary<int, Cluster>();
            foreach (int key in orig.Keys)
            {
                Cluster cluster = orig[key];
                if (cluster.Count != 0)
                {
                    overlapExists = SearchAndMerge(cluster, -1, -1, diameter, orig, overlapExists);
                    overlapExists = SearchAndMerge(cluster, -1, 0, diameter, orig, overlapExists);
                    overlapExists = SearchAndMerge(cluster, -1, 1, diameter, orig, overlapExists);

                    overlapExists = SearchAndMerge(cluster, 0, -1, diameter, orig, overlapExists);
                    overlapExists = SearchAndMerge(cluster, 0, 1, diameter, orig, overlapExists);

                    overlapExists = SearchAndMerge(cluster, 1, -1, diameter, orig, overlapExists);
                    overlapExists = SearchAndMerge(cluster, 1, 0, diameter, orig, overlapExists);
                    overlapExists = SearchAndMerge(cluster, 1, 1, diameter, orig, overlapExists);

                    int x = (int)Math.Round((double)((cluster.X - lowerLeft.X) / diameter));
                    int y = (int)Math.Round((double)((cluster.Y - lowerLeft.Y) / diameter));
                    cluster.Cx = x;
                    cluster.Cy = y;
                    int num4 = (x << 16) | y;
                    dictionary[num4] = cluster;
                    if (worker.CancellationPending)
                    {
                        return null;
                    }
                }
            }
            return dictionary;
        }
 private static GeoPoint GetBottomLeft(IEnumerable<Feature> features)
 {
     GeoPoint point = new GeoPoint(double.MaxValue, double.MaxValue);
     foreach (Feature f in features)
     {
         if ((f != null) && (f.Geometry != null))
         {
             GeoPoint geometry = f.Geometry as GeoPoint;
             if (geometry == null)
             {
                 geometry = new GeoPoint(f.Geometry.Bounds.Center.X, f.Geometry.Bounds.Center.Y); ;
             }
             if (!double.IsNaN(geometry.X) && !double.IsNaN(geometry.Y))
             {
                 point.X = Math.Min(point.X, geometry.X);
                 point.Y = Math.Min(point.Y, geometry.Y);
             }
         }
     }
     return point;
 }
        //遍历每一个点,把其归类,得到最终的聚类点Cluster,其所在格网index的X/Y组成Key
        private static Dictionary<int, Cluster> AssignGeoPointsToClusters(IEnumerable<Feature> features, GeoPoint bottomLeft, double diameter)
        {
            Dictionary<int, Cluster> dictionary = new Dictionary<int, Cluster>();
            GeoPoint gp = null;
            foreach (Feature feature in features)
            {
                if (feature.Geometry == null)
                {
                    continue;
                }
                if (feature.Geometry is GeoPoint)
                {
                    gp = feature.Geometry as GeoPoint;
                }
                else
                {
                    Rectangle2D bounds = feature.Geometry.Bounds;
                    if (bounds.IsEmpty)
                    {
                        continue;
                    }
                    gp = new GeoPoint(bounds.Center.X, bounds.Center.Y);
                }

                double x = gp.X;
                double y = gp.Y;
                int cx = (int)Math.Round((x - bottomLeft.X) / diameter);
                int cy = (int)Math.Round((y - bottomLeft.Y) / diameter);
                int key = (cx << 16) | cy;//int是32位的  左16位是x,右16位是y
                if (dictionary.ContainsKey(key))
                {
                    Cluster cluster = dictionary[key];
                    cluster.X = (cluster.X + x) / 2.0;
                    cluster.Y = (cluster.Y + y) / 2.0;
                    cluster.Features.Add(feature);
                }//有就合并
                else
                {
                    dictionary[key] = new Cluster(x, y, cx, cy);
                    dictionary[key].Features.Add(feature);
                }//没有就new一个
            }
            return dictionary;
        }
        private static Dictionary<int, Cluster> AssignGeoPointsToClusters(IEnumerable<Feature> features, ObservableCollection<GeoRegion> geos)
        {
            Dictionary<int, Cluster> dictionary = new Dictionary<int, Cluster>();
            GeoPoint gp = null;
            foreach (Feature feature in features)
            {
                if (feature.Geometry == null)
                {
                    continue;
                }
                gp = feature.Geometry as GeoPoint;

                if (gp == null)
                {
                    Rectangle2D bounds = feature.Geometry.Bounds;
                    if (bounds.IsEmpty)
                    {
                        continue;
                    }
                    gp = new GeoPoint(bounds.Center.X, bounds.Center.Y);
                }

                bool isContained = false;
                double x = gp.X;
                double y = gp.Y;

                foreach (GeoRegion clusterRegion in geos)
                {
                    if (clusterRegion.Bounds.Contains(x, y) && clusterRegion.Contains(x, y))
                    {
                        int key = -geos.IndexOf(clusterRegion);
                        if (dictionary.ContainsKey(key))
                        {
                            Cluster cluster = dictionary[key];
                            cluster.X += x;
                            cluster.Y += y;
                            cluster.Features.Add(feature);
                        }//有就合并
                        else
                        {
                            dictionary[key] = new Cluster(x, y);
                            dictionary[key].Features.Add(feature);
                        }//没有就new一个
                        isContained = true;
                        break;
                    }
                }
                int key1 = feature.GetHashCode();
                if (!isContained)
                {
                    if (!dictionary.ContainsKey(key1))
                    {
                        dictionary[key1] = new Cluster(gp.X, gp.Y);
                        dictionary[key1].Features.Add(feature);
                    }
                }
            }

            Cluster cltValue;
            int featuresCount = 0;
            foreach (var clt in dictionary)
            {
                cltValue = clt.Value;
                featuresCount = cltValue.Features.Count;
                clt.Value.X = cltValue.X / featuresCount;
                clt.Value.Y = cltValue.Y / featuresCount;
            }

            return dictionary;
        }
 /// <summary>${mapping_FeaturesClusterer_method_OnCreateFeature_D}</summary>
 /// <param name="cluster">${mapping_FeaturesClusterer_method_OnCreateFeature_param_cluster}</param>
 /// <param name="center">${mapping_FeaturesClusterer_method_OnCreateFeature_param_center}</param>
 /// <param name="maxClusterCount">${mapping_FeaturesClusterer_method_OnCreateFeature_param_maxClusterCount}</param>
 protected abstract Feature OnCreateFeature(FeatureCollection cluster, GeoPoint center, int maxClusterCount);
        /// <summary>${mapping_FeaturesClusterer_method_OnCreateFeature_D}</summary>
        /// <param name="cluster">${mapping_FeaturesClusterer_method_OnCreateFeature_param_cluster}</param>
        /// <param name="center">${mapping_FeaturesClusterer_method_OnCreateFeature_param_center}</param>
        /// <param name="maxClusterCount">${mapping_FeaturesClusterer_method_OnCreateFeature_param_maxClusterCount}</param>
        protected override Feature OnCreateFeature(FeatureCollection cluster, GeoPoint center, int maxClusterCount)
        {
            lastFC = cluster;
            lastCenter = center;
            lastMaxClusterCount = maxClusterCount;

            if (cluster.Count == 1)
            {
                return cluster[0];
            }
            Feature feature = null;
            double size = (Math.Log((double)(cluster.Count / 10)) * 10.0) + 20.0;//小于10个,size都是负无穷
            if (size < 12.0)
            {
                size = 12.0;
            }
            if (cluster.Count <= this.MaximumCount)
            {
                if (!this.cache.ContainsKey(cluster.Count))
                {
                    ScatterStyle style = new ScatterStyle(cluster.Count, EnableRotation)
                    {
                        ForeColor = this.Foreground,
                        FillColor = this.Background
                    };
                    this.cache.Add(cluster.Count, style);
                }//如果没有这种 样式,就创建新的样式。 根据Count决定。
                ScatterStyle style3 = this.cache[cluster.Count];
                feature = new Feature
                {
                    Geometry = center,
                    Style = style3
                };
            }
            else
            {
                feature = new ClusterFeature(size)
                {
                    Geometry = center
                };
            }//如果不达到聚合数(太多,比如大于10),则去生成新的样式
            feature.Attributes.Add("Count", cluster.Count);
            feature.Attributes.Add("Size", size);
            feature.Attributes.Add("Color", ClusterUtil.InterpolateColor((double)cluster.Count, maxClusterCount, this.Gradient));
            return feature;
        }
        private void MyMap_Loaded(object sender, RoutedEventArgs e)
        {
            #region 使用预定义点符号
            Feature featurePoint = new Feature();
            GeoPoint point = new GeoPoint();
            point.X = 116.2;
            point.Y = 39.6;
            PredefinedMarkerStyle simpleMarkerStyle = new PredefinedMarkerStyle();
            simpleMarkerStyle.Color = new SolidColorBrush(Colors.Red);
            simpleMarkerStyle.Size = 20;
            simpleMarkerStyle.Symbol = SuperMap.Web.Core.PredefinedMarkerStyle.MarkerSymbol.Star;
            featurePoint.Style = simpleMarkerStyle;
            featurePoint.Geometry = point;
            featuresLayer.Features.Add(featurePoint);
            #endregion

            #region 使用预定义线符号
            Feature featureLine = new Feature();
            Point2DCollection points = new Point2DCollection();
            points.Add(new Point2D(116.2, 39.6));
            points.Add(new Point2D(90, 50));
            points.Add(new Point2D(50, 25));
            points.Add(new Point2D(-80, 45));
            points.Add(new Point2D(-100, 38));
            ObservableCollection<Point2DCollection> path = new ObservableCollection<Point2DCollection>();
            path.Add(points);
            GeoLine geoLine = new GeoLine();
            geoLine.Parts = path;

            PredefinedLineStyle simpleLineStyle = new PredefinedLineStyle();
            simpleLineStyle.Stroke = new SolidColorBrush(Colors.Black);
            simpleLineStyle.StrokeThickness = 1;
            simpleLineStyle.StrokeDashArray = new DoubleCollection { 3, 1 };

            featureLine.Geometry = geoLine;
            featureLine.Style = simpleLineStyle;
            featuresLayer.Features.Add(featureLine);
            #endregion

            #region 使用预定义面符号
            Feature featureRegion = new Feature();
            Point2DCollection pointsRegion = new Point2DCollection();
            pointsRegion.Add(new Point2D(-8, 61));
            pointsRegion.Add(new Point2D(-6, 55));
            pointsRegion.Add(new Point2D(-8, 50));
            pointsRegion.Add(new Point2D(2, 50));
            pointsRegion.Add(new Point2D(1, 61));
            pointsRegion.Add(new Point2D(-8, 61));
            ObservableCollection<Point2DCollection> pRegion = new ObservableCollection<Point2DCollection>();
            pRegion.Add(pointsRegion);
            GeoRegion geoRegion = new GeoRegion();
            geoRegion.Parts = pRegion;

            PredefinedFillStyle simpleFillStyle = new PredefinedFillStyle();
            simpleFillStyle.StrokeThickness = 1;
            simpleFillStyle.Stroke = new SolidColorBrush(Colors.Black);
            simpleFillStyle.Fill = new SolidColorBrush(Colors.Yellow);

            featureRegion.Geometry = geoRegion;
            featureRegion.Style = simpleFillStyle;
            featuresLayer.Features.Add(featureRegion);
            #endregion

            #region 添加文本
            Feature featureText = new Feature();
            GeoPoint text = new GeoPoint();
            text.X = 5;
            text.Y = 10;

            TextStyle textStyle = new TextStyle();
            textStyle.Text = "Africa";
            textStyle.FontSize = 40;
            textStyle.Foreground = new SolidColorBrush(Colors.Blue);

            featureText.Geometry = text;
            featureText.Style = textStyle;
            featuresLayer.Features.Add(featureText);
            #endregion
        }
 private GeoPoint ParsePointCoordinates(string p)
 {
     GeoPoint point = new GeoPoint();
     if (!string.IsNullOrEmpty(p))
     {
         string[] pointStr = p.Trim().Split(',');
         point.X = double.Parse(pointStr[0], CultureInfo.InvariantCulture);
         point.Y = double.Parse(pointStr[1], CultureInfo.InvariantCulture);
     }
     return point;
 }