当前位置:网站首页>Uncaught Error:Invalid geoJson format Cannot read property ‘length‘ of undefind
Uncaught Error:Invalid geoJson format Cannot read property ‘length‘ of undefind
2022-07-28 19:31:00 【song854601134】
对比geojson数据发现,出现报错原因是因为数据类型中有GeometryCollection存在。经分析,由于生成的地图里有一个区域为两块不连续的地图块,所以生成的geoJson中此区域的geometry.type===GeometryCollection。然而,echarts 中对于此类型没有做处理,详情见
访问官方的github仓库,issues存在对应的解决方法, https://github.com/apache/echarts/issues/9350
二、修改方法
如果函数一样,可直接复制粘贴下面这一段,其他情况,请参考下图2处修改逻辑自行更改。
export default function parseGeoJson(geoJson, nameProperty) {
decode(geoJson);
return zrUtil.map(
zrUtil.filter(geoJson.features, function(featureObj) {
if (featureObj.geometry.geometries) {
let geometry = featureObj.geometry.geometries.map(i => {
return i.coordinates;
});
let {
type, properties, ...params } = featureObj;
return {
type, properties, geometry };
}
// Output of mapshaper may have geometry null
return (
featureObj.geometry &&
featureObj.properties &&
featureObj.geometry.coordinates &&
featureObj.geometry.coordinates.length > 0
);
}),
function(featureObj) {
var properties = featureObj.properties;
var geo = featureObj.geometry;
var coordinates = geo.coordinates;
var geometries = [];
if (geo.type === "GeometryCollection") {
let geometry = {
type: "Polygon"
};
let coordinatesArr = featureObj.geometry.geometries.map(i => {
return i.coordinates;
});
geometry.coordinates = coordinatesArr;
console.log(coordinatesArr, "coordinatesArr");
coordinatesArr.forEach(i => {
geometries.push({
type: "polygon",
// According to the GeoJSON specification.
// First must be exterior, and the rest are all interior(holes).
exterior: i[0],
interiors: i.slice(1)
});
});
}
if (geo.type === "Polygon") {
console.log("coordinatesPolygon", coordinates);
geometries.push({
type: "polygon",
// According to the GeoJSON specification.
// First must be exterior, and the rest are all interior(holes).
exterior: coordinates[0],
interiors: coordinates.slice(1)
});
}
if (geo.type === "MultiPolygon") {
zrUtil.each(coordinates, function(item) {
if (item[0]) {
geometries.push({
type: "polygon",
exterior: item[0],
interiors: item.slice(1)
});
}
});
}
console.log(
properties[nameProperty || "name"],
geometries,
properties.cp,
"asdfasdfasdf"
);
var region = new GeoJSONRegion(
properties[nameProperty || "name"],
geometries,
properties.cp
);
region.properties = properties;
return region;
}
);
}
需要修改的parseGeoJson函数中的2处:echarts 源代码在116行左右
边栏推荐
- C foundation 8-reflection and dependency injection
- 广和通&高通物联网技术开放日成功举办
- After Europe, it entered Japan and South Korea again, and the globalization of Pico consumer VR accelerated
- 数据库--explain的使用
- 实习日记第一周
- MoCo V1:视觉领域也能自监督啦
- Moco V2: further upgrade of Moco series
- 又一款装机神器
- Ctfshow network lost track record (2)
- Jiuxin intelligence officially joined opengauss community
猜你喜欢

探讨:想要落地DevOps的话,只考虑好的PaaS容器平台就够了么?

Unity3d tutorial notes - unity initial 02

智能家居行业发展,密切关注边缘计算和小程序容器技术

New development of letinar in Korea: single lens 4.55G, light efficiency up to 10%

npm如何切换淘宝源镜像

SSM use @async and create threadpooltaskexecutor thread pool

How to build a foreign environment for the self-supporting number of express evaluation? How much does it cost?

Explain in detail the rays and radiographic testing in unity

Moco V2: further upgrade of Moco series

Nacos 原理
随机推荐
Dom4J的Bug
智能家居行业发展,密切关注边缘计算和小程序容器技术
什么是低代码?哪些平台适合业务人员?用来开发系统靠不靠谱?
上市1个月接连发生两起安全事故,理想L9还理想吗?
Moco V1: the visual field can also be self supervised
一名在读研究生的自白:我为什么会沉迷于openGauss 社区?
How does lazada store make up orders efficiently? (detailed technical explanation of evaluation self-supporting number)
New development of letinar in Korea: single lens 4.55G, light efficiency up to 10%
Maxwell is an easy-to-use software for capturing MySQL data in real time
C # basic 5-asynchronous
取色器实战(Qt含源码)
Redis缓存雪崩、缓存穿透、缓存击穿
MySQL sorts out the review content -- with mind map
Guanghetong & Qualcomm Internet of things technology open day successfully held
Applet container technology improves mobile R & D efficiency by 500%
图书馆借阅系统「建议收藏」
BUUCTF做题Upload-Labs记录pass-11~pass-20
证券企业基于容器化 PaaS 平台的 DevOps 规划建设 29 个典型问题总结
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
There have been two safety accidents in a month after listing. Is L9 ideal?

