在地图上显示多边形(处理几何图形 WKT 格式)
Display polygon on Map (Process geometries WKT-format)
编辑: 工作解决方案。
(适用于 DevBab 所做的更改)。
额外: 添加了一个选项来设置多边形的样式。 (var polyStyle)
var url = 'http://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.json' +
'?app_id='+ app_id +
'&app_code=' + app_code +
'&prox=' + lat +','+ lng +',1000' +
'&mode=retrieveAddresses&maxresults=1' +
'&level=county'+
'&additionaldata=IncludeShapeLevel,county';
$.getJSON(url,function (data) {
var location = data.Response.View[0].Result[0].Location;
var wktShape = location.Shape.Value;
var polyStyle = {
strokeColor: 'red',
fillColor: 'rgba(255, 255, 255, 0.3',
lineWidth: 2
};
var geoPoint = H.util.wkt.toGeometry(wktShape);
map.addObject(new H.map.Polygon(geoPoint,{style:polyStyle}));
});
您创建的是多边形,而不是标记,因此请修改:
map.addObject(new H.map.Marker(geoPoint));
据此:
map.addObject(new H.map.Polygon(geoPoint));
编辑: 工作解决方案。 (适用于 DevBab 所做的更改)。
额外: 添加了一个选项来设置多边形的样式。 (var polyStyle)
var url = 'http://reverse.geocoder.cit.api.here.com/6.2/reversegeocode.json' +
'?app_id='+ app_id +
'&app_code=' + app_code +
'&prox=' + lat +','+ lng +',1000' +
'&mode=retrieveAddresses&maxresults=1' +
'&level=county'+
'&additionaldata=IncludeShapeLevel,county';
$.getJSON(url,function (data) {
var location = data.Response.View[0].Result[0].Location;
var wktShape = location.Shape.Value;
var polyStyle = {
strokeColor: 'red',
fillColor: 'rgba(255, 255, 255, 0.3',
lineWidth: 2
};
var geoPoint = H.util.wkt.toGeometry(wktShape);
map.addObject(new H.map.Polygon(geoPoint,{style:polyStyle}));
});
您创建的是多边形,而不是标记,因此请修改:
map.addObject(new H.map.Marker(geoPoint));
据此:
map.addObject(new H.map.Polygon(geoPoint));