/// <summary> /// Opens the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="map">The map.</param> /// <param name="layer">The layer.</param> public static void Open(string fileName, IMap map, Layer layer) { Contract.Requires(!String.IsNullOrEmpty(fileName), "fileName is null or empty."); Contract.Requires(map != null, "map is null."); Contract.Requires(layer != null, "featureLayer is null."); string lblFile = Path.ChangeExtension(fileName, "lbl"); if (File.Exists(lblFile) && layer is IFeatureLayer) { try { dynamic parser = DynamicXMLNode.Load(lblFile); DeserializeLabels(parser.Labels, map, layer as IFeatureLayer); } catch (RuntimeBinderException ex) { Trace.WriteLine(ex.Message); } } string mwsrFile = Path.ChangeExtension(fileName, "mwsr"); if (File.Exists(mwsrFile)) { try { dynamic parser = DynamicXMLNode.Load(mwsrFile); DeserializeLayer(parser.Layer, map, layer); } catch (RuntimeBinderException ex) { Trace.WriteLine(ex.Message); } } string mwleg = Path.ChangeExtension(fileName, "mwleg"); if (File.Exists(mwleg) && layer is MapImageLayer) { try { dynamic parser = DynamicXMLNode.Load(mwleg); DeserializeLegend(parser.GridColoringScheme, map, layer); } catch (RuntimeBinderException ex) { Trace.WriteLine(ex.Message); } } }
private void ShowPropertiesClick(object sender, EventArgs e) { // Allow subclasses to prevent this class from showing the default dialog HandledEventArgs result = new HandledEventArgs(false); OnShowProperties(result); if (result.Handled) return; if (_propertyDialogProvider == null) return; _editCopy = this.Copy(); CopyProperties(_editCopy); // for some reason we are getting blank layers during edits, this tries to fix that _propertyDialogProvider.ShowDialog(_editCopy); LayerManager.DefaultLayerManager.ActiveProjectLayers = new List<ILayer>(); }
/// <summary> /// Deserializes the layer properties. /// </summary> /// <param name="layer">The layer.</param> /// <param name="mapLayer">The map layer.</param> internal static void DeserializeLayerProperties(dynamic layer, Layer mapLayer) { mapLayer.LegendText = layer["Name"]; mapLayer.IsVisible = Convert.ToBoolean(layer["Visible"]); mapLayer.IsExpanded = Convert.ToBoolean(layer["Expanded"]); try { mapLayer.UseDynamicVisibility = Convert.ToBoolean(layer.DynamicVisibility["UseDynamicVisibility"]); mapLayer.DynamicVisibilityWidth = Convert.ToDouble(layer.DynamicVisibility["Scale"]); } catch (RuntimeBinderException) { // No DynamicVisibility node, ignore that. } }
/// <summary> /// This allows overriding layers to handle any memory cleanup. /// </summary> /// <param name="disposeManagedResources">True if managed resources should be set to null.</param> protected virtual void Dispose(bool disposeManagedResources) { if (_isDisposed) { return; } if (disposeManagedResources) { LayerSelected = null; ZoomToLayer = null; ShowProperties = null; FinishedLoading = null; SelectionChanged = null; base.ContextMenuItems = null; MyExtent = null; base.LegendText = null; _progressHandler = null; _progressMeter = null; _invalidatedRegion = null; _mapFrame = null; _propertyDialogProvider = null; // Since the InnerDataset likely contains unmanaged memory constructs, dispose of it here. if (_dataSet != null) { _dataSet.UnlockDispose(); if (!_dataSet.IsDisposeLocked) { _dataSet.Dispose(); } _dataSet = null; } if (_editCopy != null) { _editCopy.Dispose(); _editCopy = null; } } _isDisposed = true; }
private static void DeserializeLayer(dynamic layer, IMap map, Layer featureLayer) { LegacyLayerType typeOfLayer = (LegacyLayerType)Enum.ToObject(typeof(LegacyLayerType), Convert.ToInt32(layer["Type"])); switch (typeOfLayer) { case LegacyLayerType.Grid: break; case LegacyLayerType.Image: break; case LegacyLayerType.Invalid: throw new ArgumentException("The LayerType is an invalid layer type and cannot be loaded."); case LegacyLayerType.LineShapefile: LegacyDeserializer.DeserializeLayer(layer, featureLayer as MapLineLayer); break; case LegacyLayerType.PointShapefile: LegacyDeserializer.DeserializeLayer(layer, featureLayer as MapPointLayer); break; case LegacyLayerType.PolygonShapefile: LegacyDeserializer.DeserializeLayer(layer, featureLayer as MapPolygonLayer); break; default: throw new NotImplementedException("That LayerType is not supported."); } LegacyDeserializer.DeserializeLayerProperties(layer, featureLayer); }
private static void DeserializeLegend(dynamic layer, IMap map, Layer imageLayer) { //var polyLayer = imageLayer as MapImageLayer; ////var imageSymbolizer = new ImageSymbolizer(); ////var outlineColor = LegacyDeserializer.GetColor(layer.ShapeFileProperties["OutLineColor"]); ////var outlineWidth = Convert.ToDouble(layer.ShapeFileProperties["LineOrPointSize"]); ////polySymbolizer.SetOutline(outlineColor, outlineWidth); ////if (Convert.ToBoolean(layer.ShapeFileProperties["DrawFill"])) ////{ //// System.Drawing.Color color = LegacyDeserializer.GetColor(layer.ShapeFileProperties["Color"]); //// float transparency = Convert.ToSingle(layer.ShapeFileProperties["TransparencyPercent"]); //// color = color.ToTransparent(transparency); //// polySymbolizer.SetFillColor(color); ////} ////else ////{ //// polySymbolizer.SetFillColor(Color.Transparent); ////} ////layer.Symbolizer = imageSymbolizer; //var j = layer.Break; //try //{ // int fieldIndex = Convert.ToInt32(layer.ShapeFileProperties.Legend["FieldIndex"]); // // we have to clear the categories or the collection ends up with a default item // polyLayer.Symbology.Categories.Clear(); // //foreach (var colorBreak in layer.ShapeFileProperties.Legend.ColorBreaks.Elements()) // //{ // // PolygonCategory category; // // string startValue = colorBreak["StartValue"]; // // string endValue = colorBreak["EndValue"]; // // if (startValue == endValue) // // { // // category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["StartColor"]), 0); // // category.FilterExpression = String.Format("[{0}] = '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue); // // category.LegendText = startValue; // // } // // else // // { // // category = new PolygonCategory(LegacyDeserializer.GetColor(colorBreak["StartColor"]), LegacyDeserializer.GetColor(colorBreak["EndColor"]), 0, GradientType.Linear, outlineColor, outlineWidth); // // category.FilterExpression = String.Format("'{2}' >= [{0}] >= '{1}'", polyLayer.DataSet.DataTable.Columns[fieldIndex].ColumnName, startValue, endValue); // // category.LegendText = String.Format("{0} - {1}", startValue, endValue); ; // // } // // category.LegendText = startValue; // // category.LegendItemVisible = Convert.ToBoolean(colorBreak["Visible"]); // // polyLayer.Symbology.AddCategory(category); // //} // // it took too a lot of work to figure out that we would need to do this... // polyLayer.ApplyScheme(polyLayer.Symbology); //} //catch (RuntimeBinderException) //{ // // ignore and continue. // // this means the legend is not available. //} }