I am desperately trying to add some markers to a mapbox map by using the mapbox-gl-js with typescript and I follwed several tutorials from the mapbox site, but it doesn't work for me.
mapboxgl.accessToken = 'mykey';
this.map = new mapboxgl.Map({
container: 'map',
style: this.style,
zoom: 13,
center: [12, 12]
});
this.map.on('load', (event) => {
this.map.addSource('testSrc', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [ 12, 12]
},
properties: {
title: 'Mapbox',
description: 'Washington, D.C.'
}
},
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.414, 37.776]
},
properties: {
title: 'Mapbox',
description: 'San Francisco, California'
}
}]
}
});
this.map.addLayer({
id: 'testSrc',
source: 'testSrc',
type: 'circle',
layout: {
'text-field': '{message}',
'text-size': 24,
'text-transform': 'uppercase',
'icon-image': 'rocket-15',
'text-offset': [0, 1.5]
},
paint: {
'text-color': '#f16624',
'text-halo-color': '#fff',
'text-halo-width': 2
}
});
this.map.addControl(new mapboxgl.NavigationControl());
});
I created a source with some static data and I set it to a layer of the mapboxgl map-object. The map is displaying without any problems, but I can't add some markers with the required geojson format.
My goal is to dynamically add markers, but here I stuck in adding some static ones.
Do you have any idea what's the problem in here?
Regards Marko