📄 webgis.java
字号:
package mycwebgis;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.*;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.NumberFormat;
import javax.swing.*;
import com.mapinfo.beans.layercontrol.LayerControl;
import com.mapinfo.beans.vmapj.VisualMapJ;
import com.mapinfo.beans.tools.MapToolBar;
import com.mapinfo.beans.tools.RadiusSelectionMapTool;
import com.mapinfo.beans.tools.ViewEntireLayer;
import com.mapinfo.beans.vmapj.RendererParams;
import com.mapinfo.beans.vmapj.ZoomPanel;
import com.mapinfo.beans.theme.AddTheme;
import com.mapinfo.beans.legend.*;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.util.DoublePoint;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class MYCWebGis extends JApplet implements ActionListener,
PropertyChangeListener {
boolean isStandalone = false;
BorderLayout borderLayout1 = new BorderLayout();
// Declare visual beans used in the GUI
VisualMapJ m_visualMapJ = new VisualMapJ();
MapToolBar m_mapToolBar = new MapToolBar();
ZoomPanel m_zoomPanel = new ZoomPanel();
ViewEntireLayer m_viewEntire = new ViewEntireLayer();
// Declare objects used to create thematic shading and legend
AddTheme m_addTheme = new AddTheme();
LegendContainer m_legendContainer = new LegendContainer();
// Define a label that will display the current radius when
// the user selects and drags with the Radius Select tool
JLabel m_lblRadius;
// A button the user can click to display the Add Theme wizard.
JButton m_btnAddTheme;
// A panel used to show/hide thematic user-interface elements
JPanel m_panelTheme;
// A button the user can click to show/hide the Thematic panel.
JButton m_btnShowHide;
// A boolean to remember whether the Thematic panel is currently visible.
boolean m_bThemesVisible;
// A number formatter object, used with the RadiusSelect tool
NumberFormat m_nf = null;
// TODO: You may want to assign the following URL string, to make it match
// the URL you are using as your MapXtremeServlet service, such as:
// m_mapxtremeURL = "http://localhost:8080/mapxtreme480/mapxtreme";
// Or, instead of specifying the URL explicitly here, you can specify it
// in the HTML page that loads the applet (using the 'mapxtremeurl' param).
// If you do not assign it here or in the html page, this applet will
// attempt to build a MapXtreme URL dynamically, using the host and port
// of the applet; however, that method may not be reliable, depending on
// how your server contexts are configured.
static String m_mapxtremeURL = "http://192.168.0.36:8080/mapxtreme480/mapxtreme";
// TODO: Specify a map file name such as "uk.mdf" (if the mdf file is in
// in same directory that the applet was loaded from),
// or an URL to a map file, such as "http://host.com/maps/uk.mdf".
// Or, instead of specifying this URL explicitly here, you can specify it
// in the HTML page that loads the applet (using the 'filetoload' param).
static String m_fileToLoad = "asia.mdf";
static final boolean m_Debug = false; // to print debugging messages, set to true
// define a boolean flag, to prevent displaying two Add Theme wizards at once
boolean m_bDialogActive = false;
String m_addThemeLabel = "Add theme..."; // a static label displayed in the applet
String m_radiusLabel = "Radius:"; // a static label displayed in the applet
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public MYCWebGis() {
}
public void start() {
// Use this method if you want to do any work
// that should be executed after the init method.
// Load a remote map definition file, if one was specified.
// m_fileToLoad might contain a map definition file name such as
// "http://www.mycompany.com/maps/world.mdf"
// or just a filename, such as "world.mdf", in which case we will
// assume the file is in the same directory as the html page which
// loaded this applet.
if (m_fileToLoad.length() > 1) {
// See if it is a complete URL or just "filename.mdf"
if (!m_fileToLoad.startsWith("http")) {
// Just a filename was provided; prepend this page's host etc.
String sDocBase = getDocumentBase().toString();
int iLastSlash = sDocBase.lastIndexOf("/");
m_fileToLoad = sDocBase.substring(0, iLastSlash + 1) +
m_fileToLoad;
}
InputStream isRemoteFile = null;
try {
URL u = new URL(m_fileToLoad);
URLConnection conn = u.openConnection();
isRemoteFile = conn.getInputStream();
// Load the map
m_visualMapJ.getMapJ().loadMapDefinition(isRemoteFile);
/////////////////////////////////////////////20070116
RendererParams rParams = new RendererParams();
rParams.setURL(m_mapxtremeURL);
rParams.setMime("image/gif");
m_visualMapJ.setRendererParams(rParams);
////////////////////////////////////////////
m_visualMapJ.setShowToolTips(true);
m_visualMapJ.setCenter(new DoublePoint(114.07,22.51));
} catch (Exception e) {
//e.printStackTrace();
} finally {
try {
if (isRemoteFile != null) {
isRemoteFile.close();
}
} catch (Exception ee) {
}
}
m_visualMapJ.repaint();
}
} // start method
//Initialize the applet
public void init() {
// If the HTML page specified parameters, use them to
// override our default values.
// See if a MapDef file was specified in the HTML file.
String strParm = getParameter("filetoload");
if (strParm != null && strParm.length() > 1) {
m_fileToLoad = strParm;
}
// See if the HTML page specified text strings to use as button labels,
// etc. (This parameter allows you to reword the text by editing the
// HTML page without having to modify or recompile any Java classes.)
strParm = getParameter("addthemelabel");
if (strParm != null && strParm.length() > 1) {
m_addThemeLabel = strParm;
}
strParm = getParameter("radiuslabel");
if (strParm != null && strParm.length() > 1) {
m_radiusLabel = strParm;
}
// See if the HTML page specified the URL to the MapXtremeServlet
/*
strParm = getParameter("mapxtremeurl");
if (strParm != null && strParm.length() > 1) {
// The HTML page specified an URL, so we will use it.
m_mapxtremeURL = strParm;
} else {
// The HTML file did not specify a MapXtreme URL.
// If the m_mapxtremeURL variable was not explicitly assigned,
// we will make an educated guess at what the URL might be:
if (m_mapxtremeURL == null) {
String sDocBase = getDocumentBase().toString();
// Given the applet's document base, extract just the first
// part of the string -- the "://host:port" portion
// of the string -- so that we can build a MapXtreme URL
// that references the same server.
int lastSlashPosition = sDocBase.indexOf("/", 8);
if (lastSlashPosition != -1) {
m_mapxtremeURL = sDocBase.substring(0, lastSlashPosition)
+ "/mapxtreme480/mapxtreme";
}
}
}
*/
// Print out some information to aid troubleshooting
if (m_Debug) {
System.out.println(" ");
System.out.println("m_fileToLoad =" + m_fileToLoad);
System.out.println("m_mapxtremeURL =" + m_mapxtremeURL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -