Esempio n. 1
0
        private void AndroidMap_MapSingleTap(object sender, Android.Views.MotionEvent e)
        {
            PointF     location = new PointF(e.GetX(), e.GetY());
            PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X,
                                                                 location.Y, androidMap.Width, androidMap.Height);

            LayerOverlay worldOverlay = (LayerOverlay)androidMap.Overlays["WorldOverlay"];
            FeatureLayer worldLayer   = (FeatureLayer)worldOverlay.Layers["WorldLayer"];

            LayerOverlay         highlightOverlay = (LayerOverlay)androidMap.Overlays["HighlightOverlay"];
            InMemoryFeatureLayer highlightLayer   = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"];

            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(position, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            highlightLayer.Open();
            highlightLayer.InternalFeatures.Clear();
            if (selectedFeatures.Count > 0)
            {
                AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape();
                double        area      = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                messageTextView.Text = string.Format(CultureInfo.InvariantCulture, "{0} has an area of {1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area);

                highlightLayer.InternalFeatures.Add(selectedFeatures[0]);
            }
            highlightLayer.Close();
            highlightOverlay.Refresh();
        }
Esempio n. 2
0
        private void mapView_MapClick(object sender, MapClickMapViewEventArgs e)
        {
            FeatureLayer worldLayer = mapView.FindFeatureLayer("WorldLayer");

            // Find the country the user clicked on.
            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            // Determine the area of the country.
            if (selectedFeatures.Count > 0)
            {
                ProjectionConverter project = new ProjectionConverter(3857, 4326);
                project.Open();
                AreaBaseShape areaShape = (AreaBaseShape)project.ConvertToExternalProjection(selectedFeatures[0].GetShape());
                project.Close();
                double area        = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                string areaMessage = string.Format(CultureInfo.InvariantCulture, "{0} has an area of \r{1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area);

                Popup popup = new Popup(e.WorldLocation);
                popup.Content = areaMessage;
                PopupOverlay popupOverlay = (PopupOverlay)mapView.Overlays["PopupOverlay"];
                popupOverlay.Popups.Clear();
                popupOverlay.Popups.Add(popup);
                popupOverlay.Refresh();
            }
        }
        private void cmxDistanceUnit_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            AreaUnit areaUnit = (AreaUnit)cmxDistanceUnit.SelectedItem;

            defaultAreaUnit = areaUnit;
            double acreage = areaShape.GetArea(GisEditor.ActiveMap.MapUnit, areaUnit);

            origalAcreageTb.Text = acreage.ToString();
            targetAcreageTb.Text = acreage.ToString();
        }
Esempio n. 4
0
        private void MouseMoved(object sender, MouseMovedTrackInteractiveOverlayEventArgs e)
        {
            //Gets the shape as it is being tracked and gets its properties to be displayed in labels og groupbox
            AreaBaseShape areaBaseShape = (AreaBaseShape)winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape();
            double        Perimeter     = Math.Round(areaBaseShape.GetPerimeter(winformsMap1.MapUnit, DistanceUnit.Kilometer));
            double        Area          = Math.Round(areaBaseShape.GetArea(winformsMap1.MapUnit, AreaUnit.SquareKilometers));

            lblPerimeter.Text = String.Format("{0:0,0}", Perimeter) + " km";
            lblArea.Text      = String.Format("{0:0,0}", Area) + " km2";

            //Sets the location (in screen coordinates) of the groupbox according to last moved vertex of the tracked shape (in world coordinates).
            ScreenPointF screenPointF = ThinkGeo.MapSuite.Core.ExtentHelper.ToScreenCoordinate(winformsMap1.CurrentExtent, e.MovedVertex.X, e.MovedVertex.Y, winformsMap1.Width, winformsMap1.Height);

            groupBoxInfo.Location = new Point((int)screenPointF.X + 30, (int)screenPointF.Y + 10);
        }
        private void AreaResizeMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem         item      = (MenuItem)sender;
            Feature          feature   = (Feature)item.Tag;
            AreaBaseShape    areaShape = (AreaBaseShape)feature.GetShape();
            AreaResizeWindow window    = new AreaResizeWindow(areaShape);

            window.Owner = Application.Current.MainWindow;
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            if (window.ShowDialog().GetValueOrDefault())
            {
                double orignalAcreage = window.OriginalAcreage;
                double acreage        = window.ResultAcreage;

                double difference = 1;

                while (difference > 0.05)
                {
                    if (acreage > orignalAcreage)
                    {
                        double percentage = (Math.Sqrt(acreage) / Math.Sqrt(orignalAcreage) * 100) % 100;
                        areaShape.ScaleUp(percentage);
                    }
                    else if (acreage == orignalAcreage)
                    {
                    }
                    else
                    {
                        double percentage = (Math.Sqrt(orignalAcreage) / Math.Sqrt(acreage) * 100) % 100;
                        areaShape.ScaleDown(percentage);
                    }
                    orignalAcreage = areaShape.GetArea(GisEditor.ActiveMap.MapUnit, AreaResizeWindow.DefaultAreaUnit);
                    difference     = Math.Abs(orignalAcreage - acreage) / acreage;
                }

                Feature tempfeature = GisEditor.ActiveMap.FeatureLayerEditOverlay.EditShapesLayer.InternalFeatures.FirstOrDefault(f => f.Id.Equals(feature.Id));
                if (tempfeature != null)
                {
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.EditShapesLayer.InternalFeatures.Remove(tempfeature);
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.EditShapesLayer.InternalFeatures.Add(tempfeature.Id, new Feature(areaShape, tempfeature.ColumnValues));
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.TakeSnapshot();
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.Refresh();
                }
            }
        }
        private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
        {
            FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("WorldLayer");

            // Find the country the user clicked on.
            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            // Determine the area of the country.
            if (selectedFeatures.Count > 0)
            {
                AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape();
                double        area      = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "{0} has an area of {1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area), "Area", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }
        public AreaResizeWindow(AreaBaseShape areaShape)
        {
            InitializeComponent();

            this.areaShape = areaShape;

            distanceUnits = new Collection <AreaUnit>();
            double acreage = areaShape.GetArea(GisEditor.ActiveMap.MapUnit, defaultAreaUnit);

            origalAcreageTb.Text = acreage.ToString();
            targetAcreageTb.Text = acreage.ToString();
            tempAcreage          = targetAcreageTb.Text;

            foreach (AreaUnit item in Enum.GetValues(typeof(AreaUnit)))
            {
                distanceUnits.Add(item);
            }

            cmxDistanceUnit.ItemsSource  = distanceUnits;
            cmxDistanceUnit.SelectedItem = defaultAreaUnit;
        }
Esempio n. 8
0
        public string GetArea(Map map, Collection<object> args)
        {
            double clickedX = double.Parse(args[0].ToString(), CultureInfo.InvariantCulture);
            double clickedY = double.Parse(args[1].ToString(), CultureInfo.InvariantCulture);
            PointShape point = new PointShape(clickedX, clickedY);

            FeatureLayer worldLayer = (ShapeFileFeatureLayer)((LayerOverlay)map.CustomOverlays["OverLayer"]).Layers["worldLayer"];

            // Find the country the user clicked on.
            worldLayer.Open();
            Collection<Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(point, new string[1] { "CNTRY_NAME" });
            worldLayer.Close();

            // Determine the area of the country.
            string contentHtml = @"<div style='color:#0065ce;font-size:10px; font-family:verdana; padding:4px;'>Please click on a country to see how large it is.</div>";
            if (selectedFeatures.Count > 0)
            {
                AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape();
                double area = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                contentHtml = string.Format(@"<div style='color:#0065ce;font-size:10px; font-family:verdana; padding:4px;'><span style='color:red'>{0}</span> has an area of <span style='color:red'>{1:N0}</span> square kilometers.</div>", selectedFeatures[0].ColumnValues["CNTRY_NAME"], area);
            }

            return contentHtml;
        }