📄 mainapplet.java
字号:
package com.oyc.mapxtreme.applet;
import java.awt.Color;
import java.io.IOException;
import javax.swing.JApplet;
import netscape.javascript.JSObject;
import com.oyc.mapxtreme.applet.util.AppletRequest;
/**
* 显示地图的Applet
* @author 三峡大学理学院 欧阳超
*
*/
public class MainApplet extends JApplet {
//默认地图servlet,工程根目录
private String m_servletName = "http://localhost/MyGISApplet/servlet/mapper";
private String m_basePath = "http://localhost/MyGISApplet/";
//画布大小,默认值为500,500
private int mapWidth = 500;
private int mapHeight = 500;
//绘制地图的画布对象
private MapWindow m_map;
//请求对象
private AppletRequest request;
//地图字节数据
byte[] buff = null;
//url变量,每次请求地图servlet时,重新给它赋值
private String m_url = null;
public void init() {
//读取地图servlet url
String servletURL = this.getParameter("servleturl");
if (servletURL != null && servletURL.length() > 0) {
this.m_servletName = servletURL;
}
//读取工程根目录
String basePath = this.getParameter("basePath");
if (basePath != null && basePath.length() > 0) {
this.m_basePath = basePath;
}
//读取画布大小
String strParam = this.getParameter("canvasWidth");
if(strParam != null){
this.mapWidth = Integer.parseInt(strParam);
}
strParam = this.getParameter("canvasHeight");
if(strParam != null){
this.mapHeight = Integer.parseInt(strParam);
}
//读取地图初始视野
strParam = this.getParameter("oldZoom");
if(strParam != null){
MapState.setOldZoom(Double.parseDouble(strParam));
MapState.setCurZoom(Double.parseDouble(strParam));
}
//创建地图窗口
m_map = new MapWindow(this, this.m_servletName, this.mapWidth, this.mapHeight);
m_map.setBounds(0, 0, mapWidth, mapHeight);
m_map.setBackground(Color.lightGray);
// 创建请求对象
request = new AppletRequest();
this.setLayout(null);
add(m_map, null);
m_url = m_servletName + "?method=fullMap";
this.adjustMapBySelf(m_url);
}
/**
* 外部javascript调用,设置当前工具
* @param tool 取值0,1,2,3,4,5,6,代表无工具,放大,缩小,平移,测距离,信息访问,范围查询
*/
public void setCommandTool(int tool){
this.m_map.setCommandTool(tool);
}
/**
* 内部调用,发送get请,校正地图
* @param url 绝对url,形如http://localhost/project/servletName
*/
public void adjustMapBySelf(String url){
try {
buff = request.sendGetRequest(url);
} catch (IOException e) {
e.printStackTrace();
}
m_map.updateMap(this.getToolkit().createImage(buff));
}
/**
* 发送get请求,校正地图,通常由外部javascript调用
* @param url 相对工程根目录的url
*/
public void adjustMap(String url){
this.m_url = this.m_basePath + url;
try {
buff = request.sendGetRequest(m_url);
} catch (IOException e) {
e.printStackTrace();
}
m_map.updateMap(this.getToolkit().createImage(buff));
}
/**
* 发送post请求,校正地图,通常由外部javascript调用
* @param url 相对工程根目录的url
* @param parameter 参数列表
*/
public void adjustMap(String url, String parameter){
this.m_url = this.m_basePath + url;
try {
buff = request.sendPostRequest(m_url, parameter);
} catch (IOException e) {
e.printStackTrace();
}
m_map.updateMap(this.getToolkit().createImage(buff));
}
/**
* 调用外部javascript代码
* @param method 要调用的方法名
*/
public void invokeJavascript(String method){
try {
JSObject.getWindow(this).eval(method);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 初始化地图状态,即将地图视野重新设为起始值
*
*/
public void initMapState(){
MapState.setCurZoom(MapState.getOldZoom());
}
/**
* 清除地图上所有绘的图形
*
*/
public void clearMap(){
this.m_map.clear();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -