maps icon indicating copy to clipboard operation
maps copied to clipboard

Symbol Layer aren't displayed on Android

Open martinfrouin opened this issue 7 years ago • 12 comments

Describe the bug The symbols aren't displayed on Android with the 7.0.1 release It works fine on iOS It used to work fine on the 7.0.0rc3

To Reproduce

  <View>
    <MapboxGL.Images images={{ assets: icons }} />
    <MapboxGL.ShapeSource
      id="scooters"
      shape={shape(collection)}
      hitbox={{ width: 10, height: 10 }}
      {...props}
      onPress={({ nativeEvent }) => onPress(nativeEvent.payload.properties)}
    >
      <MapboxGL.SymbolLayer
        id="scooter"
        style={styles.scooter}
        minZoomLevel={minZoomLevel}
      />
    </MapboxGL.ShapeSource>
  </View>

Screenshots IMG_5517

Left: Expected -> iOS Right: Issue -> Android

Versions:

  • Platfrom: Android
  • Device: Honor 8X
  • OS: Android 9
  • SDK Version: 28
  • React Native Version: 0.59.10

martinfrouin avatar Aug 07 '19 09:08 martinfrouin

Hi, can I possibly see the rest of the code, specifically how this works:

shape={shape(collection)}

allthetime avatar Aug 07 '19 22:08 allthetime

import { featureCollection, point } from '@turf/helpers'

const feature = ({ coordinates, status, hasBoost, ...props }) => {
  const type = hasBoost ? 'boosted' : 'scooter'
  const icon = `${type}_${status}`

  return point(
    coordinates,
    {
      icon: icons[icons.indexOf(icon)] || icons[0],
      coordinates,
      ...props
    },
    { id: props.id }
  )
}

const shape = (collection = []) => featureCollection(collection.map(feature))

And collection is my coordinate list

martinfrouin avatar Aug 08 '19 07:08 martinfrouin

I have succed to make it work on this way neither, I have to pass the icon directly on SymbolLayer style and display one ShapeSource for each marker type.

class CustomMarkerTest extends React.PureComponent<Props, OwnState> {
  constructor(props: Props) {
    super(props);
  }

  handleClick = (e: { nativeEvent: { payload: { id: string; }; }; }) => {
    this.props.openModal(e.nativeEvent.payload.id);
  }

  render() {
    return (
      <MapboxGL.ShapeSource
        hitbox={{ width: 44, height: 44 }}
        id='markers_shapesource'
        shape={{
          type: 'FeatureCollection', features: this.props.markerFeatures
        }}
        onPress={this.handleClick}
      >
        <MapboxGL.SymbolLayer
          id={`markers_symbollayer`}
          style={mapStyles.icon}
        >
        </MapboxGL.SymbolLayer>
      </MapboxGL.ShapeSource>
    );
  }
}

const mapStyles = {
  icon: {
    iconImage: markeIcon,
    iconIgnorePlacement: true,
    iconSize: 0.06
  }
};

I think the problem isn't on ShapeSource but on Images component.

ethaqnix avatar Aug 13 '19 08:08 ethaqnix

I am experiencing the same issue.

Tried with 7.0.1 and 7.0.0-rc3 and neither are working on Android. It is working fine on iOS devices for both versions.

I have had similar issues (version 6.x) in the past with layer and have added a key to the components, this time it does not work.

karlguillotte avatar Aug 13 '19 19:08 karlguillotte

I just fixed my problem. Apparently, I have not completely updated my style to the latest style specs. Older specs still work on iOS, but they do not on Android.

{
        iconImage: '{icon}', // PREVIOUS STYLE SPECS
        iconImage: ['get', 'icon'],  // NEW STYLE SPECS
        iconAllowOverlap: true,
        iconSize: 0.35,
    }

@tinmar33 That might be your problem!

karlguillotte avatar Aug 13 '19 19:08 karlguillotte

@karlguillotte that solved my problem too. Took me a while to figure it out. Should be better documented.

allthetime avatar Aug 13 '19 19:08 allthetime

@karlguillotte well done, that solved it ! 👌

It's wired that it's working on iOS with the old style specs as well

martinfrouin avatar Aug 14 '19 07:08 martinfrouin

I just fixed my problem. Apparently, I have not completely updated my style to the latest style specs. Older specs still work on iOS, but they do not on Android.

{
        iconImage: '{icon}', // PREVIOUS STYLE SPECS
        iconImage: ['get', 'icon'],  // NEW STYLE SPECS
        iconAllowOverlap: true,
        iconSize: 0.35,
    }

@karlguillotte Hey! I know this is a pretty old post but I am also having the same problem. Could you link me to some docs for this?

This here ---> iconImage: ['get', 'icon'], // NEW STYLE SPECS is still a bit vague for me 😅

My code for context

