I have problem with Mapzen's TangramJS labelling. I am using MVT tiles and labels as an attributes to polygons that are multiplying in large scales. Below an example:

Multiplying labels on polygons

I would like to put one label per feature. Here is an example solving code but only for TopoJSON and GeoJSON tiles - not working for MVT.

Do you have any idea how to resolve this problem for Mapbox Vector Tiles?

I have found mapzen's code for GeoJSON i TopoJSON:

key: "preprocessFeatures",
value: function(e) {    
if (this.config.generate_label_centroids) {
        var t = [],
            n = {
                label_placement: !0
        e.forEach(function(e) {
            if (null != e.geometry) {
                var i = void 0,
                    a = void 0;
                switch (e.geometry.type) {
                    case "Polygon":
                        a = s(i = e.geometry.coordinates, e.properties, n), t.push(a);
                    case "MultiPolygon":
                        i = e.geometry.coordinates;
                        for (var r = -1 / 0, o = 0, l = 0; l < i.length; l++) {
                            var u = f.default.polygonArea(i[l]);
                            u > r && (r = u, o = l)
                        a = s(i[o], e.properties, n), t.push(a)
        }), t = t.filter(function(e) {
            return e
        }), Array.prototype.push.apply(e, t)
    return e

What should I do to implement it to MVT?

  • The idea is the same as in your reference: select all the parts of big polygons which are split across many tiles by a common feature ID, union the parts and generate one label point for the complete polygon. Perhaps someone has implemented that already. – user30184 Mar 13 '18 at 9:59
  • I've edited post and added code for implementing the feature for TopoJSON and GeoJSON which is not working for MVT. – sk1me Mar 26 '18 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.