OpenLayers使用(二)

上次简单的接触了一下openlayers,这次再来做个小例子测试一下:

我的需求是,在相应的坐标自动生成标注点,(坐标数据可以改成从数据库中读取),当power值为1的时候产生报警,报警的地方的标注点会由静态变成闪烁状态,点击可以获取该点的信息,在弹出的popup上处理报警信息,提交后闪烁状态消失,变回原来的静态标注点!

下面是整个小测试的项目目录:
OpenLayers使用(二)_第1张图片

Eclipse3.9+Mysql5.0+Tomcat6.0,使用ibatis和dwr框架搭配openlayers。

Monitor.java

package project.entity;

public class Monitor {
	private int id;
	private String name;
	private int value;
	
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getValue() {
		return value;
	}
	public void setValue(int value) {
		this.value = value;
	}
}

 
 Monitor.xml





	
	

	
	
	
	
	
	
		update monitor set name=#name#,value=#value# where id=#id#
	

 MonitorDAO.java

package project.dao;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;

import project.entity.Monitor;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class MonitorDAO {
	private static SqlMapClient sqlMapClient = null;
	
	static{
		Reader reader;
		try {
			reader = Resources.getResourceAsReader("SqlMapConfig.xml");
			sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	public List queryAllMonitor() throws SQLException{
		List monitorList = null;
		monitorList = sqlMapClient.queryForList("selectAllMonitor");
		return monitorList;
	}
	
	
	public List queryOther() throws SQLException{
		List moList = null;
		moList = sqlMapClient.queryForList("selectOther");
		return moList;
	}
	
	
	public boolean updateMonitorMsg(Monitor mo) throws SQLException{
		boolean flag = false;
		int i = sqlMapClient.update("updateMonitor", mo);
		if(i > 0){
			flag = true;
		}
		return flag;
	}
	
	
	public Monitor queryById(int id) throws SQLException{
		Monitor mo = (Monitor) sqlMapClient.queryForObject("selectById", id);
		return mo;
	}
	
	
	public static void main(String[] args) throws SQLException{
		MonitorDAO d = new MonitorDAO();
		List arr = d.queryOther();
		Iterator it = arr.iterator();
		while(it.hasNext()){
			Monitor m = it.next();
			System.out.println(m.getId()+":"+m.getValue());
		}
	}
}

 下面是综合测试的小例子:test.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




test4








	

 
OpenLayers使用(二)_第2张图片

 

项目所有源代码和文件已经上传到附件中 了,有需要的可以下载参考!

你可能感兴趣的:(openlayers)