Mapsforge 不会从 Realm 重绘集群 POI

Mapsforge does not redraw cluster POI from Realm

我使用 Realm 从数据库加载 POI。接下来将这个点添加到mapsforge的集群实现中。 此代码运行良好:

 RealmResults<GasolineRealm> gasolineRealms = presenter.getRealm().where(GasolineRealm.class)
            .findAll();
    for(int i=0; i<gasolineRealms.size(); i++){
        geoItems.add(new GasolineGeoItem(gasolineRealms.get(i).getId(),
                gasolineRealms.get(i).getLocalizationRealms().get(0).getTitle(),
                gasolineRealms.get(i).getCoordinateLatitude(),
                gasolineRealms.get(i).getCoordinateLongitude()));
        clusterer.addItem(geoItems.get(i));
    }

它在地图上绘制了所有 POI,但是如果我将 RxJava 用于 Realm 集群,则永远不会在地图上添加 POI。 这是代码:

Realm.getDefaultInstance().where(GasolineRealm.class)
            .findAllAsync()
            .asObservable()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<RealmResults<GasolineRealm>>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {

                }

                @Override
                public void onNext(RealmResults<GasolineRealm> gasolineRealms) {
                    for(int i=0; i<gasolineRealms.size(); i++){
                        geoItems.add(new GasolineGeoItem(gasolineRealms.get(i).getId(),
                                gasolineRealms.get(i).getLocalizationRealms().get(0).getTitle(),
                                gasolineRealms.get(i).getCoordinateLatitude(),
                                gasolineRealms.get(i).getCoordinateLongitude()));
                        clusterer.addItem(geoItems.get(i));
                    }
                }
            });

如果你这样做,两者几乎是等价的

     Subscription subscription = presenter.getRealm().where(GasolineRealm.class)
        .findAllAsync()
        .asObservable()
        .filter(RealmResults::isLoaded)
        .first()
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Observer<RealmResults<GasolineRealm>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(RealmResults<GasolineRealm> gasolineRealms) {
                for(int i=0; i<gasolineRealms.size(); i++){
                    GasolineRealm gasolineRealm = gasolineRealms.get(i);
                    geoItems.add(new GasolineGeoItem(gasolineRealm.getId(),
                            gasolineRealm.getLocalizationRealms().get(0).getTitle(),
                            gasolineRealm.getCoordinateLatitude(),
                            gasolineRealm.getCoordinateLongitude()));
                    clusterer.addItem(geoItems.get(i));
                }
            }
        });