private void ExchangeElement(LayerListItem dragedEntity, LayerListItem targetEntity) { var dragEntityParent = dragedEntity.Parent; var targetEntityParent = targetEntity.Parent; if (dragEntityParent == targetEntityParent) { var targetStyleItem = targetEntityParent as StyleLayerListItem; if (targetStyleItem != null) { var targetStyle = ((StyleLayerListItem)targetEntity); var dragedStyle = ((StyleLayerListItem)dragedEntity); if (targetStyle != null && dragedStyle != null) { int targetStyleIndex = targetStyleItem.Children.IndexOf(targetStyle); int dragedStyleIndex = targetStyleItem.Children.IndexOf(dragedStyle); targetStyleItem.Children[targetStyleIndex] = dragedStyle; targetStyleItem.Children[dragedStyleIndex] = targetStyle; targetStyleItem.UpdateConcreteObject(); } } RearrangeStylesInZoomLevel(dragedEntity, targetEntity); var componentStyleEntity = LayerListHelper.FindItemInLayerList <CompositeStyle>(dragedEntity); if (componentStyleEntity != null) { var bitmapSource = new BitmapImage(); bitmapSource = ((StyleLayerListItem)componentStyleEntity).GetPreviewSource(23, 23) as BitmapImage; componentStyleEntity.PreviewImage = new Image { Source = bitmapSource }; var featureLayer = componentStyleEntity.Parent.ConcreteObject as FeatureLayer; } dragedEntity.IsSelected = true; TileOverlay overlay = LayerListHelper.FindMapElementInLayerList <TileOverlay>(dragedEntity); if (overlay != null) { overlay.Invalidate(); } } }
public static void EditStyle(LayerListItem selectedLayerListItem) { var componentStyleItem = LayerListHelper.FindItemInLayerList <CompositeStyle>(selectedLayerListItem) as StyleLayerListItem; if (componentStyleItem != null) { var componentStyle = componentStyleItem.ConcreteObject as CompositeStyle; var styleArguments = new StyleBuilderArguments(); styleArguments.FeatureLayer = componentStyleItem.Parent.ConcreteObject as FeatureLayer; var featureLayerPlugin = GisEditor.LayerManager.GetLayerPlugins(styleArguments.FeatureLayer.GetType()).FirstOrDefault() as FeatureLayerPlugin; if (featureLayerPlugin != null) { styleArguments.AvailableStyleCategories = StylePluginHelper.GetStyleCategoriesByFeatureLayer(styleArguments.FeatureLayer); int from = 0; int to = GisEditor.ActiveMap.ZoomLevelSet.CustomZoomLevels.Count; if (!string.IsNullOrEmpty(componentStyleItem.ZoomLevelRange)) { var array = componentStyleItem.ZoomLevelRange.Split(" to ".ToArray(), StringSplitOptions.RemoveEmptyEntries); if (array.Length == 2) { int.TryParse(array[0].Replace("(", "").Trim(), out from); int.TryParse(array[1].Replace(")", "").Trim(), out to); } } styleArguments.FromZoomLevelIndex = from; styleArguments.ToZoomLevelIndex = to; styleArguments.AppliedCallback = new Action <StyleBuilderResult>((styleResults) => { if (!styleResults.Canceled) { var resultStyle = styleResults.CompositeStyle as CompositeStyle; var count = GisEditor.ActiveMap.ZoomLevelSet.GetZoomLevels().Count; for (int i = 0; i < count; i++) { var customStyles = styleArguments.FeatureLayer.ZoomLevelSet.CustomZoomLevels[i].CustomStyles; if (i >= styleResults.FromZoomLevelIndex - 1 && i < styleResults.ToZoomLevelIndex) { if (!customStyles.Contains(componentStyle)) { customStyles.Add(componentStyle); } componentStyle.Styles.Clear(); componentStyle.Name = resultStyle.Name; foreach (var item in resultStyle.Styles) { componentStyle.Styles.Add(item); } } else { customStyles.Remove(componentStyle); } } foreach (var overlay in GisEditor.ActiveMap.GetOverlaysContaining(styleArguments.FeatureLayer)) { if (overlay.MapArguments != null) { overlay.Invalidate(); } } GisEditor.UIManager.BeginRefreshPlugins(new RefreshArgs(styleResults, RefreshArgsDescription.EditStyleDescription)); } }); var styleItems = new Collection <StyleLayerListItem>(); foreach (var style in componentStyle.Styles) { var item = GisEditor.StyleManager.GetStyleLayerListItem(style); if (item != null) { styleItems.Add(item); } } var clonedStyleItems = new Collection <StyleLayerListItem>(); var clonedCompositeStyle = componentStyle.CloneDeep() as CompositeStyle; styleArguments.StyleToEdit = clonedCompositeStyle; foreach (var style in clonedCompositeStyle.Styles) { var item = GisEditor.StyleManager.GetStyleLayerListItem(style); if (item != null) { clonedStyleItems.Add(item); } } object selectedClonedObject = FindSelectedObject(styleItems.ToList(), clonedStyleItems.ToList(), selectedLayerListItem.ConcreteObject); styleArguments.FillRequiredColumnNames(); styleArguments.SelectedConcreteObject = selectedClonedObject; var styleBuilder = GisEditor.StyleManager.GetStyleBuiderUI(styleArguments); if (styleBuilder.ShowDialog().GetValueOrDefault()) { styleArguments.AppliedCallback(styleBuilder.StyleBuilderResult); } } } }