Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Last active April 2, 2019 14:48
Show Gist options
  • Save stepankuzmin/31b562396ee3020a2a2f7f89cf8f3a6f to your computer and use it in GitHub Desktop.
Save stepankuzmin/31b562396ee3020a2a2f7f89cf8f3a6f to your computer and use it in GitHub Desktop.
Urbica React MapGL Comparison
import ReactMapboxGl, { Source, Layer } from 'react-mapbox-gl';
const Map = ReactMapboxGl({
accessToken: 'pk...'
});
const SOURCE_OPTIONS = {
type: 'vector',
tiles: ['https://...']
};
<Map
style='mapbox://styles/mapbox/streets-v11'
center={[-74.50, 40]}
zoom={9}
>
<Source id='sourceId' tileJsonSource={SOURCE_OPTIONS} />
<Layer type='raster' id='layerId' sourceId='sourceId' />
</Map>
import mapboxgl from 'mapbox-gl';
mapboxgl.accessToken = 'pk...';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-74.50, 40],
zoom: 9
});
map.on('load', () => {
map.addSource('sourceId', { type: 'vector', tiles: ['https://...'] });
map.addLayer({
id: 'layerId',
type: 'line',
source: 'sourceId',
paint: {}
});
map.addControl(new mapboxgl.NavigationControl());
});
map.on('moveend', (event) => {
 if (event.originalEvent) {
  console.log('A human moved the map');
 }
});
import MapGL, { NavigationControl } from 'react-map-gl';
const mapStyle = {
version: 8,
sources: {
sourceId: { type: 'vector', tiles: ['https://...'] }
},
layers: [
{ id: 'layerId', type: 'line', source: 'sourceId', paint: {} }
]
};
const viewport = { latitude: 40, longitude: -74.50, zoom: 9};
<MapGL
mapStyle={mapStyle}
mapboxApiAccessToken='pk...'
onViewportChange={updateViewport}
{...viewport}
>
<div style={{position: 'absolute', right: 0}}>
<NavigationControl onViewportChange={updateViewport} />
</div>
</MapGL>
import MapGL, { Source, Layer, NavigationControl } from '@urbica/react-map-gl';
<MapGL
mapStyle='mapbox://styles/mapbox/streets-v11'
accessToken='pk...'
latitude={40}
longitude={-74.50}
zoom={9}
>
<Source id='sourceId' type='vector' tiles=['https://...'] />
<Layer id='layerId' type='line' source='sourceId' paint={{}} />
<NavigationControl />
</MapGL>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment