-
-
Notifications
You must be signed in to change notification settings - Fork 854
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
[Bug]: LocationPuck
bearing not visible on Android
#3391
Comments
You should use a custom image to show LocationPuck bearing on Android.
|
Hi there! for some reason this custom image is not working for my project in android. Is there any way i could add an SVG icon here instead of the PNG? React Native Version Platform @rnmapbox/maps version Code: import React from 'react'; const ShowMap = () => { <MapboxGL.LocationPuck Error that i am encountering: Error while updating property 'images' of a view managed by: RNMBXImages |
@philiplindberg nope svg is not supported, sorry |
Just a quick question @smartmedev or may be you can answer @mfazekas. How can i import the png images (markerUserIcon, headingIcon, headingIconXS) in my file? import markerUserIcon from './markerUserIcon.png'; i have placed the icons at the same path as my project file on which i want to use the image. am i doing it correct or anything i need to change here? |
Hi @fahadShah23 , in react native you cannot import images with "import". You need require. Here's an example: on my /app/utils/icons.js file:
then on my /app/screens/HomeScreen.js import icons like this:
|
Hi @smartmedev thank you for your response. I have tried your solution but unfortunately image is still not appearing at my end. No sure what wrong i am doing here, can you please help identify. File Path: /home/{user}/{projectName}/libs/pattern/src/ui/features/Field/DrawField/DrawFieldFeature.native.tsx here is how i am getting them in my file i.e. 'DrawFieldFeature.native.tsx': const headingIcon = require('./heading.png'); Here is how i am using the above icons in Images & LocationPuck:
Also just to check if the images are correctly imported in the file, i console the headingIcon, markerUserIcon and headingIconXS values and it gives my an numeric value i.e. 6. is it correct or it should give some kind or uri? |
hi @fahadShah23 if images are in the same folder, have you tried to import like this ?
Also, use double quotes "" for the name of image in "images" attribute of element, you didn't put it in your example.
Let me know if it works, i think that require should give the path not numbers, but I'm not sure at all. |
I have tried this but I can only get the import React from 'react';
import { Images, LocationPuck } from '@rnmapbox/maps';
export default function UserLocationMarker() {
const headingIcon = require('./heading.png');
const userIcon = require('./user-location.png');
return (
<>
<Images
images={{
headingArrow: headingIcon,
userLocation: userIcon,
}}
/>
<LocationPuck
// bug? topImage and bearingImage do not work well together
// topImage={'userLocation'}
puckBearingEnabled={true}
puckBearing={'heading'}
bearingImage={'headingArrow'}
visible={true}
pulsing={{ isEnabled: true, radius: 50.0, color: 'lightblue' }}
/>
</>
);
} I'm running Mapbox version |
I had the same issue as you and came up with an alternative, hope this helps for you. I have a prop called puckBearingEnabled, if that is true and the platform is android, it shows a custom image that already has a bearing arrow in it (which i created myself). I have added the image to the comment in PNG (so you can use it yourself) or SVG (so you can edit it in figma or other tool)
|
if anyone is looking for a way to use the View component or SVG (react-native-svg), here is an example: ...
import {LocationPuck, Images, Image} from '@rnmapbox/maps';
const ImagesWrapper = ({children}) => {
// fix ios issue with overlapping the map layer
if (Platform.OS === 'ios') {
return <View style={styles.hiddenLayer}>{children}</View>;
}
return <>{children}</>;
};
const CustomLocation = () => {
return (
<>
<ImagesWrapper>
<Images>
<Image name="topImageID">
<SomeSvgComponent />
</Image>
<Image name="shadowImageID">
<SomeViewComponent />
</Image>
</Images>
</ImagesWrapper>
<LocationPuck
shadowImage="shadowImageID"
topImage="topImageID"
puckBearingEnabled={true}
puckBearing="heading"
pulsing={{
isEnabled: false,
}}
/>
</>
);
};
const styles = StyleSheet.create({
hiddenLayer: {
position: 'absolute',
top: -1000,
left: -1000,
},
}); |
It seems to me like the puckBearingEnabled property just gets ignored inside Android? Like right here it's supposed to set the bearing image and it only pays attention to the deprecated androidRenderMode. It looks to me like that function in particular is just a poor imitation of the Android SDK's createDefault2DPuck. Which is what should be used instead I think.. Anyhow, I'll see if I have time make a PR so everybody can stop messing around with loading custom images for a bearing indicator hahaha. |
Mapbox Implementation
Mapbox
Mapbox Version
default
React Native Version
0.73.4
Platform
Android
@rnmapbox/maps
version10.1.15
Standalone component to reproduce
Observed behavior and steps to reproduce
When rendering the
LocationPuck
with its bearing enabled on Android, the bearing does not appear. The bearing does appear on iOS.Expected behavior
The
LocationPuck
's bearing should be visible on both Android and iOS if enabled.Notes / preliminary analysis
No response
Additional links and references
No response
The text was updated successfully, but these errors were encountered: