发表用户:LongRiver
收集整理:James.Liu
相关讨论:http://www.mygis.com.cn/forum/dispbbs.asp?BoardID=11&id=3696
信息原始来源:不祥

文章标题:MapXtreme for Java开发专题七:怎样实现GPS监控


MapXtreme的新版本中提供了一个新的CompositeRender。通过它可以仅仅将某些需要改变的图层重画刷新,这样MapXtreme可以将图层分为静态图层和动态图层,前者只画一次并保存为本地的栅格图,而每一个处理输出地图请求时只重画动态图层。这样就可以实现诸如地理编码、车辆监控之类的应用。

如:

地理编码:

创建一个临时图层(Annotaion)用来保存地理编码的点符号,通过CompositeRender可以在生成绘出地图后再画点符号,符号在地图(包括地图标注)的上面。如果不使用CompositeRender,标注总是最后绘制,因此显示的编码点符号会位于标注的下面。

车辆监控:

象GPS监控之类的应用,可以将地图绘制一次,每次GPS数据更新时,只重画车辆的位置。

 

使用CompositeRender的注意事项:

• 静态图层会保存在本地,需要占用内存,如640 x 480的图像需要至少2.7 MB;

• 改变视野时,静态图层可能变形,如线出现锯齿;

• 改变地图中心时,静态图层的边缘不能完成平移,这时必须重新生成静态图层。

       示例:

       下面代码演示了如何在地图上显示移动目标:

try {

// ASSUMPTIONS:

// The variable mapj is of type MapJ and has loaded a map

// The variable req is of type HttpServletRequest

// The variable res is of type HttpServletResponse

// The variable dp is of type DoublePoint

// Add annotation layer - this layer will consist of one image symbol to "animate"

AnnotationTableDescHelper atdh = new AnnotationTableDescHelper("Animation_Layer");

AnnotationDataProviderHelper adph = new AnnotationDataProviderHelper();

LocalDataProviderRef ldpr = new LocalDataProviderRef(adph);

//Add the annotation layer

Layer animate_layer = mapj.getLayers().insert(ldpr, atdh,0, "Animation_Layer");

//Create the rendition for the point

Rendition r = RenditionImpl.getDefaultRendition();

r.setvalue(Rendition.SYMBOL_MODE,Rendition.SymbolMode.IMAGE);

r.setvalue(Rendition.SYMBOL_URL, "file:///C:/images/car.gif");

//Create the point

FeatureFactory ff = mapj.getFeatureFactory();

//An array containing a single int Attribute

Attribute[] aAIntAttribute = {new Attribute(33)};

//create a new Primary Key an an integer

PrimaryKey pkey = new PrimaryKey(aAIntAttribute);

Feature f = ff.createPoint(dp, r, aAIntAttribute, pkey);

PrimaryKey pk = animate_layer.addFeature(f);

// Create the ImageRequestComposer

ImageRequestComposer imageRC =ImageRequestComposer.create(mapj, 256, Color.blue,"image/gif");

/*

Create the composite renderer

Render the image

Stream the image back to the client

*/

CompositeRenderer compositeRenderer = new CompositeRenderer("http://localhost:8080/mapxtreme40/servlet/mapxtreme";, 0);

compositeRenderer.render(imageRC);

ServletOutputStream sos = res.getOutputStream();

compositeRenderer.toStream(sos);

//Set this attribute to false so that the bottom image is not rendered next time

compositeRenderer.setRedrawBottom(false);

} catch(Exception e) {

//Take appropriate error handling steps

}