使用无效数据调用函数DocumentReference.set()。不支持嵌套数组

时间:2020-02-15 05:30:54

标签: javascript angular firebase google-cloud-firestore leaflet

我试图使用Angular和angularfire构建项目。我的项目是使用传单地图绘制多边形,然后将坐标多边形推到FireStore。问题是我在完成绘制后正在获取数组坐标多边形,而我试图将它们推到Firestore上时却出错了

core.js:6014 ERROR Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: Function DocumentReference.set() called with invalid data. Nested arrays are not supported
FirebaseError: Function DocumentReference.set() called with invalid data. Nested arrays are not supported
    at new FirestoreError (index.cjs.js:351)
    at ParseContext.push../node_modules/@firebase/firestore/dist/index.cjs.js.ParseContext.createError (index.cjs.js:20790)
    at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (index.cjs.js:21010)
    at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseArray (index.cjs.js:21044)
    at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (index.cjs.js:21012)
    at index.cjs.js:21031
    at forEach (index.cjs.js:455)
    at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseObject (index.cjs.js:21030)
    at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseData (index.cjs.js:20984)
    at UserDataConverter.push../node_modules/@firebase/firestore/dist/index.cjs.js.UserDataConverter.parseSetData (index.cjs.js:20845)
    at resolvePromise (zone-evergreen.js:797)
    at new ZoneAwarePromise (zone-evergreen.js:879)
    at Module.__awaiter (tslib.es6.js:69)
    at WeatherNowComponent.addIdea (weather-now.component.ts:201)
    at Object.eval [as handleEvent] (WeatherNowComponent.html:21)
    at handleEvent (core.js:43992)
    at callWithDebugContext (core.js:45631)
    at Object.debugHandleEvent [as handleEvent] (core.js:45246)
    at dispatchEvent (core.js:29803)
    at core.js:42924

对象坐标的Json格式:

0: LatLng {lat: 35.53222622770339, lng: 43.57177734375001}
1: LatLng {lat: 33.687781758439364, lng: 44.84619140625001}
2: LatLng {lat: 33.32134852669881, lng: 45.43945312500001}
3: LatLng {lat: 35.29943548054545, lng: 45.87890625}
4: LatLng {lat: 35.97800618085566, lng: 45.3076171875}
5: LatLng {lat: 35.995785386420344, lng: 44.82421875000001}

Firebase服务类

export interface PostionsAddress {
  coords: any,
}

@Injectable({
  providedIn: 'root'
})
export class PostionService {

  private ideas: Observable<PostionsAddress[]>;
  private ideaCollection: AngularFirestoreCollection<PostionsAddress>;


  constructor(private afs: AngularFirestore) {
    this.ideaCollection = this.afs.collection<PostionsAddress>('Locations');
    this.ideas = this.ideaCollection.snapshotChanges().pipe(
      map(actions => {
        return actions.map(a => {
          const data = a.payload.doc.data();
          const id = a.payload.doc.id;
          return { id, ...data };
        });
      })
    );
  }
  getAllMarkers() {
    return this.afs.collection("Locations").valueChanges();
  }
  getIdeas(): Observable<PostionsAddress[]> {
    return this.ideas;
  }

  getIdea(id: string): Observable<PostionsAddress> {
    return this.ideaCollection.doc<PostionsAddress>(id).valueChanges().pipe(
      take(1),
      map(idea => {
        idea.coords= id;
        return idea
      })
    );
  }

  addIdea(idea: PostionsAddress): Promise<DocumentReference> {
    return this.ideaCollection.add(idea);
  }


  deleteIdea(id: string): Promise<void> {
    return this.ideaCollection.doc(id).delete();
  }

}

首页ts

export class WeatherNowComponent {

  map: Map;
  mark: Marker
  public $location: Observable<PostionsAddress[]>;
  report: PostionsAddress = {
    coords: '',

  };

  constructor(private locationservice:PostionService) {

  }

  async ngOnInit() {

    this.leafletMap()
    // this.getData()
    this.$location = this.locationservice.getIdeas()

  }

 --- Map initializing -- - 
  leafletMap() {
    let cloud = tileLayer(`http://maps.openweathermap.org/maps/2.0/weather/CL/{z}/{x}/{y}?
  &appid=9de243494c0b295cca9337e1e96b00e2`, {
      attribution: '2019 © منظومة ارصاد العراق',
      minZoom: 5,
      maxZoom: 9,
      opacity: 0.8
    })

      console.log(this.map.getBounds().toBBoxString())

    }

    var editableLayers = new L.FeatureGroup();
    this.map.addLayer(editableLayers);

    var editableLayers = new L.FeatureGroup();
    this.map.addLayer(editableLayers);


    var options = {
      position: 'topright',
    }

    var drawControl = new L.Control.Draw(options);
    this.map.addControl(drawControl);
    this.map.on(Draw.Event.CREATED, (a => {

        layer = a.layer;

        -------- Pushing coords here after drawing --------

        this.report.coords= layer.getBounds()

      editableLayers.addLayer(layer);

    }))


  }

  async addIdea() {
    this.locationservice.addIdea(this.report).then(async () => {

    }, err => {
      console.log(err)
    });
  }




}

请问有什么主意吗?

0 个答案:

没有答案