正常来说通过接口获取这样的多面数据:
"geom":"SRID=4326;MULTIPOLYGON(((112.42895654300003 22.552396602000044,112.42907274700008 22.55247649300003,112.42915152800003 22.552530657000034,112.42921560100001 22.552533587000028,112.42920648400002 22.55248800800007,112.4292030580001 22.552453743000058,112.4292030580001 22.55242290500007,112.42919620400005 22.55238864000006,112.42918592400008 22.55236465400003,112.42917221800008 22.552330389000076,112.42915851100008 22.552306403000046,112.42914480500008 22.55228241800006)))“
我们需要对其进行转为对应的多面对象或者是几何体Geometry,这样就可以直接GraphicLayer.addGraphic(Geometry)方法来显示了;但需要非常注意的一点是如果不是自己组建Polygon来进行显示的话,而已直接通过这样的生成jsonParser = jsonFactory.createJsonParser(geoJson);
MapGeometry mapGeometry = GeometryEngine.jsonToGeometry(jsonParser);
Geometry geometry = mapGeometry.getGeometry();
那就必须先把返回的经纬度通过GeometryEngine.project()来转换为投影坐标才行 ,
那就必须先把返回的经纬度通过GeometryEngine.project()来转换为投影坐标才行 ,
那就必须先把返回的经纬度通过GeometryEngine.project()来转换为投影坐标才行 ,
重要的事说三遍.
附上相关坐标转换
SpatialReference mSR4326 = SpatialReference.create(4326);
SpatialReference mSR3857 = SpatialReference.create(3857);
1. 屏幕坐标转换成投影坐标
@Override
public boolean onSingleTap(MotionEvent point) {
SpatialReference sr = map.getSpatialReference();
Point dp = map.toMapPoint(point.getX(), point.getY());
}
2. 投影坐标转换成经纬度
Point wgsPoint = (Point) GeometryEngine.project(dp ,map.getSpatialReference(),mSR3857);
3、经纬度转换成投影坐标
Point mapPoint = (Point) GeometryEngine.project(wgsPoint ,mSR4326,map.getSpatialReference());
4、投影坐标转换成屏幕坐标
Point screenPoint = map.toScreenPoint(mapPoint);