Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Make InfoWindow dynamically updatable #5237

Closed
tobrun opened this issue Jun 4, 2016 · 8 comments
Closed

Make InfoWindow dynamically updatable #5237

tobrun opened this issue Jun 4, 2016 · 8 comments
Labels
Android Mapbox Maps SDK for Android

Comments

@tobrun
Copy link
Member

tobrun commented Jun 4, 2016

We expose setTitle and setSnippet on Marker to set the contents of the default InfoWindow. At this point you can only set them once. Calling these methods consecutively will not always result in changing the contents of the InfoWindow (eg. when it's already open). We have been hearing about the requirement to do this and this follows the line set in 4.1.0 to make other Marker attributes updatable.

We should also look into the possibility to expose an InfoWindowAdapter equivalent for this use-case by exposing an invalidate method on InfoWindowAdapter (this will result in recreating the InfoWindow).

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Jun 4, 2016
@tobrun tobrun added this to the android-v4.2.0 milestone Jun 4, 2016
bleege added a commit that referenced this issue Jun 6, 2016
@bleege
Copy link
Contributor

bleege commented Jun 6, 2016

I've started work on this functionality by re-enabling access to Marker.setTitle() and Marker.setSnippet() to be the API for updating this content as this is consistent with how the other dynamic marker APIs work (Marker.setPosition() and Marker.setIcon() API ). I've also updated the test case for this in the TestApp's DynamicMarkerChangeActivity so that work on this can commence. So far the InfoWindow moves from location to location just fine, but the content doesn't update. As shown below, when the FAB is originally pressed to do the initial toggle Chelsea's content appears above Arsensal's marker and icon (sorry @jacquestardie ).

device-2016-06-06-161305
Original State

device-2016-06-06-161328
State After First Toggle

bleege added a commit that referenced this issue Jun 6, 2016
bleege added a commit that referenced this issue Jun 6, 2016
@jqtrde
Copy link

jqtrde commented Jun 6, 2016

@bleege I hope this is at the top top top of your list of things to do 😄

@bleege
Copy link
Contributor

bleege commented Jun 6, 2016

I've now added the functionality to update the existing InfoWindow that uses the default InfoWindow for setTitle() and setSnippet(). There's a bit of race condition causing the InfoWindow content to be updated a split second before the InfoWindow is moved to it's new location. I think this has to do with the update process and the (likely unusual) use case as this case is setting all four properties at once and then calling updateMarker() after each property is set.

The next steps are to:

  1. Verify that updated title and snippet works in InfoWindow when the InfoWindow is closed between FAB toggles
  2. Verify that the updated title and snippet works in InfoWindow when the InfoWindow isn't moved
  3. Try to minimize the number of updateMarker() calls
   // Use Case Updating all four 4 items
    private void updateMarker() {
        // update model
        boolean first = (boolean) mMapView.getTag();
        mMapView.setTag(!first);

        // update marker
        mMarker.setPosition(first ? LAT_LNG_CHELSEA : LAT_LNG_ARSENAL);
        mMarker.setIcon(mIconFactory.fromResource(first ? R.drawable.ic_chelsea : R.drawable.ic_arsenal));
        mMarker.setTitle(first ? getString(R.string.dynamic_marker_chelsea_title) : getString(R.string.dynamic_marker_arsenal_title));
        mMarker.setSnippet(first ? getString(R.string.dynamic_marker_chelsea_snippet) :  getString(R.string.dynamic_marker_arsenal_snippet));
    }

// Update being run after each setXXX() method is called
MapboxMap map = getMapboxMap();
if (map != null) {
    map.updateMarker(this);
}

ezgif com-video-to-gif 1

@bleege
Copy link
Contributor

bleege commented Jun 6, 2016

Verify that updated title and snippet works in InfoWindow when the InfoWindow is closed between FAB toggles

☑️

ezgif com-video-to-gif

@bleege
Copy link
Contributor

bleege commented Jun 7, 2016

Verify that the updated title and snippet works in InfoWindow when the InfoWindow isn't moved

☑️

location-stays-same

@bleege
Copy link
Contributor

bleege commented Jun 7, 2016

Commenting out the updateMarker code from refreshInfoWindowContent() still updates the InfoWindow content (yay!), but I'm also still seeing a bit of lag between the two. I'm going to try removing the updateMarker() calls that are generated by the setPosition() and setIcon() that are part of this test.

            MapboxMap map = getMapboxMap();
            if (map != null) {
                map.updateMarker(this);
            }

2016-06-07 11_04_02

@bleege
Copy link
Contributor

bleege commented Jun 7, 2016

Discussed the split second offset issue with @zugaldia @cammace @ivovandongen this morning and we decided to ship with this to start with and look to refine over time. The fundamental issue is that the InfoWindow is rendered at the Java View level while the annotation is rendered in Core GL.

@bleege
Copy link
Contributor

bleege commented Jun 7, 2016

Squashed and Merged into release-android-v4.1.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

No branches or pull requests

3 participants