【发布时间】:2021-10-04 10:42:32
【问题描述】:
我需要为以下输入创建图钉。
var Countries = ["Austria", "Brazil", "India", "Germany", "USA", "Malaysia"];
Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(Countries, geoDataRequestOptions, map,
(data) => {
var value = data.location;
if (data.results.length > 0 && data.results[0].Polygons !== null) {
var polygons = data.results[0].Polygons;
var dataBounds = Microsoft.Maps.LocationRect.fromShapes(data.results[0].Polygons);
var loc = new Microsoft.Maps.Location(dataBounds.center.latitude, dataBounds.center.longitude);
var pin = new Microsoft.Maps.Pushpin(loc, {
icon: svgIcon,
anchor: new Microsoft.Maps.Point(20 / 2, 20 / 2)
});
map.entities.push(pin);
locs.push(pin);
map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(locs), padding: 80 });
}
});
}, 3000);
我正在使用 GeoDataAPIManager 获取边界多边形并获取多边形的中心以生成图钉。但是在加载马来西亚或美国等国家/地区时,图钉被放置在海中,因为getboundary() 返回多个多边形并且获取多边形的中心返回两个边界之间的中心,这导致图钉放置在海中。
如果有其他方法可以创建图钉或获取多边形的中心,请告诉我。
我已经尝试了spatial.Math 模块来获取中心。
【问题讨论】:
-
澄清一下,您希望图钉始终位于陆地上吗?我不熟悉 Bing Maps API,但有没有办法搜索几何而不包括(小)岛屿?也许过滤掉最大的多边形并选择它来放置图钉。
-
听起来你想要类似的东西:github.com/mapbox/polylabel
标签: javascript gis bing-maps