private static CommandId[] FilterMapContextMenuCommands(MapContextCommand[] excludeCommands) { Hashtable contextCommandTable = new Hashtable(); foreach (MapContextCommand commandEnum in excludeCommands) contextCommandTable[commandEnum] = commandEnum; ArrayList commandIds = new ArrayList(); foreach (CommandId id in MapContextMenuIds) { if (!contextCommandTable.ContainsKey(_mapCommandIds[id])) commandIds.Add(id); } return (CommandId[])commandIds.ToArray(typeof(CommandId)); }
private MapContextCommand[] CalculateExcludedCommands() { MapContextCommand excludedCommand = MapContextCommand.ZoomRegionLevel; int zoomLevel = _mapControl.ZoomLevel; if (zoomLevel == StreetLevel) { excludedCommand = MapContextCommand.ZoomStreetLevel; } else if (zoomLevel == CityLevel) { excludedCommand = MapContextCommand.ZoomCityLevel; } else if (zoomLevel < RegionLevel) { excludedCommand = MapContextCommand.ZoomStreetLevel; } return(new MapContextCommand[] { excludedCommand }); }
internal static MapContextCommand ShowMapContextMenu(Control parent, Point location, MapContextCommand[] hideCommands, CommandManager commandManager) { Command returnCommand; using (CommandLoader commandLoader = new CommandLoader(commandManager, FilterMapContextMenuCommands(hideCommands))) { CommandContextMenuDefinition ccmd = new CommandContextMenuDefinition(); ccmd.CommandBar = false; ccmd.Entries.Add(CommandId.MapAddPushpin, false, true); ccmd.Entries.Add(CommandId.MapZoomStreetLevel, false, false); ccmd.Entries.Add(CommandId.MapZoomCityLevel, false, false); ccmd.Entries.Add(CommandId.MapZoomRegionLevel, false, false); ccmd.Entries.Add(CommandId.MapCenterMap, false, false); returnCommand = CommandContextMenu.ShowModal( commandManager, parent, location, ccmd); } if (returnCommand != null) return (MapContextCommand)_mapCommandIds[Enum.Parse(typeof(CommandId), returnCommand.Identifier)]; else return MapContextCommand.None; }
public void ShowContextMenu(CommandManager commandManager) { MapContextCommand command = MapContextMenu.ShowMapContextMenu(_mapControl, _mapControl.PointToScreen(new Point(_event.X, _event.Y)), CalculateExcludedCommands(), commandManager); switch (command) { case MapContextCommand.AddPushpin: AddPushpin(); break; case MapContextCommand.CenterMap: CenterMap(); break; case MapContextCommand.ZoomCityLevel: ZoomCityLevel(); break; case MapContextCommand.ZoomStreetLevel: ZoomStreetLevel(); break; case MapContextCommand.ZoomRegionLevel: ZoomRegionLevel(); break; case MapContextCommand.None: break; default: Debug.Fail("Unknown MapContextCommand: " + command.ToString()); break; } }