/// <summary> /// Function to search for a layer in this collection by its name /// </summary> /// <param name="layerName">The name of the layer to search for</param> /// <returns>The layer if found, otherwise <value>null</value></returns> public ILayer GetLayerByName(string layerName) { lock (this) { LayerCollection lays = this; return(GetLayerByNameInternal(layerName, lays)); } }
/// <summary> /// Method to add all layers of <paramref name="other"/> to this collection /// </summary> /// <param name="other">A collection of layers</param> public void AddCollection(LayerCollection other) { lock (this) { foreach (var lay in other) { Add(lay); } } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="staticLayers">Layer collection that holds static layers</param> public VariableLayerCollection(LayerCollection staticLayers) { _staticLayers = staticLayers; if (_timer == null) { _timer = new Timer(); _timer.Interval = 500; _timer.Elapsed += new ElapsedEventHandler(TimerElapsed); } }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="variableLayers">Layer collection that holds layers with data sources updating frequently</param> public VariableLayerCollection(LayerCollection variableLayers) { _variableLayers = variableLayers; if (_handler == null) { //_timer = new Timer(); //_timer.Interval = 500; //_timer.Elapsed += new ElapsedEventHandler(TimerElapsed); } }
/// <summary> /// Returns a cloned copy of the LayerCollection (the layer instances are the same as in the original Collection) /// </summary> /// <returns></returns> public LayerCollection Clone() { lock (this) { LayerCollection newColl = new LayerCollection(); foreach (ILayer lay in this) { newColl.Add(lay); } return(newColl); } }
private static void TestLayerPresent(LayerCollection layers, ILayer newLayer) { foreach (ILayer layer in layers) { int comparison = String.Compare(layer.LayerName, newLayer.LayerName, StringComparison.CurrentCultureIgnoreCase); if (comparison == 0) { throw new DuplicateLayerException(newLayer.LayerName); } } }
/// <summary> /// Returns a cloned copy of the LayerCollection /// </summary> /// <remarks> /// The layer instances are the same as in the original collection, however if a layer implements ICloneable this could not be true. /// </remarks> /// <returns></returns> public LayerCollection Clone() { lock (this) { var newColl = new LayerCollection(); foreach (ILayer lay in this) { var cloneable = lay as ICloneable; if (cloneable != null) { newColl.Add((ILayer)cloneable.Clone()); } else { newColl.Add(lay); } } return(newColl); } }
private static void AdjustRotation(LayerCollection lc, float angle) { foreach (ILayer layer in lc) { if (layer is VectorLayer) ((VectorLayer) layer).Style.SymbolRotation = -angle; else if (layer is LabelLayer) ((LabelLayer)layer).Style.Rotation = -angle; } }
private Image GetMap(Map map, LayerCollection layers, LayerCollectionType layerCollectionType, Envelope extent) { try { var width = Width; var height = Height; if ((layers == null || layers.Count == 0 || width <= 0 || height <= 0)) { if (layerCollectionType == LayerCollectionType.Background) return new Bitmap(1, 1); return null; } var retval = new Bitmap(width, height); using (var g = Graphics.FromImage(retval)) { g.Clear(Color.Transparent); map.RenderMap(g, layerCollectionType, false, true); } /*if (layerCollectionType == LayerCollectionType.Variable) retval.MakeTransparent(_map.BackColor); else if (layerCollectionType == LayerCollectionType.Static && map.BackgroundLayer.Count > 0) retval.MakeTransparent(_map.BackColor);*/ return retval; } catch (Exception ee) { Logger.Error("Error while rendering map", ee); if (layerCollectionType == LayerCollectionType.Background) return new Bitmap(1, 1); return null; } }
/// <summary> /// Initializes a new map /// </summary> /// <param name="size">Size of map in pixels</param> public Map(Size size) { Size = size; Layers = new LayerCollection(); _variableLayers = new VariableLayerCollection(_Layers); BackColor = Color.Transparent; _MaximumZoom = double.MaxValue; _MinimumZoom = 0; _MapTransform = new Matrix(); MapTransformInverted = new Matrix(); _Center = new Point(0, 0); _Zoom = 1; _PixelAspectRatio = 1.0; }
private static void TestLayerPresent(LayerCollection layers, ILayer newLayer) { foreach (ILayer layer in layers) { int comparison = String.Compare(layer.LayerName, newLayer.LayerName, StringComparison.CurrentCultureIgnoreCase); if (comparison == 0) throw new DuplicateLayerException(newLayer.LayerName); } }
/// <summary> /// Method to create a legend item for a layer collection /// </summary> /// <param name="settings">The legend</param> /// <param name="title">The title</param> /// <param name="layerCollection">The layer collection</param> /// <returns>The created legend item</returns> protected virtual ILegendItem Create(ILegendSettings settings, string title, LayerCollection layerCollection) { var res = new LegendItem { Indentation = LegendSettings.Indentation, Label = title, LabelFont = LegendSettings.HeaderFont, LabelBrush = LegendSettings.ForeColor, Expanded = true, Padding = LegendSettings.Padding, //Parent = legend.Root, Item = layerCollection }; for (var i = layerCollection.Count-1; i >= 0; i--) { var layer = layerCollection[i]; var item = Create(settings, layer); res.SubItems.Add(item); } return res; }
/// <summary> /// Initializes a new map /// </summary> /// <param name="size">Size of map in pixels</param> public Map(Size size) { Size = size; _Layers = new LayerCollection(); _backgroundLayers = new LayerCollection(); _backgroundLayers.ListChanged += _Layers_ListChanged; //_Layers.ListChanged += new System.ComponentModel.ListChangedEventHandler(_Layers_ListChanged); _variableLayers = new VariableLayerCollection(_Layers); BackColor = Color.Transparent; _MaximumZoom = double.MaxValue; _MinimumZoom = 0; _MapTransform = new Matrix(); MapTransformInverted = new Matrix(); _Center = new Point(0, 0); _Zoom = 1; _PixelAspectRatio = 1.0; }
private Image GetMap(Map map, LayerCollection layers, LayerCollectionType layerCollectionType, BoundingBox extent) { if ((layers == null || layers.Count == 0 || Width == 0 || Height == 0)) { if (layerCollectionType == LayerCollectionType.Background) return new Bitmap(1, 1); return null; } var retval = new Bitmap(Width, Height); using(var g = Graphics.FromImage(retval)) { map.RenderMap(g, layerCollectionType, false); } if (layerCollectionType == LayerCollectionType.Variable) retval.MakeTransparent(_map.BackColor); return retval; }
/// <summary> /// Initializes a new map /// </summary> /// <param name="size">Size of map in pixels</param> public Map(Size size) { _mapViewportGuard = new MapViewPortGuard(size, 0d, Double.MaxValue); Factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(_srid); _layers = new LayerCollection(); _backgroundLayers = new LayerCollection(); _variableLayers = new VariableLayerCollection(_layers); BackColor = Color.Transparent; _mapTransform = new Matrix(); MapTransformInverted = new Matrix(); _center = new Point(0, 0); _zoom = 1; WireEvents(); if (_logger.IsDebugEnabled) _logger.DebugFormat("Map initialized with size {0},{1}", size.Width, size.Height); }
private static void ExtendBoxForCollection(LayerCollection layersCollection, ref Envelope bbox) { foreach (var l in layersCollection) { //Tries to get bb. Fails on some specific shapes and Mercator projects (World.shp) Envelope bb; try { bb = l.Envelope; } catch (Exception) { bb = new Envelope(new Coordinate(-20037508.342789, -20037508.342789), new Coordinate(20037508.342789, 20037508.342789)); } if (bbox == null) bbox = bb; else { //FB: bb can be null on empty layers (e.g. temporary working layers with no data objects) if (bb != null) bbox.ExpandToInclude(bb); } } }
/* protected void map_Click(object sender, EventArgs e) { //Set center of the map to where the client clicked Point ClickPnt = ajaxMap.Map.ImageToWorld(new System.Drawing.Point(e.X, e.Y)); ; SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet(); //Execute click-query (ajaxMap.Map.Layers[0] as SharpMap.Layers.VectorLayer).DataSource.ExecuteIntersectionQuery(ClickPnt, ds); if (ds.Tables.Count > 0) //We have a result { clickresults.DataSource = ds.Tables[0]; clickresults.DataBind(); //Add clicked features to a selection layer SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection"); laySelected.DataSource = new GeometryProvider(ds.Tables[0]); laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); ajaxMap.Map.Layers.Add(laySelected); } GenerateMap(); }*/ private void createCheckboxes(LayerCollection LayerList) { Int32 i = 0; foreach (SharpMap.Layers.Layer myLayer in LayerList) { CheckBox chk = new CheckBox(); chk.ID = "chk" + i.ToString(); chk.Checked = true; if (myLayer.GetType() == typeof(SharpMap.Layers.LabelLayer)) setLabel(chk, (myLayer as SharpMap.Layers.LabelLayer)); if (myLayer.GetType() == typeof(SharpMap.Layers.LayerGroup)) { chk.Attributes.Add("OnClick", "SharpMap_HiddenLayers(ajaxMapObj);togLayerGroup(this, '" + chk.ID.Substring(3) + "');test(ajaxMapObj);"); pnlLayers.Controls.Add(chk); HtmlImage exCol = new HtmlImage(); exCol.ID = "img" + i.ToString(); exCol.Src = "images/minus.gif"; exCol.Style.Add("cursor", "hand"); exCol.Attributes.Add("onclick", "expandIt('" + chk.ID.Substring(3) + "');"); pnlLayers.Controls.Add(exCol); Label myLabel = new Label(); myLabel.Text = " " + myLayer.LayerName; pnlLayers.Controls.Add(myLabel); } else { chk.Attributes.Add("OnClick", "SharpMap_HiddenLayers(ajaxMapObj);test(ajaxMapObj);"); chk.Text = myLayer.LayerName; pnlLayers.Controls.Add(chk); DropDownList listFill = new DropDownList(); DropDownList listLine = new DropDownList(); listFill.ID = "ColorPicker1" + myLayer.LayerName; listLine.ID = "ColorPicker2" + myLayer.LayerName; Type colorType = typeof(System.Drawing.Color); // We take only static property to avoid properties like Name, IsSystemColor ... PropertyInfo[] propInfos = colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public); foreach (PropertyInfo propInfo in propInfos) { listFill.Items.Add(propInfo.Name); listLine.Items.Add(propInfo.Name); } //pnlLayers.Controls.Add(new LiteralControl("<br>")); //pnlLayers.Controls.Add(new LiteralControl("Fill Color:")); listFill.SelectedValue = ((SolidBrush)((SharpMap.Styles.VectorStyle)myLayer.Style).Fill).Color.Name; listFill.Attributes.Add("onChange", "javascript:test(ajaxMapObj)"); listFill.Attributes.Add("tag", myLayer.LayerName); pnlLayers.Controls.Add(listFill); //pnlLayers.Controls.Add(new LiteralControl("<br>")); //pnlLayers.Controls.Add(new LiteralControl("Line Color:")); listLine.SelectedValue = ((SharpMap.Styles.VectorStyle)myLayer.Style).Line.Color.Name; listLine.Attributes.Add("onChange", "javascript:test(ajaxMapObj)"); listLine.Attributes.Add("tag", myLayer.LayerName); pnlLayers.Controls.Add(listLine); } pnlLayers.Controls.Add(new LiteralControl("<br>")); if (myLayer.GetType() == typeof(SharpMap.Layers.LayerGroup)) recursiveCheck(pnlLayers, myLayer, i, chk.ID.ToString()); i += 1; } }
private static void ExtendBoxForCollection(LayerCollection layersCollection, ref BoundingBox bbox) { foreach (ILayer l in layersCollection) { //Tries to get bb. Fails on some specific shapes and Mercator projects (World.shp) BoundingBox bb; try { bb = l.Envelope; } catch (Exception) { bb = new BoundingBox(-20037508.342789, -20037508.342789, 20037508.342789, 20037508.342789); } if (bb != null) bbox = bbox == null ? bb : bbox.Join(bb); } }
private Image GetMap(LayerCollection layers, LayerCollectionType layerCollectionType) { if ((layers == null || layers.Count == 0 || Width == 0 || Height == 0)) { if (layerCollectionType == LayerCollectionType.Background) return new Bitmap(1, 1); return null; } var retval = new Bitmap(Width, Height); Graphics g = Graphics.FromImage(retval); _map.RenderMap(g, layerCollectionType, false); g.Dispose(); if (layerCollectionType == LayerCollectionType.Variable) retval.MakeTransparent(_map.BackColor); return retval; }
/// <summary> /// Creates an instance of this class /// </summary> /// <param name="staticLayers">Layer collection that holds static layers</param> public VariableLayerCollection(LayerCollection staticLayers) { _staticLayers = staticLayers; _timer.Elapsed += new ElapsedEventHandler(TimerElapsed); }