当前位置:网站首页>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行左右
边栏推荐
- BUUCTF做题Upload-Labs记录pass-11~pass-20
- 智能家居行业发展,密切关注边缘计算和小程序容器技术
- mysql还有哪些自带的函数呢?别到处找了,看这个就够了。
- Unit editor details
- Applet container technology improves mobile R & D efficiency by 500%
- Explain mesh Collider in unity
- Guo Mingxuan: meta contraction is conducive to the development of VR competitors, and apple XR headshow will change the industry rules
- DLL decompile (decompile encrypted DLL)
- How to build internal Wikipedia
- Unity - script lifecycle
猜你喜欢

Unit editor details

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

【TiDB】txt文档导入数据库,这样做真的很高效
![[Zhou Zhou has a prize] cloud native programming challenge](/img/0d/e26e37cddf3cf01b5e9dcaf7211106.png)
[Zhou Zhou has a prize] cloud native programming challenge "edge container" track invites you to fight!

After Europe, it entered Japan and South Korea again, and the globalization of Pico consumer VR accelerated

C language function program example (super complete)

MoCo V3:视觉自监督迎来Transformer

详细讲解C语言12(C语言系列)

It is not only convenient, safe + intelligent, but also beautiful. Fluorite releases the Big Dipper face lock dl30f and Aurora face video lock y3000fv

MobileViT:挑战MobileNet端侧霸主
随机推荐
Moco V1: the visual field can also be self supervised
Explain the script data transmission and notification in unity
What is ci/cd| Achieve faster and better software delivery
Introduction to singleton mode
Interpretation of netappp SP sensors output content
[tool class] util package of map, common entity classes are converted to map and other operations
Basic operations of unity3d scene production
uniapp的进度条自定义
承载银行关键应用的容器云平台如何选型及建设?
Guanghetong & Qualcomm Internet of things technology open day successfully held
ABB电磁流量计维修信号变送器维修41F/E4技术参数
quii cordova-plugin-telerik-imagepicker插件多图上传乱序
EfficientFormer:轻量化ViT Backbone
C language function program example (super complete)
C foundation 2-encapsulation, inheritance, polymorphism
【input 身份证号】星号 代替,input 切割成 多个 小格格(类似)
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
Nacos principle
Color finder actual combat (QT including source code)
DELTA热金属检测器维修V5G-JC-R1激光测量传感器/检测仪原理分析

