首页 > 解决方案 > How to find the width of a text-field in symbol type in mapbox

问题描述

I am trying to get the width of a text-field in coordinates, i.e. starting coordinates and ending coordinates of the text-field on the map. My code is as below:

        map.on('load', function () {


            map.addLayer({
                "id": "labels",
                "type": "symbol",
                "source": {
                    "type": "geojson",
                    "data": {
                        "type": "FeatureCollection",
                        "features": [{
                                "type": "Feature",
                                "geometry": {
                                    "type": "Point",
                                    "coordinates": [-119.4179, 36.7783]
                                }
                            }]
                    }
                },
                "layout": {
                    "icon-image": "harbor-15",
                    "text-field": "Testing city name",
                    "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
                    "text-offset": [0, 0.6],
                    "text-anchor": "top",
                    "text-allow-overlap": true
                }
            });

From the above, I would like to get the exact start and end coordinates of the text-field only. Could somebody say whether this is possible?

标签: javascriptmapboxmapbox-gl-jsmapbox-marker

解决方案


我不认为这是可能的访问。文本布局计算深埋在 mapbox-gl 源代码中。文本本身使用距离字段字体在 WebGL 中呈现


推荐阅读