1.GeoJson数据格式:
1.shp数据格式转geojson数据格式方法:
2.点类型格式:
{ geometry: { type: 'Point', coordinates: [123, 23] }, style:{ //样式配置 }, name: "", count: 30 //权重 }
3.线类型格式:
//线
{ geometry: { type: 'LineString', coordinates: [ [123, 23], [124, 24] ] }, style:{ //样式配置 }, name: "", count: 30 }
//多线
{ geometry: { type: 'MultiLineString', coordinates: [ [123, 23], [124, 24], [123, 23], [124, 24], [123, 23], [124, 24], ] }, style:{ //样式配置 }, name: "", count: 30 }
4.面类型格式:
//面
{ name: "", count: 30, //权重 geometry: { type: 'Polygon', coordinates: [ [ //外环 [123, 23], [123, 23], [123, 23] ], [ //内环 [124, 21], [124, 21], [124, 21] ] ] } }
//多面
{ name: "", count: 30, //权重 geometry: { type: 'MultiPolygon', coordinates:[ [ [ //外环 [123, 23], [123, 23], [123, 23] ], [ //内环 [124, 21], [124, 21], [124, 21] ] ], [ [ //外环 [123, 23], [123, 23], [123, 23] ], [ //内环 [124, 21], [124, 21], [124, 21] ] ] ] } }
2.加载后台json数据
let search_url = `shape/buffer/poly?distance=${values}&polygon=${pointsPolygon}`;
self.$http .get(search_url, {
//_timeout: 3000,
onTimeout: request => {
//alert('请求超时');
} }) .then(res => {
NF.GeoJsonDataSource.load(res.url, {
clampToGround: true,
}).then(function (dataSource) {
dataSource.show = true;
let entitys = dataSource.entities.values;
entitys[0].polygon.material = NF.Color.fromCssColorString("#6032ff").withAlpha(0.5); ZhiYunGisProperty.ZhiYunViewer.dataSources.add(dataSource);
}).otherwise(function (error) { console.error(error); }); }).catch(() => console.log('promise catch err')); //捕获异常;
3.加载点线面geojson数据
// 定义对象用于存储实体数据,供外部调用该实体数据显示或隐藏
let PlanningMap = {
PlanningMap1: [],
};
// 初始化加载geojson数据
import("../../../static/planningMap/PlanningMap2/6/中国移动管线.json").then((dataSource) => {
new Promise((resolve, reject) => {
let typeId = newGuid();
let result = {
name: '中国移动管线——2020-03-15',
data: {
typeId: typeId
},
children: [],
};
resolve(result)
}).then((result) => {
ret[0].children.push(result);
let arrs = [];
let height = 30;
dataSource.features.forEach(item => {
let geometries = {
position: ZhiYunGisProperty.calcGeometry(item.geometry.coordinates, height).position,
name: item.properties.Layer,
color: "#ff050e",
width: 5
};
arrs.push(geometries);
});
let entity = {
geometries: arrs,
dataSource: dataSource,
type: "polyline",
isFly: true,
typeId: result.data.typeId,
name: result.name,
show: false
};
//加载entity实体
ZhiYunGisProperty.AddEntity(entity);
})
});
//加载entity实体
AddEntity: function (ret) {
let entity = {};
let typeId = null;
if (ret.type === "point") {
ret.geometries.forEach(item => {
typeId = ret.isPopulation ? item.typeId : ret.typeId;
entity.typeId = typeId;
entity.position = item.position;
entity.name = item.name;
entity.color = item.color;
entity.pixelSize = item.pixelSize;
entity.labelColor = item.labelColor;
entity.isLabelShow = item.isLabelShow;
entity.isFly = ret.isFly;
entity.show = ret.show;
try {
ZhiYunGisProperty.AddPoint(entity);
} catch (e) {
console.log("绘制点出错:===>", e, item)
}
})
} else if (ret.type === "polyline") {
ret.geometries.forEach(item => {
typeId = ret.isPopulation ? item.typeId : ret.typeId;
entity.typeId = typeId;
entity.position = item.position;
entity.name = item.name;
entity.color = item.isOtherMaterial ? item.color : NF.Color.fromCssColorString(item.color);
entity.width = item.width;
entity.isFly = ret.isFly;
entity.show = ret.show;
try {
ZhiYunGisProperty.AddPolyline(entity);
} catch (e) {
console.log("绘制线出错:===>", e, item)
}
})
} else if (ret.type === "polygon") {
ret.geometries.forEach(item => {
typeId = ret.isPopulation ? item.typeId : ret.typeId;
entity.typeId = typeId;
entity.position = item.position;
entity.name = item.name;
entity.color = item.color;
entity.width = item.width;
entity.hole = item.hole;
entity.isFly = ret.isFly;
entity.show = ret.show;
try {
ZhiYunGisProperty.AddPolygon(entity);
} catch (e) {
console.log("绘制面出错:===>", e, item)
}
})
} else if (ret.type === "Billboard") {
ret.geometries.forEach(item => {
typeId = ret.isPopulation ? item.typeId : ret.typeId;
typeId = item.isChildren ? item.typeId : ret.typeId;
entity.typeId = typeId;
entity.position = item.position;
entity.name = item.name;
entity.image = item.image;
entity.imageSize = item.imageSize;
entity.pixelSize = item.pixelSize;
entity.labelColor = item.labelColor;
entity.isLabelShow = item.isLabelShow;
entity.isFly = ret.isFly;
entity.show = ret.show;
try {
ZhiYunGisProperty.AddBillboard(entity);
} catch (e) {
console.log("绘制面出错:===>", e, item)
}
})
}
},
//加载线
AddPolyline: function (item) {
let entity = {
name: item.name,
typeId: item.typeId,
polyline: {
positions: NF.Cartesian3.fromDegreesArray(item.position),
// positions: NF.Cartesian3.fromDegreesArrayHeights(item.position),
width: item.width,
material: item.color,
clampToGround:true,
zIndex:20,
classificationType: NF.ClassificationType.BOTH
},
};
PlanningMap.PlanningMap1.push(entity);
},
//处理坐标
calcGeometryPolygon(geometry) {
let position = [];
let hole = [];
if (geometry.length > 1) {
calc(geometry[0]);
for (let i = 1; i < geometry.length; i++) {
let _hole = [];
calcHole(geometry[i], _hole);
hole.push(_hole)
}
} else {
calc(geometry)
}
function calc(geometry) {
if (geometry.length > 0) {
if (geometry[0] instanceof Array) {
// geometry.forEach((geo) => {
// calc(geo);
// })
for (let i = 0, len = geometry.length; i < len; i++) {
calc(geometry[i]);
}
} else {
position.push(...geometry);
}
}
}
function calcHole(geometry, array) {
if (geometry.length > 0) {
if (geometry[0] instanceof Array) {
for (let i = 0, len = geometry.length; i < len; i++) {
calcHole(geometry[i], array);
}
} else {
array.push(...geometry);
}
}
}
return { position: position, hole: hole };
},