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.

[Improvement] Marker component

See original GitHub issue

Hi there,

Just a question/recommandation/idea of improvement: because I struggle quite a lot to try and put a simple marker on my map, and it looks so complicated for such a basic feature (why would I need a GeoJSON ?), why not create an abstraction of it and create a MapboxGL.Marker component such as the react-native-maps/marker ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
arnaudambrocommented, Jul 15, 2019

So thanks to all your help I could build a proper components to show custom markers, see the code below. My only big issue is: it doesn’t update when a new marker is dynamically added, even with the trick to set a key prop on ShapeSource updating properly. I think I tried a lot of times but I can’t still figure out what is wrong there…

import React from 'react';
import MapboxGL from '@react-native-mapbox-gl/maps';
import { View } from 'react-native';
import styles from './markerStyles';

const getFeatureId = ({ properties: { _id } }) => _id;
const getDataId = data => data._id
const createFeature = data => ({
  // https://github.com/react-native-mapbox-gl/maps/blob/master/docs/ShapeSource.md -> shapeSource prop
  // https://geojson.org
  // this has a geoJSON shape
  type: 'Feature',
  properties: {
    _id: data._id,
    whatever: 'you want'
  },
  geometry: {
    type: 'Point',
    coordinates: data.coordinates, // [lat, long]
  }
})

class MyMarkers extends React.Component {


  onPress = (e) => {
    const feature = e.nativeEvent.payload;
    const dataId = getFeatureId(feature)
    console.log({ feature, dataId })
    // TODO
  }

  render() {

    const { datas } = this.props;

    const features = datas.map(createFeature)

    return (
      <MapboxGL.ShapeSource
        id='markersShape'
        shape={{ type: 'FeatureCollection', features }}
        onPress={this.onPress}
      >
        {datas.map(data => (
          <MapboxGL.SymbolLayer
            id={getDataId(data)}
            key={getDataId(data)}
            sourceID='markersShape'
            filter={['==', '_id', getDataId(data)]}
            style={{
              iconSize: 1,
              iconAllowOverlap: true
            }}
          >
            <View
              style={styles.marker}
              pointerEvents='none' // this is important for the onPress prop of ShapeSource to work
            >
              {/* ... place what you want as a marker here, even SVG from react-native-svg for instance */}
            </View>
          </MapboxGL.SymbolLayer>
        ))}
      </MapboxGL.ShapeSource>
    )
  }
}

export default MyMarkers;
2reactions
arnaudambrocommented, Jul 12, 2019

@ethaqnix I still have an issues with your solution:

  • it seems that the Mapview doesn’t update when a ShapeSource is added: I was able to show the newly added Marker by updating the Mapview key, do you know why ?
  • depending on the zoom, some markers disappear automatically because the are hidden by other markers : how if I never want any marker to be hidden ?

If you have some clues there it would be great !

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Improvement] Marker component · Issue #227 · rnmapbox/maps
Hi there, Just a question/recommandation/idea of improvement: because I struggle quite a lot to try and put a simple marker on my map, ......
Read more >
Combination of multiple functional markers to improve ... - NCBI
In this article, we propose a one-dimension scalar feature motivated by square loss distance, as an alternative of the original functional curve ...
Read more >
Engraving | Process Improvement | Laser Marking Central
Laser markers support small and large products requirements, can deliver damage-free marks, and don't require part updates whenever a new product is introduced....
Read more >
An enhanced marker pattern that achieves improved accuracy ...
The main goal of this paper is to design an enhanced cylindrical marker that achieves improved accuracy for surgical tool tracking.
Read more >
A Pathologist's Toolbox for Predictive Marker Quality ...
Describe the elements of an IHC laboratory quality plan; Understand the value of a standard approach to IHC assay improvement; Review components of...
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