Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

dynamically adding marker react native mapbox

You can add markers dynamically by using this code:

Create marker component:
const Marker = ({ coordinate, image, id }) => {
    return (
      <MapboxGL.MarkerView coordinate={coordinate} id={id}>
      // Add any image or icon or view for marker
		<Image
            source={{ uri: image }}
            style={{width: '100%', height: '100%'}}
            resizeMode="contain"
          />
      </MapboxGL.MarkerView>
    );
 };

Consume it inside MapBoxGL:
<MapboxGL.MapView
      style={{
        // it will help you keep markers inside mapview
        overflow: 'hidden'
      }}>
{markers &&
      markers?.length > 0 &&
         markers.map((marker, index) => (
      	    <Marker
              coordinate={[marker.longitude, marker.latitude]}
              // id must be a string
              id={`index + 1`}
              image={getIconUrl(index)}
            />
         ))
}
</MapboxGL.MapView>
Comment

PREVIOUS NEXT
Code Example
Javascript :: EVERY METHOD 
Javascript :: clear arrays in jquery 
Javascript :: generate component with module angular 8 
Javascript :: array methods javascript 
Javascript :: javascript string array sort alphabetically 
Javascript :: electron file association 
Javascript :: Installation failed, reverting ./composer.json and ./composer.lock to their original content. 
Javascript :: javascript game loop 
Javascript :: jquery datatable iterate all rows 
Javascript :: range javascript 
Javascript :: print hello world in javascript 
Javascript :: javascript remove all event listeners 
Javascript :: sequelize.org findById 
Javascript :: js get data from form 
Javascript :: get element by 
Javascript :: momeny day in range 
Javascript :: javascript round to 2 digits 
Javascript :: string array to int array javascript 
Javascript :: regex for month 
Javascript :: update formgroup value angular 
Javascript :: run function every second javascript 
Javascript :: Iterate with JavaScript For Loops 
Javascript :: sort from the key value js 
Javascript :: UpperCase every first letter in each word in str 
Javascript :: comment in react 
Javascript :: object values javascript 
Javascript :: float to currency 
Javascript :: how to get time and date from iso string javascript 
Javascript :: neo4j create relationship between existing nodes 
Javascript :: onclick open link js 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =