Last active
April 2, 2019 14:48
-
-
Save stepankuzmin/31b562396ee3020a2a2f7f89cf8f3a6f to your computer and use it in GitHub Desktop.
Urbica React MapGL Comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map.on('moveend', (event) => { | |
| if (event.originalEvent) { | |
| console.log('A human moved the map'); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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