Hi Retool,
Hoping y'all could help steer us in the right direction.
Our goal is to manually draw polygons on a map and send their JSON representations via API.
To this end, we would like to create a custom component with a Mapbox object (with polygon-drawing capabilities) and extract the generated JSON.
We can successfully implement a Mapbox component that draws polygons (see: Draw a polygon and calculate its area | Mapbox GL JS | Mapbox). However, it's created with plain JS. Our understanding is that one needs a custom component that uses react to enable data sharing across the Retool dashboard.
When creating a custom component with React, we are having trouble creating the Mapbox component. We suspect an issue with imports or with the way the component is declared. The generated error messages don't provide sufficient information on possible error sources. Would you, by chance, have suggestions on how to proceed?
Thank you.
<style>
body {
margin: 0;
}
</style>
<script src="https://cdn.tryretool.com/js/react.production.min.js" crossorigin></script>
<script src="https://cdn.tryretool.com/js/react-dom.production.min.js" crossorigin></script>
<script src="https://unpkg.com/@material-ui/core@3.9.3/umd/material-ui.production.min.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js"></script>
<script type="text/babel">
const mapboxgl = window['mapbox-gl'];
const MyCustomComponent = ({ triggerQuery, model, modelUpdate }) => (
<p>Hello, Retool!</p>
);
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/dark-v10', //hosted style id
center: [-99.874, 19.76], // starting position
zoom: 8 // starting zoom
});
const ConnectedComponent = Retool.connectReactComponent(MyCustomComponent);
ReactDOM.render(<ConnectedComponent />, document.getElementById('react'));
</script>
<div id="react"></div>