Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function geoJSON(data, cfg) {
// 矢量瓦片图层不做 rewind
rewind(data, true);
const resultData = [];
const featureKeys = {};
data.features = data.features.filter(item => {
return item != null && item.geometry && item.geometry.type && item.geometry.coordinates && item.geometry.coordinates.length > 0;
});
// 数据为空时处理
let i = 0;
turfMeta.flattenEach(data, (currentFeature, featureIndex) => { // 多个polygon 拆成一个
const coord = getCoords(currentFeature);
let id = featureIndex + 1;
if (cfg.idField && currentFeature.properties[cfg.idField]) {
const value = currentFeature.properties[cfg.idField];
id = djb2hash(value) % 1000019;
featureKeys[id] = {
index: i++,
idField: value
export default function geoJSON(
data: FeatureCollection,
cfg?: IParserCFG,
): IParserData {
rewind(data, true); // 设置地理多边形方向 If clockwise is true, the outer ring is clockwise, otherwise it is counterclockwise.
const resultData: IParseDataItem[] = [];
const featureKeys: IFeatureKey = {};
data.features = data.features.filter((item: Feature) => {
const geometry: Geometry | null = item.geometry as Geometry;
return (
item != null &&
geometry &&
geometry.type &&
geometry.coordinates &&
geometry.coordinates.length > 0
);
});
// 数据为空时处理
const i = 0;
// multi polygon 拆分
turfMeta.flattenEach(
if (x1 && y1) { // 弧线 或者线段
coords = [[ col[x], col[y] ], [ col[x1], col[y1] ]];
}
if (coordinates) {
let type = 'Polygon';
if (!Array.isArray(coordinates[0])) {
type = 'Point';
}
if (Array.isArray(coordinates[0]) && !Array.isArray(coordinates[0][0])) {
type = 'LineString';
}
const geometry = {
type,
coordinates: [ ...col[coordinates] ]
};
rewind(geometry, true);
coords = geometry.coordinates;
}
col._id = featureIndex + 1;
const dataItem = {
...col,
coordinates: coords
};
resultdata.push(dataItem);
});
return {
this.loadGeoJSON(params, (err: ?Error, data: ?Object) => {
if (err || !data) {
return callback(err);
} else if (typeof data !== 'object') {
return callback(new Error(`Input data given to '${params.source}' is not a valid GeoJSON object.`));
} else {
rewind(data, true);
try {
this._geoJSONIndex = params.cluster ?
new Supercluster(getSuperclusterOptions(params)).load(data.features) :
geojsonvt(data, params.geojsonVtOptions);
} catch (err) {
return callback(err);
}
this.loaded = {};
const result = {};
if (perf) {
const resourceTimingData = perf.finish();
// it's necessary to eval the result of getEntriesByName() here via parse/stringify
// late evaluation in the main thread causes TypeError: illegal invocation
[parseFloat(col[x1]), parseFloat(col[y1])],
];
}
if (coordinates) {
let type = 'Polygon';
if (!Array.isArray(coordinates[0])) {
type = 'Point';
}
if (Array.isArray(coordinates[0]) && !Array.isArray(coordinates[0][0])) {
type = 'LineString';
}
const geometry = {
type,
coordinates: [...col[coordinates]],
};
rewind(geometry, true);
coords = geometry.coordinates;
}
const dataItem = {
...col,
_id: featureIndex,
coordinates: coords,
};
resultData.push(dataItem);
});
return {