`
to_zoe_yang
  • 浏览: 139378 次
  • 性别: Icon_minigender_2
  • 来自: 01
社区版块
存档分类
最新评论

通过Panel中显示google地图

    博客分类:
  • GUI
阅读更多


这个是显示地图的JPanel,通过BrTabbed执行jsp显示,就像浏览器一样
package com.etsolar.monitor.client.mainpanel.gispanel;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
//Java网页浏览器
import org.jdic.web.BrTabbed;

public class GISPanel extends JPanel { 
	private static final long serialVersionUID = 1L;
	private BrTabbed browser = new BrTabbed();
	public GISPanel(){
		try {
			this.setBorder(BorderFactory.createTitledBorder("GIS Panel"));
			String fileDir = "C:" + System.getProperty("file.separator")+ "etsolar";
			String fileName = fileDir + System.getProperty("file.separator") + "GIS.jsp";
			browser.setURL(fileName);
			this.setLayout(new BorderLayout());
			this.add(new JScrollPane(browser), BorderLayout.CENTER);
			org.jdic.web.BrComponent.DESIGN_MODE = false;
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public boolean executeJavaScript(String javaScript)
	{
		boolean result = true;
		return result;
	}
	
	public void refresh()
	{
		browser.refresh();
	}
}


执行的程序,使用XML来保存需要显示的地点的信息(精度和纬度)
import java.awt.BorderLayout;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.jdic.web.BrTabbed;

public class GISTest extends JPanel{

	private BrTabbed browser = new BrTabbed();
	public GISTest(){
		this.setBorder(BorderFactory.createTitledBorder("GIS Panel"));
//		String fileDir = "C:" + System.getProperty("file.separator")+ "etsolar";
		String fileDir = "c://etsolar";
		String fileName = fileDir + System.getProperty("file.separator") + "GIS.jsp";
		browser.setURL(fileName);
		this.setLayout(new BorderLayout());
		this.add(new JScrollPane(browser), BorderLayout.CENTER);
		org.jdic.web.BrComponent.DESIGN_MODE = false;
	}
	
	public void show(){
		String num1Str = "30.657";
		String num2Str = "104.08";
		Document document = DocumentHelper.createDocument();
		Element catalogElement = document.addElement("description");
		catalogElement.addComment("An XML description of a machine");
		catalogElement.addProcessingInstruction("target", "text");
		Element detailElement = catalogElement.addElement("detail");
		detailElement.addAttribute("publisher", "NJUST");
		Element LongitudeElement = detailElement.addElement("Longitude");
		LongitudeElement.setText(num1Str);
		Element LatitudeElement = detailElement.addElement("Latitude");
		LatitudeElement.setText(num2Str);
		String fileDir = "C:" + System.getProperty("file.separator")
				+ "etsolar";
		String fileName = fileDir + System.getProperty("file.separator")
				+ "MAP.xml";
		XMLWriter output;
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("UTF-8");
		try {
			output = new XMLWriter(new FileWriter(fileName), format);
			output.write(document);
			output.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		//System.out.println("经纬度信息已经写入XML文件" + "经度: [" + num1Str + "],"					+ "纬度: [" + num2Str + "]");
		this.refresh();
	}
	
	public boolean executeJavaScript(String javaScript)
	{
		boolean result = true;
		return result;
	}
	
	public void refresh()
	{
		browser.refresh();
	}
	
	public static void main(String[] args){
		JFrame frame = new JFrame("GISTest");
		GISPanel gisPanel = new GISPanel();
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
				new JPanel(), gisPanel);
		frame.add(splitPane);
		splitPane.updateUI();
		frame.setVisible(true);
		frame.setSize(400, 500);
	}
}


这个只最重要的jsp文件啦
GIS.jsp

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
		<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
		<title>Etsolar Google Maps </title>	
		<script src="http://ditu.google.com/maps?file=api&amp;v=2"
            type="text/javascript"></script>
		<script type="text/javascript">
		var Url="C:\\etsolar\\MAP.xml";
		var x;var y;
		var cdsales=new ActiveXObject("Microsoft.XMLDOM"); 
		cdsales.async=true; 
		cdsales.load(Url); 
		function initialize()
		{
			if(cdsales.readyState==4)
			{
				if(cdsales.parseError.errorCode != 0)
				{
					document.write(cdsales.parseError.line);
					document.write(cdsales.parseError.reason);
					document.write(cdsales.parseError.srcText);
				}
				else
				{
					var bi=cdsales.documentElement.selectNodes("//detail");
					if(bi!=null)
					{
							x=bi[0].childNodes[0].text;
							y=bi[0].childNodes[1].text;
					}
				}
			}
			else
			{
				document.write("XML文档未分析完");
			}
			
			if(GBrowserIsCompatible())
			{
				var map = new GMap2(document.getElementById("maps"));
				map.addControl(new GSmallMapControl());
				map.addControl(new GMapTypeControl());
				var blueIcon = new GIcon(G_DEFAULT_ICON); 
				blueIcon.image = "computer20.gif"; 
                 
				markerOptions = { icon:blueIcon }; 

				var point = new GLatLng(x,y);
				var marker = new GMarker(point,markerOptions);
				map.setCenter(point,19);
        map.addOverlay(marker);
				GEvent.addListener(map,"click", function(overlay,point) {        
       	if(point)
				{
						document.getElementById("show_x").value = point.x;
        		document.getElementById("show_y").value = point.y;
				}  
        });
        map.addControl(new GSmallMapControl());   
				map.addControl(new GMapTypeControl());   
			}
		}
	</script>
</head>
	
	<body onLoad="initialize()" onUnload="GUnload()">
		<b><font color="#FF0000">经度:</font></b><input id="show_x" value="0">&nbsp;&nbsp;<b><font color="#FF0000">纬度:</font></b><input id="show_y" value="0">
		<div id="maps" style="width:1000px;height:700px"></div>
	</body>
</html>
分享到:
评论
1 楼 to_zoe_yang 2011-04-05  
以后自己改改,可以自己输入精度和纬度~

相关推荐

    kirby-styledmap:Kirby CMS标记和页面方法可打印常规或样式化的Google地图

    柯比风格的Google地图 Kirby CMS标记和页面方法可打印常规或样式化的Google Map。 注意:这不是一个免费的插件。 为了在生产服务器上使用它,您需要购买许可证。 有关Kirby Styledmap许可模型的详细信息,请向下...

    Android 仿高德地图可拉伸的BottomSheet的示例代码

    前言 ... Bottom Sheet中的内容默认是隐藏起来的,只显示很小一部分,可以通过在代码中设置其状态或者手势操作将其完全展开,或者完全隐藏,或者部分隐藏。对于Bottom Sheet的描述可以在官网查询:

    ExtJS 4.2+JAVA通用后台管理系统(ExtJS 4.2+Hibernate 4.1.7+Spring MVC 3.2.8)

    Panel里包含2个组件,在2个组件间传递参数显示数据。 三、开发工具和采用技术 1、开发工具:Eclipse、MyEclipse和其他IDE。 2、采用Spring 3中最新最稳定的Spring MVC 3.2.8版本。 3、采用Hibernate 4.1.7。Spring...

    ASP.NET.4揭秘

    22.4.2 在treeview控件中显示复选框812 22.4.3 绑定到站点地图814 22.4.4 绑定到xml文件815 22.4.5 绑定到数据库数据817 22.4.6 使用延时加载和ajax820 22.4.7 定制treeview控件824 22.5 创建分层的sql数据源控件830...

    PrimeFaces学习教程

    2.9.5 Google Maps 地图 61 2.9.6 Dyna Image 63 2.9.7 Media 65 2.9.8 Star Rating 65 2.9.9 Wizard: 66 2.10 消息: 66 2.10.1 Growl Mac风格的消息显示 66 2.10.2 Message/Messages 67 2.10.3 Tooltip 67 2.11 ...

    ASP.NET 控件的使用

    13.2.2 在多列中显示数据 431 13.2.3 在DataList控件中使用模板 433 13.2.4 使用DataList控件选择数据 434 13.2.5 使用DataList控件编辑数据 437 13.2.6 格式化DataList控件 440 13.3 小结 442 第14章 使用ListView...

    Java通用后台管理系统源码 JAVATYHTXT.rar

    Panel里包含2个组件,在2个组件间传递参数显示数据。 三、开发工具和采用技术 1、开发工具:Eclipse、MyEclipse和其他IDE。 2、采用Spring MVC 4.0.9版本。 3、采用Hibernate 4.3.8版本。 4、Hibernate集成二级...

    最新JAVA通用后台管理系统(ExtJS 4.2+Hibernate 4.1.7+Spring MVC 3.2.8)MyEclipse版本

    Panel里包含2个组件,在2个组件间传递参数显示数据。 三、开发工具和采用技术 1、开发工具:Eclipse、MyEclipse和其他IDE。 2、采用Spring 3中最新最稳定的Spring MVC 3.2.8版本。 3、采用Hibernate 4.1.7。Spring...

    最新JAVA通用后台管理系统(ExtJS 4.2+Hibernate 4.1.7+Spring MVC 3.2.8)Eclipse版本

    Panel里包含2个组件,在2个组件间传递参数显示数据。 三、开发工具和采用技术 1、开发工具:Eclipse、MyEclipse和其他IDE。 2、采用Spring 3中最新最稳定的Spring MVC 3.2.8版本。 3、采用Hibernate 4.1.7。Spring...

    shareyourdreams:适用于 Android 的完整应用程序示例。 更多信息请访问 http

    更多信息见 该应用程序允许您对梦境和噩梦进行地理定位、在地图上显示附近的梦境、使用数据库来识别您自己的梦境以及其他有趣的功能。 由开发的应用程序虽然是开源的,但是在这个项目的衍生作品中不得不提到作者。 ...

Global site tag (gtag.js) - Google Analytics