Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounds padding not applied when using setCamera() on iOS on version 7.2.0 #715

Closed
cristian-calugar opened this issue Mar 10, 2020 · 8 comments
Labels
bug 🪲 Something isn't working invalid This doesn't seem right upstream the bug source is a bug in native mapbox gl

Comments

@cristian-calugar
Copy link

cristian-calugar commented Mar 10, 2020

Describe the bug
When calling setCamera with bounds padding on 7.2.0, the padding is not applied on iOS. The padding is applied in Android and also on iOS on version 7.0.9.

To Reproduce

  fitMapBoundsAndHeading = (
    bounds: Bounds,
    padding: [number, number, number, number],
    heading?: number,
    pitch?: number
  ) => {
    let cameraSettings = {
      animationDuration: 1000
    };

    cameraSettings["bounds"] = {
      ne: bounds.northEast,
      sw: bounds.southWest,
      paddingTop: padding[0],
      paddingRight: padding[1],
      paddingBottom: padding[2],
      paddingLeft: padding[3]
    };

    if (heading !== undefined) {
      cameraSettings["heading"] = heading;
    }

    if (pitch !== undefined) {
      cameraSettings["pitch"] = pitch;
    }

    this.camera?.setCamera(cameraSettings);
  };

  render() {
    const { children } = this.props;
    return (
      <MapboxGL.MapView
        ref={this.map}
        style={styles.mapView}
        attributionEnabled={false}
        logoEnabled={false}
        compassEnabled={false}
      >
        <MapboxGL.Camera
          ref={this.setCamera}
          zoomLevel={MIN_ZOOM}
          minZoomLevel={MIN_ZOOM}
        />
        {children}
      </MapboxGL.MapView>
    );
  }

Expected behavior
Bounds padding should be taken in consideration when setting camera, to be able to arrange the elements we want to display in the specified bounds in a specific area of the screen.

Versions (please complete the following information):

  • Platform: iOS
  • Device: iPhone7
  • Emulator/ Simulator: no
  • OS: iOS12.3.1
  • SDK Version: 7.2.0
  • React Native Version: 0.61.5

Edit ferdicus: used correct code formatting

@cristian-calugar
Copy link
Author

Sorry for the code formatting, I really tried to fix it, but this markdown beats me :)

@cristian-calugar
Copy link
Author

cristian-calugar commented Mar 11, 2020

This issue reproduces on version 8.0.0-beta1 too.

Edit: On 8.0.0-beta1 it stopped working on Android too. Was there any change on native SDKs regarding setting of padding, that is not handled yet?

@cristian-calugar
Copy link
Author

On Android the issue appeared after the upgrade to mapbox-android-sdk 9.0.0.
If I downgrade to mapbox-android-sdk 8.6.3 it works fine.

@cristian-calugar
Copy link
Author

On iOS the issue appeared after the upgrade to Mapbox-iOS-SDK 5.7.0. It works fine if I downgrade to Mapbox-iOS-SDK 5.6.1.

@mfazekas
Copy link
Contributor

@mfazekas
Copy link
Contributor

Also there is this change but it should be in 5.6.1 and 8.6.3 mapbox/mapbox-gl-native#14664

@cristian-calugar
Copy link
Author

I checked all MapBox-android-sdk changes between 8.6.0 and 9.0.0 and there is nothing related to camera padding. Only fi there was a change in mapbox-gl-native library.

@mfazekas mfazekas added bug 🪲 Something isn't working upstream the bug source is a bug in native mapbox gl invalid This doesn't seem right labels Apr 2, 2020
@mfazekas
Copy link
Contributor

mfazekas commented Apr 2, 2020

@cristian-calugar I could not reproduce the issue on Android w mapbox/9.0.0. If you disagree Please attach a complete sample like bellow.

import React from 'react';
import {Button} from 'react-native';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
} from '@react-native-mapbox-gl/maps';

const dist = 0.002;
const padding = 100;

const aLine = {
  type: 'LineString',
  coordinates: [
    [-74.00597 - dist, 40.71427 - dist],
    [-74.00597 + dist, 40.71427 + dist],
  ],
};

class BugReportExample extends React.Component {
  render() {
    return (
      <>
        <Button
          title="move"
          onPress={() => {
            this.cameraRef.setCamera({
              bounds: {
                ne: [-74.00597 - dist, 40.71427 - dist],
                sw: [-74.00597 + dist, 40.71427 + dist],
                paddingLeft: padding * 1.1,
                paddingRight: padding * 1.1,
                paddingTop: padding * 1.1,
                paddingBottom: padding * 1.1,
              },
            });
          }}
        />
        <MapView style={{flex: 1}}>
          <Camera
            ref={ref => (this.cameraRef = ref)}
            bounds={{
              ne: [-74.00597 - dist, 40.71427 - dist],
              sw: [-74.00597 + dist, 40.71427 + dist],
              paddingLeft: padding,
              paddingRight: padding,
              paddingTop: padding,
              paddingBottom: padding,
            }}
          />
          <ShapeSource id="idStreetLayer" shape={aLine}>
            <LineLayer id="idStreetLayer" style={{lineWidth: 4.0}} />
          </ShapeSource>
        </MapView>
      </>
    );
  }
}

export default BugReportExample;

@mfazekas mfazekas closed this as completed Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working invalid This doesn't seem right upstream the bug source is a bug in native mapbox gl
Projects
None yet
Development

No branches or pull requests

2 participants