Display Point for a Location

用户尝试在地图上显示一个位置图标,但遇到了图标不显示的问题。通过调整ZoomToExtents方法解决了该问题,确保了单个点也能正确显示。
Display Point for a Location 
Tags: General Topics

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

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

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

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 event
	if (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 event
	if (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

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.

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 ^^
 
代码转载自:https://pan.quark.cn/s/7f503284aed9 Hibernate的核心组件总数达到五个,具体包括:Session、SessionFactory、Transaction、Query以及Configuration。 这五个核心组件在各类开发项目中都具有普遍的应用性。 借助这些组件,不仅可以高效地进行持久化对象的读取与存储,还能够实现事务管理功能。 接下来将通过图形化的方式,逐一阐述这五个核心组件的具体细节。 依据所提供的文件内容,可以总结出以下几个关键知识点:### 1. SSH框架详细架构图尽管标题提及“SSH框架详细架构图”,但在描述部分并未直接呈现关于SSH的详细内容,而是转向介绍了Hibernate的核心接口。 然而,在此我们可以简要概述SSH框架(涵盖Spring、Struts、Hibernate)的核心理念及其在Java开发中的具体作用。 #### Spring框架- **定义**:Spring框架是一个开源架构,其设计目标在于简化企业级应用的开发流程。 - **特点**: - **分层结构**:该框架允许开发者根据实际需求选择性地采纳部分组件,而非强制使用全部功能。 - **可复用性**:Spring框架支持创建可在不同开发环境中重复利用的业务逻辑和数据访问组件。 - **核心构成**: - **核心容器**:该部分包含了Spring框架的基础功能,其核心在于`BeanFactory`,该组件通过工厂模式运作,并借助控制反转(IoC)理念,将配置和依赖管理与具体的应用代码进行有效分离。 - **Spring上下文**:提供一个配置文件,其中整合了诸如JNDI、EJB、邮件服务、国际化支持等企业级服务。 - **Spring AO...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值