1.Mapeper.jar
List<Map<String,Object>> selectGeom();
2.Mapper.xml
<select id="selectGeom" resultType="java.util.HashMap">
select st_asgeojson(geom) as geom,xzqdm,uuid from xzq_n where del_flag='0' order by id asc
</select>
3.转geoJson
public Map<String,Object> geoJSON(List<Map<String,Object>> pointList){
Map<String,Object> map = new HashMap<>();
List<Map<String, Object>> features = new ArrayList<Map<String, Object>>();
for (Map<String, Object> m : pointList) {
Map<String, Object> feature = new HashMap<String, Object>();
feature.put("type", "Feature");
Map<String, Object> properties = new HashMap<String, Object>();
//把非geojson全部放到属性里面
Iterator<Map.Entry<String, Object>> it = m.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> en = it.next();
if (!"geom".equals(en.getKey())) {
properties.put(en.getKey(), en.getValue());
}
}
feature.put("properties", properties);
feature.put("geometry", JSON.parse(m.get("geom").toString()));
feature.put("id",m.get("uuid"));
features.add(feature);
}
map.put("features", features);
return map;
}
4.cesium调用
let geoJson={"type": "FeatureCollection", "name": "河道线", "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}},"features":geomList.features};
var promise=GeoJsonDataSource.load(geoJson);
promise.then(function(dataSource) {
dataSource.name='SourceName'
viewer.dataSources.add(dataSource);
var entities = dataSource.entities.values;
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
entity.polygon.outline = true;
entity.polygon.extrudedHeight=20;
entity.polygon.fill=false;
entity.polygon.classificationType =ClassificationType.BOTH;
entity.polygon.outlineColor = Color.TEAL;
}
});