您的位置:首页 > 汽车 > 时评 > echars根据geojson地块坐标数据coordinates计算地图地块的中心点

echars根据geojson地块坐标数据coordinates计算地图地块的中心点

2024/10/5 15:05:15 来源:https://blog.csdn.net/u013675978/article/details/140112962  浏览:    关键词:echars根据geojson地块坐标数据coordinates计算地图地块的中心点

echarts地图根据地块名称获取地块的中心坐标。实现在中心位置放置标记。
需要放置数据的地块名称的数据格式:
mapData: [
        {name: '江苏省', value: 500},
        {name: '上海市', value: 10}
],
计算中心代码:

    // this.geoData是中国地图的geojson格式数据// this.mapData是需要计算中心点的省份名称数据for (let item of this.mapData) {//从地图数据中拿到坐标for ( let area of this.geoData.features){if (item.name === area.properties.name){let coordinates;// 判断是否是多块的地图if (area.geometry.type === 'MultiPolygon') {coordinates = area.geometry.coordinates[0][0]} else {coordinates = area.geometry.coordinates[0]}//计算中心点let x = 0, y = 0, count = 0;for (let i = 0; i < coordinates.length; i++) {x += coordinates[i][0];y += coordinates[i][1];count++;}this.pointData.push({name: item.name,value: [x / count, y / count],data: item.value})// this.pointData.push({//   name: item.name,//   value: area.properties.center,//   data: item.value// })}}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com