【Mars3d】new mars3d.layer.GeoJsonLayer({不规则polygon加载label不在正中间的解决方案

问题:

1.new mars3d.layer.GeoJsonLayer({type: "polygon",在styleOptions里配置label的时候,发现这个

不规则polygon加载的时候,会出现label不在中心位置。

graphicLayer = new mars3d.layer.GeoJsonLayer({

name: "全国省界",

url: "//data.mars3d.cn/file/geojson/areas/100000_full.json",

format: simplifyGeoJSON, // 用于自定义处理geojson

symbol: {

type: "polylineP",

styleOptions: {

width: 2,

materialType: mars3d.MaterialType.LineFlow,

materialOptions: {

color: "#00ffff",

image: "img/textures/fence-line.png",

speed: 10,

repeat_x: 10

},

distanceDisplayCondition: true,

distanceDisplayCondition_far: 12000000,

distanceDisplayCondition_near: 100000,

label: {

text: "{name}",

position: "{center}", // 省会位置center

font_size: 30,

color: "#ffffff",

outline: true,

outlineColor: "#000000",

scaleByDistance: true,

scaleByDistance_far: 60000000,

scaleByDistance_farValue: 0.2,

scaleByDistance_near: 1000000,

scaleByDistance_nearValue: 1,

distanceDisplayCondition: true,

distanceDisplayCondition_far: 10000000,

distanceDisplayCondition_near: 100000,

setHeight: 10000

}

}

},

flyTo: true

})

map.addLayer(graphicLayer)

label: {

text: "{name}",

position: "{center}", // 省会位置center

这个配置可以看到在不规则的时候,就无法显示在中心了,是因为sdk内部计算多个点的点位中心依靠的是数学的围合面的多个点的中心点坐标算法计算的。

相关链接:

PolyUtil - V3.6.18 - Mars3D API文档

翻看了mars3d.graphic.PolygonEntity.StyleOptions,面 支持的样式信息这个label的文字所在位置除了center还有其他的位置是可以额外支持的。

解决方案:

可以在我们的图形数据里面加properties,带着坐标点位,就类似我们自己维护的数据一样,加个参数是专门显示点位的。

真正在项目中遇到的不规则的面数据也没几个,可以一个个点一下,避免通过center获取中心点有时候会在图形之外的问题。

默认是中心点位,遇到一个不正确的就修改一个。

相关推荐
TO_WebNow3 分钟前
使用thinkPHP8.x 访问接口提示跨域
前端·php
掘金一周4 分钟前
回家的时候用车,不回家感觉又没啥用,这车还要不要买 | 沸点周刊 5.14
前端
HelloWorld工程师10 分钟前
SSL证书在哪里可以免费且快速申请?
服务器·网络协议·ssl
梦想的颜色14 分钟前
前端UI宝藏SKILL——UI/UX Pro Max
前端·ui·ux
techdashen18 分钟前
dial9:给 Tokio 装上“飞行记录仪“
java·数据库·redis
2501_9010064719 分钟前
Golang怎么用gRPC Gateway_Golang gRPC Gateway教程【经典】
jvm·数据库·python
2501_9012005321 分钟前
golang如何实现错误预算Error Budget计算_golang错误预算Error Budget计算实现实战
jvm·数据库·python
無名路人31 分钟前
uniApp 小程序 vue3 app.vue静默登录其他页面等待登录完成方式二
前端·微信小程序·ai编程
2401_8676239832 分钟前
如何解决OUI图形界面无法调用_xhost与DISPLAY变量设置
jvm·数据库·python
CoCo的编程之路35 分钟前
2026 前端效能飞跃:深度解析智能助手的页面构建最大化方案
前端·人工智能·ai编程·智能编程助手·文心快码baiducomate