小马看Gis–通过Openlayers实现实时定位

    说到实时监控,我们不能不承认Openlayers功能的确非常强大。Openlayers中通过很多方式都能实现实时监控。我讲讲我的实现方式。

      我的方式很简单:页面发起异步请求;服务端程序将请求结果处理成GeoJSON串回传至请求页面;请求页面通过OpenLayers提供的OpenLayers.Format.GeoJSON解析GeoJSON串,将结果展现到地图上。

 

      下面的示例显示:实时获得油机的位置数据,展示到页面上。

 

页面程序: 

 

 

 服务端程序:

 

if (state) {
LineString line = new LineString();
StringBuffer geo = new StringBuffer();
Point pointEnd = new Point();
Feature feaPoint = new Feature(pointEnd);
Map<String, String> propoint = new HashMap<String, String>();
feaPoint.setProperties(propoint);
for (int i = 0; i < list.size(); i++) {
geo.append(“[” + list.get(i).getCurLoc() + “]”);
if (i != (list.size() – 1)) {
geo.append(“,”);
}
}
line.setLine(geo.toString());
Feature feaLine = new Feature(line);
Map<String, String> properties = new HashMap<String, String>();
properties.put(“color”, “#1A60CA”);
feaLine.setProperties(properties);
List<Component> components = new ArrayList<Component>();
components.add(feaLine);
components.add(feaPoint);
FeatureCollection feaCol = new FeatureCollection(components);
orieStr = feaCol.draw();
}
}

 

 

 

 服务器端提供的数据格式如下:

 

   

 

 

 

 服务器端生成json串,我用装饰者模式写了一个模块,只要调用这个模块的API就会生成需要的Json串。

 

 

转载自:https://blog.csdn.net/mach365/article/details/6151827

You may also like...

退出移动版