* feat: 完善 dataArray 的处理逻辑

* style: lint style
This commit is contained in:
YiQianYao 2022-04-08 18:58:13 +08:00 committed by GitHub
parent f088f85db1
commit f920c7a92c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 48 deletions

View File

@ -520,19 +520,13 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
this.clusterZoom = 0;
return this;
}
public setData(data: any, options?: ISourceCFG) {
const currentSource = this.getSource();
if (this.inited) {
if (currentSource && !isEqual(currentSource.parser, options)) {
// 在 source 不一致的情况下,需要重新设置 source parser/data 格式解析规则需要重新生成)
this.source(new Source(data, options));
this.sourceEvent();
} else {
this.layerSource.setData(data, options);
}
// this.layerSource.setData(data, options);
} else {
this.on('inited', () => {
const currentSource = this.getSource();
if (!currentSource) {
// 执行 setData 的时候 source 还不存在(还未执行 addLayer
this.source(new Source(data, options));

View File

@ -11,6 +11,11 @@ import rewind from '@mapbox/geojson-rewind';
export default function json(data: IJsonData, cfg: IParserCfg): IParserData {
const { x, y, x1, y1, coordinates } = cfg;
const resultData: IParseDataItem[] = [];
if (!Array.isArray(data)) {
return {
dataArray: [],
};
}
data.forEach((col: IJsonItem, featureIndex: number) => {
let coords = [];
if (x && y) {

View File

@ -49,59 +49,61 @@ export default class Amap2demo extends React.Component {
},
geometry: {
type: 'Point',
coordinates: [120, 30, 0.0],
coordinates: [125, 30, 0.0],
},
},
],
};
const layer = new PointLayer()
// .source(data)
.source({
type: 'FeatureCollection',
crs: {
type: 'name',
properties: { name: 'urn:ogc:def:crs:OGC:1.3:CRS84' },
},
features: [
{
type: 'Feature',
properties: {
id: 'ak16994521',
mag: 2.3,
time: 1507425650893,
felt: null,
tsunami: 0,
},
geometry: {
type: 'Point',
coordinates: [125, 30, 0.0],
},
},
],
})
// .source({
// type: 'FeatureCollection',
// crs: {
// type: 'name',
// properties: { name: 'urn:ogc:def:crs:OGC:1.3:CRS84' },
// },
// features: [
// {
// type: 'Feature',
// properties: {
// id: 'ak16994521',
// mag: 2.3,
// time: 1507425650893,
// felt: null,
// tsunami: 0,
// },
// geometry: {
// type: 'Point',
// coordinates: [125, 30, 0.0],
// },
// },
// ],
// })
.shape('circle')
.size(40)
.color('#000');
scene.on('loaded', () => {
layer.setData(
[
{
lng: 120,
lat: 30,
},
],
{
parser: {
type: 'json',
x: 'lng',
y: 'lat',
},
},
);
// layer.setData(
// [
// {
// lng: 125,
// lat: 30,
// },
// ],
// {
// parser: {
// type: 'json',
// x: 'lng',
// y: 'lat',
// },
// },
// );
// layer.setData(data)
scene.addLayer(layer);
layer.setData(data);
});
}