3

Is it possible to change the location of the compass in React-Native Mapbox GL? It currently defaults to the top-right and I have been trying to find how to move it to the top-left.

<Mapbox.MapView
                    ref={component => this.map = component}
                    styleURL={this.state.mapStreetView}
                    zoomLevel={this.state.defaultZoom}
                    centerCoordinate={[this.state.long, this.state.lat]}
                    showUserLocation={true}
                    onPress={this.onLocationPress}
                    zoomEnabled={true}>
jengin
  • 31
  • 1
  • 3
  • Can you provide your code sample? – VerySeriousSoftwareEndeavours Jul 19 '19 at 01:43
  • @McWayWeb I added the code for the component. Its jut standard code. Are you familiar with Mapbox for react native? – jengin Jul 19 '19 at 18:01
  • I am having the same issue where I am not able to update the position of the compass icon or even change the icon to use custom ones - I think the feature is present on native side in the mapbox-gl-native repo, but its RN bindings are not yet added. See - https://github.com/react-native-mapbox-gl/maps/issues/112 – Awadhoot Aug 02 '19 at 14:24

3 Answers3

1

It's possible with iOS - since #389. See compassViewPosition and compassViewMargins on MapView

mfazekas
  • 5,589
  • 1
  • 34
  • 25
0

No you can't move the compass position, you can only show it or hide it with the compassEnabled property. (https://github.com/react-native-mapbox-gl/maps/blob/master/docs/MapView.md)

Simon Robert
  • 111
  • 5
0

there is a bug in react-native-mapbox-gl/maps 8.5.0 version in android part. They cut density to int when multiply layout pixels and density. (for example, my devices has 2.8125 and 2.75 dencity, but mapbox counts them as 2.

the bug is in @react-native-mapbox-gl/maps/android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java in updateUISettings method and looks like

int pixelDensity = (int)getResources().getDisplayMetrics().density;

so on js side you can simply fix this with coefficient

const androidPixelRatio = PixelRatio.get();
const androidDensityCoefficient = androidPixelRatio / Math.floor(androidPixelRatio);
compassViewMargins = {
    x: layoutX * androidDensityCoefficient;
    y: layoutY * androidDensityCoefficient;
};
<MapboxGL.MapView
    {...restProps}
    compassViewMargins={compassViewMargins}
/>
Evgen_she
  • 11
  • 2