/// <param name="mapControl">Parent map control.</param>
        /// <param name="clustering">Clustering manager.</param>
        /// <param name="objectLayers">Map object layers.</param>
        public MapSelectionManager(MapControl mapControl, Clustering clustering, List<ObjectLayer> objectLayers)
        {
            Debug.Assert(mapControl != null);
            Debug.Assert(clustering != null);
            Debug.Assert(objectLayers != null);

            _mapControl = mapControl;
            _clustering = clustering;
            _objectLayers = objectLayers;

            _InitEventHandlers();

            SelectionFrameLayer = new GraphicsLayer();
        }
        /// <summary>
        /// Initializes tool with map control.
        /// </summary>
        /// <param name="mapControl"></param>
        public void Initialize(MapControl mapControl)
        {
            _mapControl = mapControl;
            _cursor = Cursors.Cross;

            SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol()
            {
                Color=new SolidColorBrush(Colors.Red),
                Width=2
            };

            _polylineDrawObject = new Draw(mapControl.map);
            _polylineDrawObject.LineSymbol = simpleLineSymbol;
            _polylineDrawObject.DrawComplete += _PolylineDrawComplete;
            _polylineDrawObject.DrawMode = DrawMode.Polyline;
        }
        /// <summary>
        /// Get current geocodable object.
        /// </summary>
        /// <param name="mapctrl">Map control.</param>
        /// <returns>Current geocodable object.</returns>
        private IGeocodable _GetCurrentGeocodableObject(MapControl mapctrl)
        {
            // Current geocodable object is edited object or,
            // in case of address by point tool activated, selected object.
            IGeocodable result = mapctrl.EditedObject as IGeocodable;

            if (result == null && mapctrl.CurrentTool is AddressByPointTool)
            {
                Debug.Assert(mapctrl.SelectedItems.Count == 1);
                result = mapctrl.SelectedItems[0] as IGeocodable;
            }

            return result;
        }
 public Clustering(MapControl mapctrl)
 {
     _mapctrl = mapctrl;
     _Init();
 }
        /// <summary>
        /// Create GeocodablePage.
        /// </summary>
        /// <param name="geocodableType">Geocodable type.</param>
        /// <param name="mapCtrl">Map from parent page.</param>
        /// <param name="candidateSelect">Control for selecting candidates.</param>
        /// <param name="controlsGrid">Grid, that contains map and candidateselect control.</param>
        /// <param name="geocodableGrid">Grid with geocodable items from parent page.</param>
        /// <param name="splitter">Splitter between map and candidateSelectControl.</param>
        /// <param name="parentLayer">Layer, that contains regions.</param>
        public GeocodablePage(Type geocodableType, MapControl mapCtrl, CandidateSelectControl candidateSelect,
            Grid controlsGrid, DataGridControlEx geocodableGrid, GridSplitter splitter, ObjectLayer parentLayer)
        {
            Debug.Assert(mapCtrl != null);
            Debug.Assert(candidateSelect != null);
            Debug.Assert(controlsGrid != null);
            Debug.Assert(geocodableGrid != null);
            Debug.Assert(splitter != null);
            Debug.Assert(parentLayer != null);

            _mapCtrl = mapCtrl;

            _candidateSelect = candidateSelect;
            _candidateSelect.Initialize(geocodableType);
            _controlsGrid = controlsGrid;
            _geocodableGrid = geocodableGrid;
            _splitter = splitter;
            _parentLayer = parentLayer;

            _geocodableType = geocodableType;

            _collapsed = new GridLength(0, GridUnitType.Star);
            _expanded = controlsGrid.ColumnDefinitions[SELECTORGRIDINDEX].Width;
            _collapsedMinWidth = 0;
            _expandedMinWidth = controlsGrid.ColumnDefinitions[SELECTORGRIDINDEX].MinWidth;
            _CollapseCandidateSelect();

            // Subscribe to grid loaded event.
            _geocodableGrid.Loaded += new RoutedEventHandler(_GeocodableGridLoaded);
        }
 /// <summary>
 /// Initializes with map control.
 /// </summary>
 /// <param name="mapControl">Map control.</param>
 public void Initialize(MapControl mapControl)
 {
     _mapControl = mapControl;
     _mapControl.map.MouseUp += new MouseButtonEventHandler(_MouseUp);
     _mapControl.map.ExtentChanging +=new EventHandler<ESRI.ArcGIS.Client.ExtentEventArgs>(_ExtentChanging);
 }
        /// <summary>
        /// Initializes tool with map control.
        /// </summary>
        /// <param name="mapControl">Map control.</param>
        public void Initialize(MapControl mapControl)
        {
            Debug.Assert(mapControl != null);

            _cursor = mapControl.map.Cursor;

            _mapControl = mapControl;
            _moveShapeCursor = ((TextBlock)mapControl.LayoutRoot.Resources[MOVE_SHAPE_CURSOR_RESOURCE_NAME]).Cursor;
            _moveVertexCursor = ((TextBlock)mapControl.LayoutRoot.Resources[MOVE_VERTEX_CURSOR_RESOURCE_NAME]).Cursor;

            _popupAddress.Initialize(_mapControl);
        }
        /// <summary>
        /// Initializes tool with map control.
        /// </summary>
        /// <param name="mapControl"></param>
        public void Initialize(MapControl mapControl)
        {
            _mapControl = mapControl;
            _cursor = Cursors.Cross;

            _mapControl.map.MouseEnter += new MouseEventHandler(_MapMouseEnter);
            _mapControl.map.MouseLeave += new MouseEventHandler(_MapMouseLeave);

            _popupAddress.Initialize(_mapControl);
        }
        /// <summary>
        /// Initializes tool with map control.
        /// </summary>
        /// <param name="mapControl">Parent map control.</param>
        public void Initialize(MapControl mapControl)
        {
            _mapControl = mapControl;
            _cursor = Cursors.Cross;

            CartographicLineSymbol simpleLineSymbol = new CartographicLineSymbol()
            {
                Color=new SolidColorBrush(Colors.Blue),
                Width=2
            };

            SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol()
            {
                BorderThickness = 1,
                BorderBrush = new System.Windows.Media.SolidColorBrush(Colors.Black),
                Fill = new SolidColorBrush(Color.FromArgb(128,128,128,128))
            };

            _polygonDrawObject = new Draw(mapControl.map);
            _polygonDrawObject.LineSymbol = simpleLineSymbol;
            _polygonDrawObject.FillSymbol = simpleFillSymbol;
            _polygonDrawObject.DrawComplete += _PolygonDrawComplete;
            _polygonDrawObject.DrawMode = DrawMode.Polygon;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parentPage">Optimize and edit page.</param>
        public RoutesListViewContextHandler(OptimizeAndEditPage parentPage)
        {
            Debug.Assert(null != parentPage);
            Debug.Assert(null != parentPage.CurrentSchedule);

            _parentPage = parentPage;
            _routes = parentPage.CurrentSchedule.Routes;
            _dataGridControl = parentPage.RoutesView.RoutesGrid;
            _dataGridControl.InitializingInsertionRow += new EventHandler<InitializingInsertionRowEventArgs>(xceedGrid_InitializingInsertionRow);
            _mapControl = parentPage.MapView.mapCtrl;
            _mapControl.EndEditRouteCallback = _EditEnded;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mapControl">Parent map control.</param>
        /// <param name="clustering">Clustering manager.</param>
        /// <param name="mapSelectionManager">Map selection manager.</param>
        public MapExtentManager(MapControl mapControl, Clustering clustering, MapSelectionManager mapSelectionManager)
        {
            Debug.Assert(mapControl != null);
            Debug.Assert(clustering != null);
            Debug.Assert(mapSelectionManager != null);

            _mapControl = mapControl;
            _clustering = clustering;
            _mapSelectionManager = mapSelectionManager;

            _InitEventHandlers();
        }
        /// <summary>
        /// Zoom to candidate depends on locator type.
        /// </summary>
        /// <param name="mapCtrl">Map control.</param>
        /// <param name="addressCandidate">Candidate to zoom.</param>
        /// <param name="locatorType">Type of locator, which return this candidate.</param>
        private static void _ZoomToCandidate(MapControl mapCtrl, AddressCandidate addressCandidate, LocatorType locatorType)
        {
            Debug.Assert(mapCtrl != null);
            Debug.Assert(addressCandidate != null);

            double extentInc = 0;

            // Get extent size.
            switch (locatorType)
            {
                case LocatorType.CityState:
                    {
                        extentInc = ZOOM_ON_CITY_STATE_CANDIDATE;
                        break;
                    }
                case LocatorType.Zip:
                    {
                        extentInc = ZOOM_ON_ZIP_CANDIDATE;
                        break;
                    }
                case LocatorType.Street:
                    {
                        extentInc = ZOOM_ON_STREET_CANDIDATE;
                        break;
                    }
                default:
                    {
                        Debug.Assert(false);
                        break;
                    }
            }

            // Make extent rectangle.
            ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope();
            rect.SetEmpty();
            rect.Union(addressCandidate.GeoLocation);

            rect.left -= extentInc;
            rect.right += extentInc;
            rect.top += extentInc;
            rect.bottom -= extentInc;

            ESRI.ArcGIS.Client.Geometry.Envelope extent = GeometryHelper.CreateExtent(rect,
                mapCtrl.Map.SpatialReferenceID);
            mapCtrl.ZoomTo(extent);
        }
        /// <summary>
        /// Zoom to candidate depends on locator type.
        /// </summary>
        /// <param name="mapCtrl">Map control.</param>
        /// <param name="addressCandidate">Candidate to zoom.</param>
        public static void ZoomToCandidates(MapControl mapCtrl, AddressCandidate[] addressCandidates)
        {
            Debug.Assert(mapCtrl != null);
            Debug.Assert(addressCandidates != null);

            LocatorType? locatorType = null;
            if (addressCandidates.Length == 1)
            {
                locatorType = GeocodeHelpers.GetLocatorTypeOfCandidate(addressCandidates[0]);
            }

            if (locatorType == null)
            {
                // If not composite locator - zoom to candidate.
                List<ESRI.ArcLogistics.Geometry.Point> points = new List<ESRI.ArcLogistics.Geometry.Point>();
                foreach (AddressCandidate addressCandidate in addressCandidates)
                {
                    points.Add(addressCandidate.GeoLocation);
                }
                SetExtentOnCollection(mapCtrl, points);
            }
            else
            {
                _ZoomToCandidate(mapCtrl, addressCandidates[0], locatorType.Value);
            }
        }
        /// <summary>
        /// Set map extent on point collection.
        /// </summary>
        /// <param name="mapCtrl">Map control.</param>
        /// <param name="points">Points collection.</param>
        public static void SetExtentOnCollection(MapControl mapCtrl, IList<ESRI.ArcLogistics.Geometry.Point> points)
        {
            ESRI.ArcLogistics.Geometry.Envelope? rect = GetCollectionExtent(points);

            if (rect.HasValue)
            {
                ESRI.ArcGIS.Client.Geometry.Envelope extent = GeometryHelper.CreateExtent(rect.Value,
                    mapCtrl.Map.SpatialReferenceID);
                mapCtrl.ZoomTo(extent);
            }
        }
        /// <summary>
        /// Create RegionsPage.
        /// </summary>
        /// <param name="mapCtrl">Map from parent page.</param>
        /// <param name="dataGridControl">Grid from parent page.</param>
        /// <param name="parentLayer">Layer, that contains regions.</param>
        /// <param name="type">Semantic type of regions. Barrier or Zone.</param>
        /// <param name="layoutRoot">Parent page layout root.</param>
        /// <param name="mapBorder">Container element for map.</param>
        public RegionsPage(MapControl mapCtrl, DataGridControlEx dataGridControl, ObjectLayer parentLayer,
            Type type, Grid layoutRoot, Border mapBorder)
        {
            _mapCtrl = mapCtrl;
            _mapCtrl.CanSelectCallback = _CanSelect;
            _mapCtrl.StartEditRegionCallback = _EditStarted;
            _mapCtrl.EndEditRegionCallback = _EditEnded;

            _dataGridControl = dataGridControl;

            _parentLayer = parentLayer;

            _type = type;

            if (_type == typeof(Zone))
            {
                _polygonTool = new ZonePolygonTool();
                _polygonTool.OnComplete += new EventHandler(_PolygonToolOnComplete);
                _mapCtrl.AddTool(_polygonTool, _CanActivateZonePolygonTool);
            }
            else if (_type == typeof(Barrier))
            {
                _CreateBarrierTools();
            }
            else
                Debug.Assert(false);

            _gridAutoFitHelper = new GridAutoFitHelper(dataGridControl, layoutRoot, mapBorder);
        }