mapxtreme java 初始化地图

先说下开发的环境,我使用的IDE是eclipse 3.5,mapxtreme java用的是4.7版本的,还需要一个mapxtreme使用的mdf文件

 

那么,让我们开始架设项目吧

一  从新建项目开始,首先我们建立一个项目,然后把mapxtreme java的lib包里面的client,common,server文件夹里面的所有jar文件全部导入到项目里面

二  新建一个index.jsp,然后再建一个名字叫MapServer的servlet,建好后,项目如下图所示

 

mapxtreme java 初始化地图

 

在index.jsp页面的添加一个img组件,src直接链接到servlet上面去,具体内容如下:

 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<img alt="" src="http://localhost:9090/mymap/MapServer" />
</body>
</html>
  

 

servlet的具体内容如下:

try {
			//得到mapj对象
			MapJ mapj = new MapJ();
			//加载mdf文件
			mapj.loadMapDefinition("c://test.mdf");
			//设置地图的大小为800*600
			mapj.setDeviceBounds(new DoubleRect(0, 0, 800d, 600d));
			//得到项目的相对路径
			String path = request.getContextPath();
			String url = request.getScheme() + "://" + request.getServletPath() + ":" + request.getServerPort() + path + "/mapxtreme";
			//获得和设置地图的图像类型
			ImageRequestComposer composer = ImageRequestComposer.create(mapj, ImageRequestComposer.MAX_COLORS_TRUECOLOR, Color.white, "image/gif");
			//渲染器进行渲染
			MapXtremeImageRenderer imageRenderer = new MapXtremeImageRenderer(url);
			imageRenderer.render(composer);
			response.reset();
			response.setContentType("image/gif");
			//输出文件
			imageRenderer.toStream(response.getOutputStream());
			imageRenderer.dispose();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally{
			
		}

 

最后,在web.xml文件里面加上这段代码,表示mapxtreme java的工具的配置

 

<!-- 地图配置 -->
	<!--mapxtreme地图服务器的servlet的配置-->
	<servlet>
		<servlet-name>mapxtreme</servlet-name>
		<servlet-class>
			com.mapinfo.mapxtreme.MapXtremeServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- internal servlets which are called by MapXtremeServlet -->
	<!-- these servlets should not be called directly!          -->
	<servlet>
		<servlet-name>mxtj_image</servlet-name>
		<servlet-class>
			com.mapinfo.mapxtreme.ImageHandlerServlet
		</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>
	<servlet>
		<servlet-name>mxtj_metadata</servlet-name>
		<servlet-class>
			com.mapinfo.mapxtreme.MetadataHandlerServlet
		</servlet-class>
		<load-on-startup>3</load-on-startup>
	</servlet>
	<servlet>
		<servlet-name>mxtj_vector</servlet-name>
		<servlet-class>
			com.mapinfo.mapxtreme.VectorHandlerServlet
		</servlet-class>
		<load-on-startup>4</load-on-startup>
	</servlet>
	<!-- FineReport -->
	<servlet>
		<servlet-name>ReportServer</servlet-name>
		<servlet-class>com.fr.web.ReportServlet</servlet-class>
		<load-on-startup>0</load-on-startup>
	</servlet>

	<!-- servlet URL mappings -->
	<servlet-mapping>
		<servlet-name>ReportServer</servlet-name>
		<url-pattern>/ReportServer</url-pattern>
	</servlet-mapping>
	<!-- mapxtreme -->
	<servlet-mapping>
		<servlet-name>mapxtreme</servlet-name>
		<url-pattern>/servlet/mapxtreme</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>mapxtreme</servlet-name>
		<url-pattern>/mapxtreme</url-pattern>
	</servlet-mapping>

 

运行项目,就能在index.jsp页面上面看到地图了

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(java,exception,servlet,Servlets,String,colors)