Skip to content

Commit

Permalink
feat: 🎸 store viewport in app state
Browse files Browse the repository at this point in the history
  • Loading branch information
device25 committed Jul 4, 2019
1 parent 1d2faaf commit 9770af4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React, { useState, createRef } from 'react';
import MapGL from '@urbica/react-map-gl';
import { validate } from '@mapbox/mapbox-gl-style-spec';
import initStyle from '../config/initStyle';
import { initStyle, initViewport } from '../config';
import 'mapbox-gl/dist/mapbox-gl.css';

const initStyleString = JSON.stringify(initStyle, null, 1);

function App() {
const [style, setStyle] = useState(initStyleString);
const [viewport, setViewport] = useState(initViewport);
const editorRef = createRef();

const onViewportChange = (newViewport) => {
setViewport(newViewport);
};

const setStyleHandler = () => {
let { value } = editorRef.current;
value = value.replace(/'/g, '"');
Expand Down Expand Up @@ -37,10 +42,8 @@ function App() {
}}
mapStyle={JSON.parse(style)}
accessToken='pk.eyJ1IjoiZGV2aWNlMjUiLCJhIjoiY2lzaGN3d2tiMDAxOTJ6bGYydDZrcHptdiJ9.UK55aUzBquqYns1AdnuTQg'
latitude={0}
longitude={0}
zoom={0}
onViewportChange={() => ({})}
{...viewport}
onViewportChange={onViewportChange}
/>
<textarea
ref={editorRef}
Expand Down
2 changes: 2 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as initStyle }from './initStyle';
export { default as initViewport }from './initViewport';
5 changes: 5 additions & 0 deletions src/config/initViewport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
latitude: 0,
longitude: 0,
zoom: 0
};

0 comments on commit 9770af4

Please sign in to comment.