Я пытаюсь построить проект, используя Angular и angularfire. Мой проект о рисовании многоугольника с использованием карты листовки, затем pu sh координирует многоугольник с FireStore. Проблема в том, что я получаю многоугольник координат массива после окончания рисования, и пока я пытаюсь вытащить их sh в 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();
}
}
Home 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)
});
}
}
Любая идея, пожалуйста?