Display Point for a Location

来源:互联网 发布:浪潮软件股份 编辑:程序博客网 时间:2024/05/05 15:03
Display Point for a Location 
Tags: General Topics

sethbourne
May 14 2007 at 7:41 PM
hi there,
how to point a location (or display an icon) into some location ?
i've did the following, but nothing happens..

SharpMap.Map map = new SharpMap.Map(size);

System.Drawing.PointF p1 = map.WorldToImage(new SharpMap.Geometries.Point(106.798268, -6.202395));
SharpMap.Geometries.Point pt = new SharpMap.Geometries.Point(106.798268, -6.202395);
map.Center = pt;

SarpMap.Layers.VectorLayer VLayer = new SharpMap.Layers.VectorLayer("POINTX");
VLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(new SharpMap.Geometries.Point(p1.X, p1.Y));
VLayer.Style.Fill = new SolidBrush(Color.White);
VLayer.Style.Outline = System.Drawing.Pens.Black;
VLayer.Style.EnableOutline = true;
VLayer.Style.SymbolScale = 1;
VLayer.Style.Symbol = new Bitmap(@"c:/maps/pg_blue.gif");
VLayer.MaxVisible = 0.50;
VLayer.MinVisible = 0;
VLayer.Style.MaxVisible = 0.50;
VLayer.Style.MinVisible = 0;
VLayer.SRID = 4326;
map.Layers.Add(VLayer);

What should I do ?

Thanks

BladeWise
May 14 2007 at 9:12 PM
Have you tried with a
map.ZoomToExtents();map.Refresh();
could sound silly, but without knowing the full code, it's the first idea that came to my mind :P

sethbourne
May 15 2007 at 10:41 AM

BladeWise wrote:
Have you tried with a
map.ZoomToExtents();map.Refresh();
could sound silly, but without knowing the full code, it's the first idea that came to my mind :P


Yes I have, but the icon still not showing... Is it anyway to show bitmap file ?

Thanks

BladeWise
May 15 2007 at 11:04 PM
Uhmmm, I think I found the problem.
I use this code to display a point in my map
SharpMap.Geometries.Point point = new SharpMap.Geometries.Point(12, 12);SharpMap.Data.Providers.GeometryProvider provider = new SharpMap.Data.Providers.GeometryProvider(point);SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("point", provider);layer.Style.Point.Type = SharpMap.Styles.VectorStyle.PointStyle.TypeEnum.Vector;layer.Style.Point.Vector.Type = SharpMap.Styles.VectorStyle.PointStyle.VectorPointStyle.TypeEnum.Circle;layer.Enabled = true;layer.MinVisible = double.Epsilon;layer.Style.Enabled = true;layer.Style.Fill = Brushes.Red;mapBox.Map.Layers.Add(layer);mapBox.Map.Center = point; mapBox.Refresh();

Note that I use the PointStyle patch from Issue Tracker section, but the problem is not related to 0.9 point style implementation.

The problem is that having a single point geometry and calling ZoomToExtents means that Zoom wil be set to 0, have a look at the ZoomToExtents code
public void ZoomToExtents(){this.ZoomToBox(this.GetExtents());} public void ZoomToBox(SharpMap.Geometries.BoundingBox bbox){this._Zoom = bbox.Width; //Set the private center value so we only fire one MapOnViewChange eventif (this.Envelope.Height < bbox.Height)this._Zoom *= bbox.Height / this.Envelope.Height; this.Center = bbox.GetCentroid();}
As you can see if the only object to render is a point, zoom is set to 0.
This means that nothing will be displayed, since having zoom 0 prevents any object from being rendered, as you can see in GetMap function in Map.cs
if (_Layers[i].Enabled && _Layers[i].MaxVisible >= this.Zoom && _Layers[i].MinVisible < this.Zoom)_Layers[i].Render(g, this);

Now, if zoom is set to 0, and your point min zoom is 0.5 (like in your example) obviusly the point will not be rendered... moreover if you set minZoom to 0 again the point will not be rendered, since the current zoom value has to be strictly greater than minZoom... if you set it to a negative value, in my case (with point styles, but I think it's the same with standard source code) render cycle throws an exception while trying to render the symbol (a path)...
So, to view correctly your drawn points you should use the proper zoom without calling ZoomToBox/ZoomToExtents, or modify ZoomToBox like this:
public void ZoomToBox(SharpMap.Geometries.BoundingBox bbox){this._Zoom = bbox.Width; //Set the private center value so we only fire one MapOnViewChange eventif (this.Envelope.Height < bbox.Height)this._Zoom *= bbox.Height / this.Envelope.Height; if(_Zoom=0)_Zoom=1; this.Center = bbox.GetCentroid();}
This way if the zoom value will be set to 0 (it happens when only a point geometry is present), automatically will be restored to 1, allowing you to see the point... btw I would advice about not changing the ZoomToBox function, and simply put another layer (as a background layer or such) to avoid the problem :P

sethbourne
May 16 2007 at 12:27 PM
Thanks Blade, I think i'll use the PointStyle patch, afterall i believe it's much quicker than show an image..

btw, you're using mapbox for refreshing map for windows form.
How about web form, i'm using ajaxMap, how to refresh them after i finnaly adding point to my map ?

Thanks.

BladeWise
May 17 2007 at 1:09 AM
Yes, I'm developing a desktop application, so I use MapBox... I don't know very much about web developing, so I haven't played with AjaxMap control, but I belive the examples show how to refresh a map like using the Refresh method, obviusly it will be a remote call... unfortunally I can't be more precise, since this is not really somethig I'm good at ^^
 
原创粉丝点击