/// <summary> /// Process cluster graphic mouse events. /// </summary> /// <param name="clusterGraphic">Cluster graphic.</param> /// <param name="clickedGraphic">Last clicked item.</param> private void _ProcessClusterGraphicMouseEvents(ClusterGraphicObject clusterGraphic, Graphic clickedGraphic) { Debug.Assert(clusterGraphic != null); Debug.Assert(clickedGraphic != null); Debug.Assert(_clustering != null); Debug.Assert(_objectLayers != null); if (!_clustering.ClusterExpanded) { _clustering.ExpandIfNeeded(clusterGraphic); } else { IList <object> clusteredData = _clustering.GetClusteredData(clusterGraphic); ObjectLayer layer = MapHelpers.GetLayerWithData(clusteredData[0], _objectLayers); if (clickedGraphic == clusterGraphic && layer.Selectable) { if (Keyboard.Modifiers != ModifierKeys.Shift && Keyboard.Modifiers != ModifierKeys.Control) { _mapControl.SelectedItems.Clear(); } _ProcessSelectionChanges(clusteredData, layer); } } }
/// <summary> /// Get elements in frame. /// </summary> /// <param name="objectLayer">Layer to find elements.</param> /// <param name="frame">Frame.</param> /// <returns>Elements in frame.</returns> private List <object> _GetElementsInSelectionFrame(ObjectLayer objectLayer, ESRI.ArcGIS.Client.Geometry.Envelope frame) { Debug.Assert(SelectedItems != null); Debug.Assert(_selectionFrame != null); Debug.Assert(_clustering != null); List <object> elementsInFrame = new List <object>(); foreach (DataGraphicObject graphic in objectLayer.MapLayer.Graphics) { // Null extent in case of empty polyline. if (graphic.Geometry != null && graphic.Geometry.Extent != null && graphic.Data.GetType() == objectLayer.LayerType) { // If graphic in frame, data type is equals to objectLayer data type and data contains in objectayercollection. if (MapHelpers.IsIntersects(frame, graphic.Geometry) && graphic.Data.GetType() == objectLayer.LayerType && MapHelpers.CollectionContainsData(objectLayer.Collection, graphic.Data)) { elementsInFrame.Add(graphic.Data); } } } _clustering.AddElementsFromClusterAndNotInFrame(objectLayer, frame, elementsInFrame); return(elementsInFrame); }
/// <summary> /// React on dropping on map. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Dropping event args.</param> private void _MapDrop(object sender, DragEventArgs e) { Debug.Assert(_dragAndDropHelper != null); Debug.Assert(_mapView != null); FrameworkElement frameworkElement = (FrameworkElement)e.OriginalSource; DataBinding dataBinding = (DataBinding)frameworkElement.DataContext; Debug.Assert(dataBinding != null); if (dataBinding != null) { System.Windows.Point position = e.GetPosition(_mapView.mapCtrl.map); Object targetData = dataBinding.Attributes[DataGraphicObject.DataKeyName]; Route route = targetData as Route; IList <Stop> stops = null; if (route != null) { Envelope extent = _GetExtentNearDroppedPoint(position); stops = MapHelpers.FindNearestPreviousStops(route.Schedule, extent); } if (stops != null && stops.Count > 1) { _DoPrepareDropOnMultipleStops(e.Data, stops); } else { Stop nextStop = targetData as Stop; _dragAndDropHelper.Drop(targetData, e.Data); } } }
/// <summary> /// Check graphics count /// </summary> /// <param name="clusterGraphic">Cluster graphic to expand</param> /// <returns>True if exceeded</returns> private bool _MaxGraphicsToExpandExceeded(ClusterGraphicObject clusterGraphic) { IList <object> clusterData = GetClusteredData(clusterGraphic); ObjectLayer objectLayer = MapHelpers.GetLayerWithData(clusterData[0], _mapctrl.ObjectLayers); FlareClusterer clusterer = (FlareClusterer)objectLayer.MapLayer.Clusterer; int objectsInCluster = (int)clusterGraphic.Attributes[ALClusterer.COUNT_PROPERTY_NAME]; bool exceeded = objectsInCluster > clusterer.MaximumFlareCount; return(exceeded); }
/// <summary> /// Add elements from cluster and not in frame /// </summary> /// <param name="objectLayer">Object layer to find cluster</param> /// <param name="frame">Selection fram envelope</param> /// <param name="elementsInFrame">Already selected elements list</param> public void AddElementsFromClusterAndNotInFrame(ObjectLayer objectLayer, Envelope frame, IList <object> elementsInFrame) { foreach (ClusterGraphicObject clusterGraphic in ClusterGraphicObject.Graphics) { if (MapHelpers.IsIntersects(frame, clusterGraphic.Geometry)) { IList <object> clusterDataList = GetClusteredData(clusterGraphic); foreach (object data in clusterDataList) { // if graphic not in frame yet, data type is equals to objectLayer data type and data contains in objectayercollection if (data.GetType() == objectLayer.LayerType && !elementsInFrame.Contains(data) && MapHelpers.CollectionContainsData(objectLayer.Collection, data)) { elementsInFrame.Add(data); } } } } }
/// <summary> /// React on selected items changed. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Collection changed args.</param> private void _SelectionCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Debug.Assert(_objectLayers != null); Debug.Assert(_clustering != null); _StoreSelectionIfNeeded(e); switch (e.Action) { case NotifyCollectionChangedAction.Add: { foreach (object data in e.NewItems) { // Select item in object layer. ObjectLayer objectLayer = MapHelpers.GetLayerWithData(data, _objectLayers); if (objectLayer != null) { objectLayer.SelectedItems.Add(data); } // Select in clustering layer also. if (_clustering != null) { _clustering.AddToSelection(data); } } break; } case NotifyCollectionChangedAction.Remove: { foreach (object data in e.OldItems) { // Deselect item in object layer. ObjectLayer objectLayer = MapHelpers.GetLayerWithData(data, _objectLayers); if (objectLayer != null) { objectLayer.SelectedItems.Remove(data); } // Remove from selection in clustering layer also. if (_clustering != null) { _clustering.RemoveFromSelection(data); } } break; } case NotifyCollectionChangedAction.Reset: { foreach (ObjectLayer objectLayer in _objectLayers) { objectLayer.SelectedItems.Clear(); } break; } default: Debug.Assert(false); break; } }