简体   繁体   English

将 PolyLabel 与 GeoJSON 数据和 Google 地图一起使用

[英]Using PolyLabel with GeoJSON data and Google Maps

I am attempting to use the PolyLabel library with GeoJSON data and the Google Maps API to generate appropriately placed labels for irregular polygons.我正在尝试使用带有 GeoJSON 数据的PolyLabel库和 Google Maps API 为不规则多边形生成适当放置的标签。 The documentation says that the library accepts polygon coordinates in GeoJSON-like format .文档说该库接受类似 GeoJSON 格式的多边形坐标。

The problem is that I cannot figure out what data to pass from the Google Maps API data layer to PolyLabel to get the best fit label position.问题是我无法弄清楚将哪些数据从 Google Maps API 数据层传递到 PolyLabel 以获得最合适的标签位置。

polygons.forEach(function (feature) {
    var geo = feature.getGeometry();

    var position = polylabel(???, 1.0);

    var mapLabel = new MapLabel({
        position: position,
        text: feature.getProperty("LABEL"),
        fontSize: 25,
        fontColor: "red",
        map: map
    })

    currentLabels.push(mapLabel);
});

I have tried multiple variations on passing in the feature, the geometry, the raw coordinates, and constructing polygons from the coordinates.我已经尝试了多种不同的方式来传递特征、几何、原始坐标以及从坐标构造多边形。

It is also worth noting that the GeoJSON data contains a mixture of Polygons and MultiPolygons.还值得注意的是,GeoJSON 数据包含多边形和多多边形的混合。

Thank you.谢谢你。

definitely difficult to see, but you can find it here.绝对很难看到,但你可以在这里找到。 https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/polylabel/index.d.ts https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/polylabel/index.d.ts

for each point in the polygon, you have [x, y].对于多边形中的每个点,您都有 [x, y]。 Each polygon is then [[x,y]...], and polylabel takes array of polygons.然后每个多边形是 [[x,y]...],并且 polylabel 采用多边形数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM