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

setVisibleCoordinateBounds directly after onCreate fails #2719

Closed

Description

@tobrun

setVisibleCoorindateBounds was added in #2613.

While moving this to a separate feature Activity in #2716 ,
I noticed that it doesn't work if executed after MapView.onCreate

mMapView = (MapView) findViewById(R.id.mapView);
mMapView.setAccessToken(ApiAccess.getToken(this));
mMapView.setStyle(Style.DARK);
mMapView.onCreate(savedInstanceState);
mMapView.setVisibleCoordinateBounds(new CoordinateBounds(losAngeles, newYork), new RectF(200, 0, 200, 0), true);

If moved to a Snackbar, setVisibleCoordinateBounds works:

Snackbar.make(findViewById(android.R.id.content), R.string.action_visible_bounds_explanation, Snackbar.LENGTH_INDEFINITE)
       .setAction(android.R.string.ok, new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   mMapView.setVisibleCoordinateBounds(new CoordinateBounds(losAngeles, newYork), new RectF(200, 0, 200, 0), true);
               }
       }).show();

Activity

  1. added
    Android
    on Oct 22, 2015
  2. added this to the android-v2.2.0 milestone on Oct 22, 2015
  3. ljbade commented on Oct 22, 2015

    @ljbade
    Contributor

    Hmm that is strange. what happens if you try setting other things like zoom and lat/lng after onCreate

  4. tobrun commented on Oct 23, 2015

    @tobrun
    MemberAuthor

    what happens if you try setting other things like zoom and lat/lng after onCreate

    No issue, see PressForMarkerActivity

  5. ljbade commented on Oct 23, 2015

    @ljbade
    Contributor

    Hmm I can't see anything wrong.

    @1ec5 Does iOS have the same bug?

  6. 1ec5 commented on Oct 23, 2015

    @1ec5
    Contributor

    No, doesn't look like it, although MGLMapView doesn't really have an analogue to onCreate() that client code has to call. Is it possible that onCreate()'s call to setCenterCoordinate() is animating or operating on a delay, clobbering the call to setVisibleCoordinateBounds() later?

  7. ljbade commented on Oct 23, 2015

    @ljbade
    Contributor

    @1ec5 is easeTo with duration of 0 equal to jumpTo? as far as cancelling animation later

  8. ljbade commented on Oct 23, 2015

    @ljbade
    Contributor

    @tobrun what happens if you set the animation parameter to false

  9. 1ec5 commented on Oct 23, 2015

    @1ec5
    Contributor

    Yes, jumpTo() just calls easeTo() with a 0 duration.

  10. tobrun commented on Oct 23, 2015

    @tobrun
    MemberAuthor

    @ljbade true or false same result

  11. ljbade commented on Oct 23, 2015

    @ljbade
    Contributor

    Hmm puzzling going to need some C±+ debug

  12. tobrun commented on Oct 26, 2015

    @tobrun
    MemberAuthor

    Updating that following code works in Sirius:

    new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        mapView.setVisibleCoordinateBounds(new CoordinateBounds(mMyLocation, mAddressLatLng), new RectF(100, 0, 100, 0), true);
                    }
                });

    Haven't look at the internals yet for this issue.

  13. 2 remaining items

  14. tobrun commented on Nov 13, 2015

    @tobrun
    MemberAuthor

    Partially related to this issue is the following:

    // FIXME cleanup this method if fix for BoundingBox lands, currently not possible to determine SW and NE without BoundingBox
    private void createMarkerAndMoveViewport(final MapView mapView, LatLng start, LatLng stop, String stopText) {
        final Marker destination = mapView.addMarker(new MarkerOptions().position(stop).title(stopText));
    
        List<LatLng> coordinates = new ArrayList<>();
        coordinates.add(start);
        coordinates.add(stop);
    
        BoundingBox box = BoundingBox.fromLatLngs(coordinates);
        LatLng southWest = new LatLng(box.getLatSouth(), box.getLonWest());
        LatLng northEast = new LatLng(box.getLatNorth(), box.getLonEast());
    
        Resources resources = mapView.getResources();
        float hMargin = resources.getDimension(R.dimen.marker_horizontal_margin);
        float tMargin = resources.getDimension(R.dimen.marker_top_margin);
        float bMargin = resources.getDimension(R.dimen.marker_bottom_margin);
        mapView.setVisibleCoordinateBounds(new CoordinateBounds(southWest, northEast), new RectF(hMargin, tMargin, hMargin, bMargin), true);
    
        // Save search
        HistoryItem entry = new HistoryItem();
        entry.key = stopText;
        entry.latitude = stop.getLatitude();
        entry.longitude = stop.getLongitude();
        entry.save();
    
     final Marker destination = mapView.addMarker(new MarkerOptions().position(stop).title(stopText));
      mapView.post(new Runnable() {
          @Override
          public void run() {
              mapView.selectMarker(destination);
          }
      });
    }

    The last few lines are not repositioning the InfoWindow correctly

  15. modified the milestones: android-v2.3.0, on Dec 4, 2015
  16. tobrun commented on Feb 17, 2016

    @tobrun
    MemberAuthor

    This is no longer applicable, API changed and is no longer reproducible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidbug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions