1
私はmergeMapを使用して、ポイントに基づいてアドレスを見つける一組のクエリを生成しています。私は各応答をオブジェクトの配列にマップします。mergeMapがあまりにも早く完了しました
//ptosDistintos = ['-34.5466 58.4363', '-34.5523 58.4486', ...]
this.suscCalcularDirecciones = Observable.from(ptosDistintos)
.mergeMap(pos => {
//I convert every position to a latLng object (Leaflet)
const [lat, lng] = pos.split(' ');
const latlng = L.latLng(+lat, +lng);
//I make requests to Google to figure out addresses
return this.http.get(`https://maps.googleapis.com/maps/api/geocode/json?latlng=${latlng.lat},${latlng.lng}`)
.filter(x => x.length)
//I return the address to the mergeMap.
.map(direccion =>
[pos, direccion.length ? direccion[0].formatted_address : '(no encontrada)'];
);
})
.finally(() => {
//I'm deleting the suscription once it is complete because in template I check for completion by checking emptyness of the subscription.
delete this.suscCalcularDirecciones;
})
.subscribe(posDir => {
const [pos, dir] = posDir;
for (let i of agrup[pos].indexes) {
this.historico[i].direccion = dir;
}
this.historico = this.historico.slice();
});
ただし、mergeMapによって生成される観測値は、あまりに早く完了しています。 "finally"命令は、 "nexts"のいくつか(最初ではないにしても)の後に実行されます。 Googleへのすべてのクエリが完了したら、私はそれを呼び出すために何ができますか?
デモを作成できますか?コードは 'delete this.suscCalcularDirecciones'を除いて私にはうまく見えます。これを行う必要はありません。 – martin
私はサブスクリプションの空きをチェックしてhtmlの補完をチェックしたいからです。私は、もし私がその行を削除しても、これは何の役にも立ちません。私の質問は、なぜこれが起こっているのかを指しています。 私はデモを試みましたが、stackoverflowスニペットツールでRxjsをインポートする際に問題がありました。 : – Umagon
このテンプレートを使用することができますhttp://jsbin.com/bumeroq/2/edit?html,js,output – martin