/// <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> /// 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> /// Expand cluster if mouse on graphic and it can be expanded /// </summary> /// <param name="graphic">Graphic under mouse</param> internal void ExpandIfNeeded(Graphic graphic) { if (!ClusterExpanded) { ClusterGraphicObject clusterGraphic = graphic as ClusterGraphicObject; if (clusterGraphic != null) { _ExpandCluster(clusterGraphic); } } }
private static Graphic CreateCustomFlareCluster(GraphicCollection cluster, MapPoint point) { ClusterGraphicObject clGr = ClusterGraphicObject.Create(point, cluster); clGr.Attributes.Add(COUNT_PROPERTY_NAME, cluster.Count); for (int index = 0; index < cluster.Count; index++) { clGr.Attributes.Add(GRAPHIC_PROPERTY_NAME + index.ToString(), cluster[index]); } return(clGr); }
public IList <object> GetClusteredData(ClusterGraphicObject clusterGraphic) { List <object> clusteredData = new List <object>(); int count = (int)clusterGraphic.Attributes[ALClusterer.COUNT_PROPERTY_NAME]; for (int index = 0; index < count; index++) { string attributeName = ALClusterer.GRAPHIC_PROPERTY_NAME + index.ToString(); DataGraphicObject dataGraphic = (DataGraphicObject)clusterGraphic.Attributes[attributeName]; clusteredData.Add(dataGraphic.Data); } return(clusteredData); }
/// <summary> /// Process graphic mouse events: expand or select. /// </summary> /// <param name="graphic">Graphic to process events.</param> /// <param name="clickedGraphic">Last clicked graphic.</param> public void ProcessGraphicMouseEvents(Graphic graphic, Graphic clickedGraphic) { Debug.Assert(graphic != null); DataGraphicObject dataGraphic = graphic as DataGraphicObject; ClusterGraphicObject clusterGraphic = graphic as ClusterGraphicObject; if (clusterGraphic != null) { _ProcessClusterGraphicMouseEvents(clusterGraphic, clickedGraphic); } else if (dataGraphic != null) { _ProcessDataGraphicMouseEvents(dataGraphic, clickedGraphic); } }
/// <summary> /// Expand cluster from cluster graphic /// </summary> /// <param name="clusterGraphic">Cluster graphic to expand</param> private void _ExpandCluster(ClusterGraphicObject clusterGraphic) { if (_mapctrl.IsInEditedMode || _MaxGraphicsToExpandExceeded(clusterGraphic)) { return; } if (!_mapctrl.IsInEditedMode) { _mapctrl.SetOpacityToLayers(MapControl.HalfOpacity); } _expandedClusterGraphic = clusterGraphic; _clusteringLayer.Visible = true; int count = (int)clusterGraphic.Attributes[ALClusterer.COUNT_PROPERTY_NAME]; Debug.Assert(count > 0); for (int index = 0; index < count; index++) { string attrKey = ALClusterer.GRAPHIC_PROPERTY_NAME + index.ToString(); DataGraphicObject grObj = (DataGraphicObject)clusterGraphic.Attributes[attrKey]; _clusteringLayerColl.Add(grObj.Data); // support already selected items if (_mapctrl.SelectedItems.Contains(grObj.Data)) { _clusteringLayer.SelectedItems.Add(grObj.Data); } } _clusterCenter = _mapctrl.map.MapToScreen((MapPoint)clusterGraphic.Geometry); if (_clusteringLayer.MapLayer.Graphics.Count > MAXIMUM_GRAPHICS_IN_CIRCLE_EXPANDED) { _SetSpiraledPositionsToExpandedClusterGraphics(); } else { _SetCircledPositionsToExpandedClusterGraphics(); } _CreateLeaderLines(); _expandedClusterGraphic.SetZIndex(ObjectLayer.FRONTZINDEX); }
public override void ClusterGraphicsAsync(IEnumerable <Graphic> graphics, double resolution) { ClusterGraphicObject.DisposeAll(); base.ClusterGraphicsAsync(graphics, resolution); }