export default function Map() {
  const styles = useStyles()
  const { hasPermissionsEnabled } = useCheckLocationPermissions()
  const point = {
    type: "Point",
    coordinates: [38.9154456, -94.659888],
  }

  return (
    <View style={styles.container}>
      <View style={styles.wrapper}>
        <MapboxGL.MapView
          style={styles.mapBox}
          zoomEnabled
          //styleURL="mapbox://styles/calvin-occ/ckt38dnwn02eu17satqicugel"
        >
          <MapboxGL.UserLocation
            visible={hasPermissionsEnabled}
            showsUserHeadingIndicator={hasPermissionsEnabled}
            renderMode="native"
          />
          <MapboxGL.Camera
            defaultSettings={{
              centerCoordinate: [-94.6579, 38.917256],
              zoomLevel: 15,
            }}
            followUserLocation
          />
          <MapboxGL.ShapeSource
            id="symbolLocationSource"
            onPress={() => console.log("Symbol was pressed")}
            shape={point}
          >
            <MapboxGL.SymbolLayer
              id="symbole"
              minZoomLevel={1}
              style={{
                iconImage: exampleIcon, // <---- What should it look like  here??
                iconSize: 10,
                iconHaloWidth: 10,
                iconHaloColor: "#314ccd",
                iconOpacity: 1,
                iconColor: "#314ccd",
                iconAllowOverlap: true,
              }}
            />
          </MapboxGL.ShapeSource>
        </MapboxGL.MapView>
      </View>
    </View>
  )
}

Alexandria avatar Sep 21 '21 15:09 Alexandria

I just fixed my problem. Apparently, I have not completely updated my style to the latest style specs. Older specs still work on iOS, but they do not on Android.

{
        iconImage: '{icon}', // PREVIOUS STYLE SPECS
        iconImage: ['get', 'icon'],  // NEW STYLE SPECS
        iconAllowOverlap: true,
        iconSize: 0.35,
    }

@karlguillotte Hey! I know this is a pretty old post but I am also having the same problem. Could you link me to some docs for this?

This here ---> iconImage: ['get', 'icon'], // NEW STYLE SPECS is still a bit vague for me 😅

My code for context

export default function Map() {
  const styles = useStyles()
  const { hasPermissionsEnabled } = useCheckLocationPermissions()
  const point = {
    type: "Point",
    coordinates: [38.9154456, -94.659888],
  }

  return (
    <View style={styles.container}>
      <View style={styles.wrapper}>
        <MapboxGL.MapView
          style={styles.mapBox}
          zoomEnabled
          //styleURL="mapbox://styles/calvin-occ/ckt38dnwn02eu17satqicugel"
        >
          <MapboxGL.UserLocation
            visible={hasPermissionsEnabled}
            showsUserHeadingIndicator={hasPermissionsEnabled}
            renderMode="native"
          />
          <MapboxGL.Camera
            defaultSettings={{
              centerCoordinate: [-94.6579, 38.917256],
              zoomLevel: 15,
            }}
            followUserLocation
          />
          <MapboxGL.ShapeSource
            id="symbolLocationSource"
            onPress={() => console.log("Symbol was pressed")}
            shape={point}
          >
            <MapboxGL.SymbolLayer
              id="symbole"
              minZoomLevel={1}
              style={{
                iconImage: exampleIcon, // <---- What should it look like  here??
                iconSize: 10,
                iconHaloWidth: 10,
                iconHaloColor: "#314ccd",
                iconOpacity: 1,
                iconColor: "#314ccd",
                iconAllowOverlap: true,
              }}
            />
          </MapboxGL.ShapeSource>
        </MapboxGL.MapView>
      </View>
    </View>
  )
}

hi, I found the doc here (not sure if adding 'images' to ShapeSource is deprecated or not): https://github.com/nitaliano/react-native-mapbox-gl/blob/master/docs/ShapeSource.md. Image doc (Looks like you need to add image to Image component first before using it in SymbolLayer): https://github.com/react-native-mapbox-gl/maps/blob/master/docs/Images.md Style doc: https://github.com/react-native-mapbox-gl/maps/blob/master/docs/StyleSheet.md Example: https://github.com/react-native-mapbox-gl/maps/blob/master/example/src/examples/SymbolCircleLayer/ShapeSourceIcon.js

TamNhiDuong avatar Dec 13 '21 18:12 TamNhiDuong

@TamNhiDuong Thanks! Both links are the same though. Is there a separate link for the docs?

Alexandria avatar Dec 14 '21 01:12 Alexandria

@TamNhiDuong Thanks! Both links are the same though. Is there a separate link for the docs?

I edited my comment!

TamNhiDuong avatar Dec 14 '21 09:12 TamNhiDuong

Hi, Im using Mapbox GL.Symbol Layer, I can see the icons, but they flicker and disappear after a wile. PointAnnotation, looks ok but for some reason I cant trigger an event on it. Any ideeas? This is on Android11

LucianFratila avatar Jan 14 '22 15:01 LucianFratila