mapbox .聚集,把'K'换成‘千’

使用mapbox的聚集功能时,可以注意到当聚集的数字超过1000时会缩写为以k为单位的数,如  1.3k

如果想要把这个英文的单位转为中文的“千”应该怎么做呢?
首先去github上找mapbox-gl-js的源码,在源码里用find in path搜索“cluster”,发现有一个包的名字叫做“supercluster”,有关聚集的代码应该在这里,node_modules\supercluster

 

看源码,发现了这样一个函数:getClusterProperties

function getClusterProperties(cluster) {
var count = cluster.numPoints;
var abbrev = count >= 10000 ? Math.round(count / 1000) + 'k' :
count >= 1000 ? (Math.round(count / 100) / 10) + 'k' : count;
return extend(extend({}, cluster.properties), {
cluster: true,
cluster_id: cluster.id,
point_count: count,
point_count_abbreviated: abbrev
});
}

 

之后回到mapgl-gl-js.js文件里去搜这个函数getClusterProperties,把里面的k替换为千就行了

posted @ 2022-03-29 17:19  泽泽生龙  阅读(351)  评论(0)    收藏  举报