question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ShapeSource and SymbolLayer as PointAnnotation.

See original GitHub issue

Problem: As the docs say PointAnnotation is deprecated and shouldn’t be used so I’m trying to switch to ShapeLayer and SymbolLayer. What I’m trying to do is something like this: facebook_blog_image_2 And the number should change dynamically, according to props. Any tips? I managed to make the chat icon appear but I have no idea how to add the number. What I have so far:

const feature = {
type: 'Feature',
id: marker.id,
      geometry: {
        type: 'Point',
        coordinates: [marker.lat, marker.lng],
      },
};
return (
<MapboxGL.MapView style={sheet.matchParent}>
     <MapboxGL.Camera
          zoomLevel={17}
          centerCoordinate={[loc.lat, loc.lng]}
        />
     <MapboxGL.ShapeSource
         id="exampleShapeSource"
         shape={feature}
       >
        <MapboxGL.SymbolLayer id={markerOne + 1} style={{ iconImage: image, iconSize: 1 }} />
    </MapboxGL.ShapeSource>
</MapboxGL.MapView>);

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:24 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
horvacommented, Oct 1, 2019

Here is full example we can include to repository.

import React, { Component } from "react";
import { StyleSheet, View, Text, Image } from "react-native";
import MapboxGL from "@react-native-mapbox-gl/maps";
import sheet from '../examples/styles/sheet';
import exampleIcon from '../examples/assets/example.png';

const point = {
  id: "1",
  lat: 40.723279,
  lng: -73.970895
}

const featureCollection = {
  "type": "FeatureCollection",
  "features": [
    {
      type: "Feature",
      id: point.id,
      properties: {
        id: point.id
      },
      geometry: {
        type: "Point",
        coordinates: [point.lng, point.lat],
      },
    }
  ]
}

export default class App extends Component {

  state = {
    count: 0
  }

  onPress = async () => {
    this.setState((prevState) => ({
      count: prevState.count + 1
    }));
  }

  render() {
    return (
      <MapboxGL.MapView
        style={sheet.matchParent}
      >
        <MapboxGL.Camera
          zoomLevel={10}
          centerCoordinate={[point.lng, point.lat]}
        />
        <MapboxGL.ShapeSource
          id="symbolLocationSource"
          hitbox={{ width: 30, height: 30 }}
          onPress={this.onPress}
          shape={featureCollection}
        >
          <MapboxGL.CircleLayer
            id="pointCircles"
            style={{
              circleStrokeColor: "#0000FF",
              circleStrokeWidth: 2,
              circleRadius: 30,
              circleColor: "#FFFFFF"
            }}
          />
          <MapboxGL.SymbolLayer
            id="teaCup"
            aboveLayerID="pointCircles"
            style={{
              iconImage: exampleIcon,
              iconSize: 1
            }}
          />
          <MapboxGL.CircleLayer
            id="notificationCircle"
            style={{
              circleColor: "#F00",
              circleRadius: 14,
              circleTranslate: [22, -22]
            }}
          />
          <MapboxGL.SymbolLayer
            id="notificationCount"
            style={{
              iconOptional: true,
              textIgnorePlacement: true,
              textField: this.state.count.toString(),
              textSize: 15,
              textMaxWidth: 50,
              textColor: '#FFF',
              textAnchor: 'center',
              textTranslate: [22, -22],
              textAllowOverlap: true
            }}
          />
        </MapboxGL.ShapeSource>
      </MapboxGL.MapView>
    );
  }
}

Usage looks like this - count is updated on icon press

SymbolLayerUpdates

1reaction
dancherbcommented, Sep 19, 2019

@arnaudambro @tomasamado97

Are there any docs or examples for adding custom component children (Views) to SymbolLayers? This is a revelation for me but I can’t get it working (maybe because of the same Android issue…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ShapeSource and SymbolLayer as PointAnnotation. #266
Problem: As the docs say PointAnnotation is deprecated and shouldn't be used so I'm trying to switch to ShapeLayer and SymbolLayer.
Read more >
rnmapbox/Lobby - Gitter
@mertozylmz I found that Annotation is a wrapper for a symbol layer tha accepts coordinates, ... But I think ShapeSource better than PointAnnotation....
Read more >
Can not able to customise Pin(Marker) and it's info window in ...
ShapeSource Result:- Nothing display. MapboxGL.PointAnnotation with Image view Result:- Display Pin but only work local image. MapboxGL.
Read more >
react native mapbox dynamically added PointAnnotations are ...
[Solved]-react native mapbox dynamically added PointAnnotations are misplaced-React Native ... ShapeSource shape={makeMapBoxGeoJson(props.datum, props.
Read more >
MapxusSdk.MapxusPointAnnotationView
Prop Type Default Required buildingId string none false floor string none false id string none true
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found