webgis.java
来自「MapXtreme for java,MapInfo公司的地图引擎。」· Java 代码 · 共 425 行 · 第 1/2 页
JAVA
425 行
System.out.println(" ");
}
// Set up the applet GUI
// Define a panel that will contain the map and the toolbar.
// Note that we are adding the MapToolBar and VisualMapJ objects
// to the same panel; this is important, because it allows the
// two objects to be automatically associated with each other.
JPanel panelMap = new JPanel();
panelMap.setLayout(new BorderLayout());
panelMap.add(m_mapToolBar, BorderLayout.NORTH);
m_mapToolBar.setFloatable(false);
// Add a Radius Select tool to the toolbar, as a demonstration
// of how to listen for property changed events. (We will
// listen for real-time changes to the circle radius as the
// user drags the mouse.)
RadiusSelectionMapTool radius = new RadiusSelectionMapTool();
m_mapToolBar.add(radius);
// Add a ViewEntireLayer button to the toolbar. The user clicks
// the button to launch the View Entire Layer dialog.
try {
m_viewEntire.setVisualMapJ(m_visualMapJ);
m_mapToolBar.add(m_viewEntire);
} catch (Exception e) {
//e.printStackTrace();
}
// For purely cosmetic reasons, we prefer to have the Layer Control
// be the last icon on the toolbar. Since we just added two new
// items to the toolbar, we will take extra steps to move the
// Layer Control to the end:
LayerControl layercontrol = m_mapToolBar.getLayerControl();
if (layercontrol != null) {
m_mapToolBar.removeLayerControl(layercontrol);
m_mapToolBar.add(layercontrol);
}
panelMap.add(m_visualMapJ, BorderLayout.CENTER);
// Define a panel that will contain a zoom width text field and a
// corresponding label, as well as a "show/hide thematic options" button
JPanel panelOptions = new JPanel();
panelOptions.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
panelOptions.setLayout(new BoxLayout(panelOptions, BoxLayout.X_AXIS));
// Add a ZoomPanel, which contains a text field where the user
// can see or modify the map's current zoom width
m_zoomPanel.setVisualMapJ(m_visualMapJ);
// Place a border around the ZoomPanel to fine-tune its
// alignment, relative to other items on the status bar
m_zoomPanel.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
panelOptions.add(m_zoomPanel);
// Add some space between the items on the status bar
panelOptions.add(Box.createHorizontalStrut(25));
// Add a label to display the current search radius
m_lblRadius = new JLabel("");
panelOptions.add(m_lblRadius);
// Act as a listener so that whenever the user uses the Radius
// tool, there is a notification, causing our propertyChange
// method to be called; there we can update the JLabel
// that shows the current radius.
radius.addPropertyChangeListener(this);
panelOptions.add(Box.createHorizontalStrut(25));
// Add a button that allows the user to show or hide the panel
// that contains thematic shading options.
m_btnShowHide = new JButton(">>");
m_btnShowHide.addActionListener(this);
panelOptions.add(m_btnShowHide);
m_bThemesVisible = true;
// Add the panel with the ZoomPanel, etc., to the bottom of
// the panel that contains the map and the toolbar.
panelMap.add(panelOptions, BorderLayout.SOUTH);
// Define a thematic panel, which will contain an "Add Theme" button
// and a container that we will use to display thematic legends.
m_panelTheme = new JPanel();
m_panelTheme.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
m_panelTheme.setPreferredSize(new Dimension(200, 400));
m_panelTheme.setLayout(new BoxLayout(m_panelTheme, BoxLayout.Y_AXIS));
// Add an Add Theme button to the upper part of the thematic panel
m_btnAddTheme = new JButton(m_addThemeLabel);
m_btnAddTheme.setAlignmentX(Component.CENTER_ALIGNMENT);
m_btnAddTheme.addActionListener(this);
m_panelTheme.add(m_btnAddTheme);
// Add a legend container to the lower part of the thematic panel
m_legendContainer.setBorder(BorderFactory.createEtchedBorder());
m_legendContainer.setPreferredSize(new Dimension(180, 1500));
JScrollPane sp = new JScrollPane(m_legendContainer);
m_panelTheme.add(sp);
// Add the toolbar/map/statusbar panel to the left part of the layout
this.getContentPane().add(panelMap, BorderLayout.CENTER);
// Add the thematic panel to the right part of the layout
this.getContentPane().add(m_panelTheme, BorderLayout.EAST);
try {
m_legendContainer.setVisualMapJ(m_visualMapJ);
m_addTheme.setVisualMapJ(m_visualMapJ);
// Set up the applet to use remote rendering
// (having the server render the images).
RendererParams rParams = new RendererParams();
rParams.setURL(m_mapxtremeURL);
m_visualMapJ.setRendererParams(rParams);
} catch (Exception e) {
}
try {
jbInit();
} catch (Exception e) {
//e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
}
// Listen for changes to the radius in the Radius Select tool.
public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName();
if (propertyName != null) {
// See whether user is using the Radius Select tool
if (propertyName.startsWith("Radius")) {
if (e.getNewValue() == null) {
// User must have pressed ESC key to cancel the tool
m_lblRadius.setText("");
} else {
if (propertyName.equalsIgnoreCase("RadiusFinished")) {
// User has finished using the tool; clear the status bar
m_lblRadius.setText("");
} else {
// User is currently dragging the Radius tool...
Double d = (Double) e.getNewValue();
if (m_nf == null) {
m_nf = NumberFormat.getNumberInstance();
m_nf.setMaximumFractionDigits(3);
m_nf.setMinimumFractionDigits(1);
m_nf.setGroupingUsed(true);
}
m_lblRadius.setText(m_radiusLabel + " " + m_nf.format(d) +
" " +
m_visualMapJ.getMapJ().
getDistanceUnits().getAbbreviation());
}
}
}
}
} // propertyChange method
// Respond to the user actions, such as clicking
// the Add Theme button.
public void actionPerformed(ActionEvent event) {
Object object = event.getSource();
if (object == m_btnAddTheme) {
// The user clicked the Add Theme button. Invoke the Add Theme
// wizard, unless we detect (by checking the m_bDialogActive
// variable) that the Add Theme wizard is already being displayed.
// (Which can happen if the user accidentally clicks the button twice.)
if (!m_bDialogActive) {
// The add theme dialog isn't currently active; so display it now.
m_bDialogActive = true;
m_addTheme.actionPerformed(null);
m_bDialogActive = false;
}
} else if (object == m_btnShowHide) {
// The user clicked the button that shows or hides the themes panel.
// Show or hide the themes panel, and reset the button caption.
if (m_bThemesVisible) {
m_btnShowHide.setText("<<");
} else {
m_btnShowHide.setText(">>");
}
m_bThemesVisible = !m_bThemesVisible;
m_panelTheme.setVisible(m_bThemesVisible);
}
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
//static initializer for setting look & feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?