Esempio n. 1
0
        private void AndroidMap_CurrentExtentChanged(object sender, CurrentExtentChangedMapViewEventArgs e)
        {
            PointShape upperLeftPoint  = e.NewExtent.UpperLeftPoint;
            PointShape lowerRightPoint = e.NewExtent.LowerRightPoint;

            labelExtent.Text = string.Format("Map cureent extent: {0}, {1}, {2}, {3}", upperLeftPoint.X.ToString("n2"), upperLeftPoint.Y.ToString("n2"), lowerRightPoint.X.ToString("n2"), lowerRightPoint.Y.ToString("n2"));
            labelScale.Text  = string.Format("Map cureent scale: {0}", ExtentHelper.GetScale(e.NewExtent, (float)androidMap.Width, androidMap.MapUnit).ToString("n4"));
        }
Esempio n. 2
0
        private void ZoomToFeatures(IEnumerable <Feature> features, FeatureLayer featureLayer)
        {
            RectangleShape extent        = features.Count() == 1 ? GetBoundingBox(features.FirstOrDefault()) : ExtentHelper.GetBoundingBoxOfItems(features);
            RectangleShape drawingExtent = ExtentHelper.GetDrawingExtent(extent, (float)GisEditor.ActiveMap.ActualWidth, (float)GisEditor.ActiveMap.ActualHeight);
            var            scale         = ExtentHelper.GetScale(drawingExtent, (float)map.ActualWidth, map.MapUnit);

            map.ZoomTo(extent.GetCenterPoint(), scale);
            //GisEditor.UIManager.RefreshPlugins(new RefreshArgs(extent.GetCenterPoint(), "Identify"));
            GisEditor.UIManager.RefreshPlugins(new RefreshArgs(new Tuple <IEnumerable <Feature>, FeatureLayer>(features, featureLayer), "Identify"));
        }
        private Bitmap ZedGraphDrawing(ZedGraphDrawingEventArgs e)
        {
            double scale = ExtentHelper.GetScale(winformsMap1.CurrentExtent, winformsMap1.Width, GeographyUnit.DecimalDegree);

            // Change the size of the graph based on the scale.  It will get bigger as you zoom in.
            int          graphHeight   = Convert.ToInt32(1400000000 / scale);
            LayerOverlay staticOverlay = (LayerOverlay)winformsMap1.Overlays["CitiesOverlay"];

            ChangeLabelPosition(((ShapeFileFeatureLayer)staticOverlay.Layers["Cities"]), graphHeight);

            ZedGraphControl zedGraph = new ZedGraphControl();

            zedGraph.Size = new Size(graphHeight, graphHeight);

            zedGraph.GraphPane.Fill.Type       = FillType.None;
            zedGraph.GraphPane.Chart.Fill.Type = FillType.None;

            zedGraph.GraphPane.Border.IsVisible       = false;
            zedGraph.GraphPane.Chart.Border.IsVisible = false;
            zedGraph.GraphPane.XAxis.IsVisible        = false;
            zedGraph.GraphPane.YAxis.IsVisible        = false;
            zedGraph.GraphPane.Legend.IsVisible       = false;
            zedGraph.GraphPane.Title.IsVisible        = false;

            PieItem pieItem1 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["WHITE"], CultureInfo.InvariantCulture), GetColorFromGeoColor(GeoColor.StandardColors.LightBlue), 0, "White");

            pieItem1.LabelDetail.IsVisible = false;

            PieItem pieItem2 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["ASIAN"], CultureInfo.InvariantCulture), GetColorFromGeoColor(GeoColor.StandardColors.LightGreen), 0, "Asian");

            pieItem2.LabelDetail.IsVisible = false;
            pieItem2.Displacement          = 0.2;

            zedGraph.AxisChange();

            return(zedGraph.GraphPane.GetImage());
        }
Esempio n. 4
0
        /// <summary>
        /// Here in the DrawCore we cluster the features
        /// </summary>
        protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers)
        {
            //  We get the scale to determine the grid.  This scale property should really be on the Canvas!
            double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);

            // Setup our grid for clustering the points.  This is where we specify our cell size in pixels
            MapSuiteTileMatrix mapSuiteTileMatrix = new MapSuiteTileMatrix(scale, cellSize, cellSize, canvas.MapUnit);

            // Pass in the current extent to get our grid cells.  All points in these cells will be consolidated
            IEnumerable <TileMatrixCell> tileMatricCells = mapSuiteTileMatrix.GetContainedCells(canvas.CurrentWorldExtent);

            // Create an unused features list, as we add them to clusters we will remove them from here
            // This is just for speed so we don't re-test lots of already associated features
            Dictionary <string, string> unusedFeatures = new Dictionary <string, string>();

            foreach (Feature feature in features)
            {
                if (feature.GetWellKnownType() != WellKnownType.Point && feature.GetWellKnownType() != WellKnownType.Multipoint)
                {
                    continue;
                }
                unusedFeatures.Add(feature.Id, feature.Id);
            }

            // Loop through each cell and find the features that fit inside of it
            foreach (TileMatrixCell cell in tileMatricCells)
            {
                int             featureCount        = 0;
                MultipointShape tempMultiPointShape = new MultipointShape();
                foreach (Feature feature in features)
                {
                    // Make sure the feature has not been used in another cluster
                    if (unusedFeatures.ContainsKey(feature.Id))
                    {
                        // Check if the cell contains the feature
                        if (cell.BoundingBox.Contains(feature.GetBoundingBox()))
                        {
                            featureCount++;
                            unusedFeatures.Remove(feature.Id);
                            if (feature.GetWellKnownType() == WellKnownType.Multipoint)
                            {
                                MultipointShape multipointShape = feature.GetShape() as MultipointShape;
                                foreach (var item in multipointShape.Points)
                                {
                                    tempMultiPointShape.Points.Add(item);
                                }
                            }
                            else
                            {
                                tempMultiPointShape.Points.Add(feature.GetShape() as PointShape);
                            }
                        }
                    }
                }
                if (featureCount > 0)
                {
                    // Add the feature count to the new feature we created.  The feature will be placed
                    // at the center of gravity of all the clustered features of the cell we created.
                    Dictionary <string, string> featureValues = new Dictionary <string, string>();
                    featureValues.Add("FeatureCount", featureCount.ToString(CultureInfo.InvariantCulture));

                    bool isMatch = false;

                    for (int i = 0; i < classBreakPoints.Count - 1; i++)
                    {
                        var startItem = classBreakPoints.ElementAt(i);
                        var endItem   = classBreakPoints.ElementAt(i + 1);
                        if (featureCount >= startItem.Key && featureCount < endItem.Key)
                        {
                            // Draw the point shape
                            startItem.Value.Draw(new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers);
                            isMatch = true;
                            break;
                        }
                    }
                    if (!isMatch && featureCount >= classBreakPoints.LastOrDefault().Key)
                    {
                        classBreakPoints.LastOrDefault().Value.Draw(new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers);
                    }

                    if (featureCount != 1)
                    {
                        // Draw the text style to show how many feaures are consolidated in the cluster
                        textSytle.Draw(new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers);
                    }
                }
            }
        }
Esempio n. 5
0
        protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers)
        {
            double                       scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);
            MapSuiteTileMatrix           mapSuiteTileMatrix = new MapSuiteTileMatrix(scale, cellSize, cellSize, canvas.MapUnit);
            IEnumerable <TileMatrixCell> tileMatricCells    = mapSuiteTileMatrix.GetContainedCells(canvas.CurrentWorldExtent);
            Dictionary <string, string>  unusedFeatures     = new Dictionary <string, string>();

            foreach (Feature feature in features)
            {
                if (feature.GetWellKnownType() != WellKnownType.Point && feature.GetWellKnownType() != WellKnownType.Multipoint)
                {
                    continue;
                }
                unusedFeatures.Add(feature.Id, feature.Id);
            }

            foreach (TileMatrixCell cell in tileMatricCells)
            {
                int             featureCount        = 0;
                MultipointShape tempMultiPointShape = new MultipointShape();
                foreach (Feature feature in features)
                {
                    // Make sure the feature has not been used in another cluster
                    if (unusedFeatures.ContainsKey(feature.Id))
                    {
                        // Check if the cell contains the feature
                        if (cell.BoundingBox.Contains(feature.GetBoundingBox()))
                        {
                            featureCount++;
                            unusedFeatures.Remove(feature.Id);
                            if (feature.GetWellKnownType() == WellKnownType.Multipoint)
                            {
                                MultipointShape multipointShape = feature.GetShape() as MultipointShape;
                                foreach (var item in multipointShape.Points)
                                {
                                    tempMultiPointShape.Points.Add(item);
                                }
                            }
                            else
                            {
                                tempMultiPointShape.Points.Add(feature.GetShape() as PointShape);
                            }
                        }
                    }
                }
                if (featureCount > 0)
                {
                    // Add the feature count to the new feature we created.  The feature will be placed
                    // at the center of gravity of all the clustered features of the cell we created.
                    Dictionary <string, string> featureValues = new Dictionary <string, string>();
                    featureValues.Add("FeatureCount", featureCount.ToString(CultureInfo.InvariantCulture));

                    bool isMatch = false;

                    for (int i = 0; i < classBreakPoint.Count - 1; i++)
                    {
                        var startItem = classBreakPoint.ElementAt(i);
                        var endItem   = classBreakPoint.ElementAt(i + 1);
                        if (featureCount >= startItem.Key && featureCount < endItem.Key)
                        {
                            //Draw the point shape
                            startItem.Value.Draw(new[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers);
                            isMatch = true;
                            break;
                        }
                    }
                    if (!isMatch && featureCount >= classBreakPoint.LastOrDefault().Key)
                    {
                        classBreakPoint.LastOrDefault().Value.Draw(new[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers);
                    }

                    if (featureCount != 1)
                    {
                        // Draw the text style to show how many feaures are consolidated in the cluster
                        textSytle.Draw(new[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) }, canvas, labelsInThisLayer, labelsInAllLayers);
                    }
                }
            }
        }