private EventLayerSettings _GetMapSettings() { EventLayerSettings result = null; LayerGroup layerGroup = null; var index = -1; if (Map == null) { return(null); } if (Map.Layers == null) { return(null); } foreach (var layer in Map.Layers) { index++; if (!(layer is LayerGroup)) { continue; } layerGroup = (LayerGroup)layer; if (layerGroup.Tag.ToString() != "eventgroup") { continue; } var xmlDoc = new XmlDocument(); var xmlElement = xmlDoc.CreateElement("AVR_Group"); GIS_V4.Serializers.LayerSerializers.LayerGroupSerializer.Instance.Serialize(layerGroup, xmlElement); xmlDoc.AppendChild(xmlElement); result = new EventLayerSettings { LayerSettings = xmlDoc, Position = index }; break; } if (result != null) { //if (layerGroup.LabelLayer != null) m_mapImage.Map.Layers.Remove(layerGroup.LabelLayer); m_mapImage.Map.Layers.Remove(layerGroup); result.MapSettings = EidssMapSerializer.Instance.SerializeAsDocument(m_mapImage.Map, "Map", ((AvrMapControl)m_mapImage.Parent).MapSettings); m_mapImage.Map.Layers.Insert(result.Position, layerGroup); //m_mapImage.Map.Layers.Add(layerGroup.LabelLayer); } return(result); }
//private bool m_SettingsAssigned = false; public void SetMapSettings(EventLayerSettings settings) { //Map settings defenition try { if (settings == null || m_mapImage.Map == null) { return; } if (settings.MapSettings == null && settings.LayerSettings == null) { RefreshMap(); RefreshContent(); return; } //Temporarely remove event layer and event labels LayerGroup eventGroup = null; foreach (LayerGroup layer in m_mapImage.Map.Layers.OfType <LayerGroup>()) { eventGroup = layer; if (eventGroup.Tag.ToString() != "eventgroup") { continue; } eventGroup = layer; break; } if (eventGroup != null) { var pos = m_mapImage.Map.Layers.IndexOf(eventGroup); m_mapImage.Map.Layers.Remove(eventGroup); //Restore map settings if (settings.MapSettings != null) { // TODO: tkobilov - Check all problem types without try-catch try { m_mapImage.Map = EidssMapSerializer.Instance.DeserializeFromDocument(settings.MapSettings); m_mapImage.MapSettings = EidssMapSerializer.Instance.DeserializeSettingsFromDocument(settings.MapSettings); } catch (Exception ex) { Trace.TraceWarning("Can't open map project referenced in MapSettings. Let's use Default map project." + ex); } } //Apply event layer settings and add it to map to specified position if (settings.LayerSettings != null) { //eventGroup = // GIS_V4.Serializers.LayerSerializers.LayerGroupSerializer.Instance.Deserialize( // settings.LayerSettings.GetElementById("AVR_Group")); LayerGroup tmpGroup; tmpGroup = GIS_V4.Serializers.LayerSerializers.LayerGroupSerializer.Instance.Deserialize( (XmlElement)settings.LayerSettings.ChildNodes[0]); foreach (var lyr in tmpGroup.Layers) { if (lyr is GIS_V4.Layers.LabelLayer) { foreach (var _lyr in eventGroup.Layers) { if (_lyr is EventLayer) { continue; } if (_lyr is GIS_V4.Layers.LabelLayer) { if ((lyr.Tag.ToString() == "event_gradient" & _lyr.Tag.ToString() == "event_gradient") || (lyr.Tag.ToString() == "event_chart" & _lyr.Tag.ToString() == "event_chart")) { _lyr.Style = lyr.Style; } _lyr.MaxVisible = lyr.MaxVisible; _lyr.MinVisible = lyr.MinVisible; ((GIS_V4.Layers.LabelLayer)_lyr).Priority = ((GIS_V4.Layers.LabelLayer)lyr).Priority; _lyr.Enabled = lyr.Enabled; } } } if (lyr is EventLayer) { foreach (var _lyr in eventGroup.Layers) { if (_lyr is GIS_V4.Layers.LabelLayer) { continue; } if (_lyr is EventLayer) { if (lyr.Tag.ToString() == "event_gradient" & _lyr.Tag.ToString() == "event_gradient") { if (ThemeIsCompatible(((EventLayer)lyr).Theme, (EventLayer)_lyr)) { // change column name //((EventLayer) lyr).Theme = ReplaceColumnName((EventLayer) lyr); ((EventLayer)_lyr).Theme = ((EventLayer)lyr).Theme; _lyr.LayerName = lyr.LayerName; _lyr.Enabled = lyr.Enabled; _lyr.MaxVisible = lyr.MaxVisible; _lyr.MinVisible = lyr.MinVisible; _lyr.Transparency = lyr.Transparency; } else { MessageForm.Show( "Previously saved settings can’t be applied to Gradient layer. Probably you have already changed gradient field of the AVR layer. Default settings will be applied.", "Uncompatible Gradient Layer Settings", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (lyr.Tag.ToString() == "event_chart" & _lyr.Tag.ToString() == "event_chart") { if (ThemeIsCompatible(((EventLayer)lyr).Theme, (EventLayer)_lyr)) { ((EventLayer)_lyr).Theme = ((EventLayer)lyr).Theme; _lyr.LayerName = lyr.LayerName; _lyr.Enabled = lyr.Enabled; _lyr.MaxVisible = lyr.MaxVisible; _lyr.MinVisible = lyr.MinVisible; _lyr.Transparency = lyr.Transparency; } else { MessageForm.Show( "Previously saved settings can’t be applied to Chart layer. Probably you have already changed the list of chart fields of the AVR layer. Default settings will be applied.", "Uncompatible Chart Layer Settings", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } } } //((EventLayer) eventGroup.Layers[0]).Theme = ((EventLayer) tmpGroup.Layers[0]).Theme; //((EventLayer) eventGroup.Layers[2]).Theme = ((EventLayer) tmpGroup.Layers[1]).Theme; m_mapImage.Map.Layers.Insert(settings.Position, eventGroup); } else { m_mapImage.Map.Layers.Insert(pos, eventGroup); } } } catch (Exception ex) { ErrorForm.ShowError("ErrMapSettingsDefenition", "", ex); } // connect symbol set var strConnection = ConnectionManager.DefaultInstance.ConnectionString; SymbolGallery = new SymbolSet(strConnection); try { UseDynamicData(); } catch (Exception) {} //Refresh map and map content try { RefreshMap(); RefreshContent(); } catch (Exception ex) { ErrorForm.ShowError("ErrRefreshingMap", "", ex); } //m_Settings = _GetMapSettings(); //m_SettingsAssigned = true; }