Exemplo n.º 1
0
        private void RegionsTreeView_OnPreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var    vm           = (GeographicalViewModel)DataContext;
            object selectedItem = RegionsTreeView.SelectedItem;
            var    region       = selectedItem as GeographicalRegionViewModel;

            if (region != null)
            {
                RegionMarker marker = MapControl.Markers.OfType <RegionMarker>().First(rm => rm.Region == region);
                if (marker.Shape.IsVisible && (_popup == null || _popup.Tag != marker))
                {
                    ZoomAndCenterRegions(new[] { marker });
                    vm.SelectedRegion = region;
                }
            }
            else
            {
                var variety = selectedItem as GeographicalVarietyViewModel;
                if (variety != null)
                {
                    ZoomAndCenterRegions(MapControl.Markers.OfType <RegionMarker>().Where(rm => rm.Shape.IsVisible && rm.Region.Variety == variety));
                    vm.SelectedRegion = null;
                }
            }
        }
Exemplo n.º 2
0
        private void AddRegions(IEnumerable<GeographicalRegionViewModel> regions)
        {
            foreach (GeographicalRegionViewModel region in regions)
            {
                var marker = new RegionMarker(region) {IsSelectable = _currentTool == Tool.Select};
                marker.Click += Region_Click;
                marker.RegenerateShape(MapControl);

                MapControl.Markers.Add(marker);
            }
        }
Exemplo n.º 3
0
        private void AddRegions(IEnumerable <GeographicalRegionViewModel> regions)
        {
            foreach (GeographicalRegionViewModel region in regions)
            {
                var marker = new RegionMarker(region)
                {
                    IsSelectable = _currentTool == Tool.Select
                };
                marker.Click += Region_Click;
                MapControl.RegenerateShape(marker);

                MapControl.Markers.Add(marker);
            }
        }
Exemplo n.º 4
0
        private void SelectRegionMarker(RegionMarker rm)
        {
            ClosePopup();

            Point centerPoint = CalculateCenter(rm);
            Point p           = CalculatePopupPosition(centerPoint);

            _popup = new GMapMarker(MapControl.FromLocalToLatLng((int)p.X, (int)p.Y))
            {
                Tag = rm, Shape = new GeographicalRegionView {
                    DataContext = rm.Region
                }, ZIndex = 100
            };
            MapControl.Markers.Add(_popup);

            int xOffset = 0;

            if (p.X - 5 < 0)
            {
                xOffset = (int)-(p.X - 5);
            }
            else if (p.X + 205 > MapControl.ActualWidth)
            {
                xOffset = (int)(MapControl.ActualWidth - (p.X + 205));
            }

            int yOffset = 0;

            if (p.Y - 5 < 0)
            {
                yOffset = (int)-(p.Y - 5);
            }
            else if (p.Y + 175 > MapControl.ActualHeight)
            {
                yOffset = (int)(MapControl.ActualHeight - (p.Y + 175));
            }

            if (xOffset != 0 || yOffset != 0)
            {
                MapControl.Offset(xOffset, yOffset);
            }

            SelectTreeRegion(rm.Region);
        }
Exemplo n.º 5
0
        private Point CalculateCenter(RegionMarker rm)
        {
            long areaSum = 0;
            long xSum    = 0;
            long ySum    = 0;

            for (int i = 0; i < rm.Points.Count; i++)
            {
                GPoint curPoint  = MapControl.FromLatLngToLocal(rm.Points[i]);
                GPoint nextPoint = MapControl.FromLatLngToLocal(i == rm.Points.Count - 1 ? rm.Points[0] : rm.Points[i + 1]);
                long   v         = (curPoint.X * nextPoint.Y) - (nextPoint.X * curPoint.Y);
                areaSum += v;
                xSum    += (curPoint.X + nextPoint.X) * v;
                ySum    += (curPoint.Y + nextPoint.Y) * v;
            }

            double areaTerm = 1.0 / (6.0 * (areaSum / 2.0));

            double cx = areaTerm * xSum;
            double cy = areaTerm * ySum;

            return(new Point(cx, cy));
        }
Exemplo n.º 6
0
        private Point CalculateCenter(RegionMarker rm)
        {
            long areaSum = 0;
            long xSum = 0;
            long ySum = 0;
            for (int i = 0; i < rm.Points.Count; i++)
            {
                GPoint curPoint = MapControl.FromLatLngToLocal(rm.Points[i]);
                GPoint nextPoint = MapControl.FromLatLngToLocal(i == rm.Points.Count - 1 ? rm.Points[0] : rm.Points[i + 1]);
                long v = (curPoint.X * nextPoint.Y) - (nextPoint.X * curPoint.Y);
                areaSum += v;
                xSum += (curPoint.X + nextPoint.X) * v;
                ySum += (curPoint.Y + nextPoint.Y) * v;
            }

            double areaTerm = 1.0 / (6.0 * (areaSum / 2.0));

            double cx = areaTerm * xSum;
            double cy = areaTerm * ySum;
            return new Point(cx, cy);
        }
Exemplo n.º 7
0
        private void SelectRegionMarker(RegionMarker rm)
        {
            ClosePopup();

            Point centerPoint = CalculateCenter(rm);
            Point p = CalculatePopupPosition(centerPoint);
            _popup = new GMapMarker(MapControl.FromLocalToLatLng((int) p.X, (int) p.Y)) {Tag = rm, Shape = new GeographicalRegionView {DataContext = rm.Region}, ZIndex = 100};
            MapControl.Markers.Add(_popup);

            int xOffset = 0;
            if (p.X - 5 < 0)
                xOffset = (int) -(p.X - 5);
            else if (p.X + 205 > MapControl.ActualWidth)
                xOffset = (int) (MapControl.ActualWidth - (p.X + 205));

            int yOffset = 0;
            if (p.Y - 5 < 0)
                yOffset = (int) -(p.Y - 5);
            else if (p.Y + 175 > MapControl.ActualHeight)
                yOffset = (int) (MapControl.ActualHeight - (p.Y + 175));

            if (xOffset != 0 || yOffset != 0)
                MapControl.Offset(xOffset, yOffset);

            SelectTreeRegion(rm.Region);
        }