Hello community:
I’m trying to add data to a Mapbox map. I’m following along with the “Integrate Mapbox” tutorial but instead of adding the Isochrone API, I’m trying to add either markers or circles.
Tutorial here: Integrate Mapbox into your Web App using only Python
My latitude/longitude data is stored in a datatable. I’m converting these X/Y pairs to a GeoDataFrame, then to a JSON string. A small portion of the json string is shown below:
{“type”: “FeatureCollection”, “features”: [{“id”: “0”, “type”: “Feature”, “properties”: {“lat”: “32.1907841691”, “long”: “-95.103430522”, “name”: “Mill A”}, “geometry”: {“type”: “Point”, “coordinates”: [-95.103430522, 32.1907841691]}}, {“id”: “1”, “type”: “Feature”, “properties”: {“lat”: “31.8786962342”, “long”: “-95.2117307865”, “name”: “Mill B.”}, “geometry”: {“type”: “Point”, “coordinates”: [-95.2117307865, 31.8786962342]}}, …
The map is displayed in a spacer control and stored in self.mapbox variable. The map is loading but I cannot get the data to display on the map. I can manually place markers on the map by looping through the longitude, latitude values from the data, but the layer will not load.
Here is a view of the code to add the source and layer to the map:
mills_json = DataAccessLayer.get_mills_json()
# add a source for the mills geojson
self.mapbox.addSource('mills', {'type': 'geojson'})
self.mapbox.addLayer(
{'id': 'mills',
'type': 'circle',
'source': 'mills',
})
self.mapbox.getSource('mills').setData(mills_json)
Any help would be greatly appreciated.