Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
3,008 additions
and
965 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,5 @@ | |
[strict] | ||
|
||
[version] | ||
0.81.0 | ||
0.95.1 | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,7 @@ coverage/ | |
.nyc_output/ | ||
.npmrc | ||
|
||
npm-debug.log | ||
yarn-error.log | ||
*.log | ||
|
||
# editor files | ||
.project | ||
|
This file contains 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
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// @flow | ||
/* eslint-env browser */ | ||
|
||
import React from 'react'; | ||
import Modal, { ModalProvider } from 'styled-react-modal'; | ||
import styled from 'styled-components'; | ||
|
||
export const Button = styled.button` | ||
display: inline-block; | ||
color: #fff; | ||
background-color: rgb(90, 98, 94); | ||
font-size: 1em; | ||
margin: 0.25em; | ||
padding: 0.375em 0.75em; | ||
border: 1px solid transparent; | ||
border-radius: 0.25em; | ||
display: block; | ||
`; | ||
|
||
const StyledModal = Modal.styled` | ||
position: relative; | ||
display: block; | ||
width: 50rem; | ||
height: auto; | ||
max-width: 500px; | ||
margin: 1.75rem auto; | ||
box-sizing: border-box; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; | ||
font-size: 1rem; | ||
font-weight: 400; | ||
color: rgb(21, 25, 29); | ||
line-height: 1.5; | ||
text-align: left; | ||
`; | ||
|
||
const Content = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
pointer-events: auto; | ||
background-color: #fff; | ||
background-clip: padding-box; | ||
border: 1px solid rgba(0, 0, 0, 0.2); | ||
border-radius: 0.3rem; | ||
outline: 0; | ||
`; | ||
|
||
const HeaderRow = styled.div` | ||
display: flex; | ||
align-items: flex-start; | ||
justify-content: space-between; | ||
padding: 0.75rem 0.75rem; | ||
border-bottom: 1px solid rgb(222, 226, 230); | ||
`; | ||
|
||
const Header = styled.h5` | ||
font-size: 1.25rem; | ||
font-weight: 500; | ||
margin: 0; | ||
`; | ||
|
||
export type ModalProps = { | ||
title: any, | ||
content: any, | ||
onClose: () => mixed | ||
}; | ||
|
||
export function EditorModal(props: ModalProps) { | ||
const [isOpen, setIsOpen] = React.useState(true); | ||
|
||
function toggleModal(e) { | ||
if (isOpen) { | ||
props.onClose(); | ||
} | ||
setIsOpen(!isOpen); | ||
} | ||
|
||
return ( | ||
<> | ||
<ModalProvider> | ||
<StyledModal isOpen={isOpen} onBackgroundClick={toggleModal} onEscapeKeydown={toggleModal}> | ||
<Content> | ||
<HeaderRow> | ||
<Header>{props.title}</Header> | ||
</HeaderRow> | ||
{props.content} | ||
</Content> | ||
</StyledModal> | ||
</ModalProvider> | ||
</> | ||
); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// @flow | ||
/* eslint-env browser */ | ||
|
||
import React from 'react'; | ||
import copy from 'clipboard-copy'; | ||
import downloadjs from 'downloadjs'; | ||
import styled from 'styled-components'; | ||
import { toGeoJson, toKml, toWkt } from './lib/exporter.js'; | ||
import { Button } from './editor-modal.js'; | ||
|
||
const FormatSelect = styled.div` | ||
display: flex; | ||
padding: 0.75rem 0.75rem 0rem 0.75rem; | ||
`; | ||
|
||
const ExportArea = styled.div` | ||
box-sizing: border-box; | ||
display: block; | ||
width: auto; | ||
height: auto; | ||
min-height: 300px; | ||
padding: 0rem 1rem; | ||
`; | ||
|
||
const ExportData = styled.textarea` | ||
padding: 0px; | ||
width: 100%; | ||
resize: vertical; | ||
min-height: 300px; | ||
max-height: 500px; | ||
border: 1px solid rgb(206, 212, 218); | ||
border-radius: 0.3rem; | ||
font-family: -apple-system, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', | ||
sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; | ||
font-size: 1rem; | ||
font-weight: 400; | ||
`; | ||
|
||
const FooterRow = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
padding: 0.75rem 0.75rem; | ||
`; | ||
|
||
export type ExportComponentProps = { | ||
features: any, | ||
onClose: () => mixed | ||
}; | ||
|
||
export function ExportComponent(props: ExportComponentProps) { | ||
const geojson = props.features; | ||
const [exportParams, setExportParams] = React.useState(toGeoJson(geojson)); | ||
const [format, setFormat] = React.useState('geoJson'); | ||
|
||
const tooMuch = exportParams.data.length > 500000; | ||
|
||
function copyData() { | ||
copy(exportParams.data).then(() => props.onClose()); | ||
// TODO Design and add in a notifications banner for errors in the modal. | ||
// .catch(err => {alert(`Error copying to clipboard: `, err)}) | ||
} | ||
|
||
function downloadData() { | ||
downloadjs(new Blob([exportParams.data]), exportParams.filename, exportParams.mimetype); | ||
props.onClose(); | ||
} | ||
|
||
return ( | ||
<> | ||
<FormatSelect> | ||
<strong style={{ padding: '0.5rem 0.25rem' }}>Format:</strong> | ||
<Button | ||
style={{ | ||
backgroundColor: format === 'geoJson' ? 'rgb(0, 105, 217)' : 'rgb(90, 98, 94)' | ||
}} | ||
onClick={() => { | ||
setExportParams(toGeoJson(geojson)); | ||
setFormat('geoJson'); | ||
}} | ||
> | ||
GeoJson | ||
</Button> | ||
<Button | ||
style={{ | ||
backgroundColor: format === 'kml' ? 'rgb(0, 105, 217)' : 'rgb(90, 98, 94)' | ||
}} | ||
onClick={() => { | ||
setExportParams(toKml(geojson)); | ||
setFormat('kml'); | ||
}} | ||
> | ||
KML | ||
</Button> | ||
<Button | ||
style={{ | ||
backgroundColor: format === 'wkt' ? 'rgb(0, 105, 217)' : 'rgb(90, 98, 94)' | ||
}} | ||
onClick={() => { | ||
setExportParams(toWkt(geojson)); | ||
setFormat('wkt'); | ||
}} | ||
> | ||
WKT | ||
</Button> | ||
</FormatSelect> | ||
<ExportArea> | ||
<ExportData | ||
readOnly={true} | ||
style={tooMuch ? { fontStyle: 'italic', padding: '0.75rem 0rem' } : {}} | ||
value={ | ||
tooMuch | ||
? 'Too much data to display. Download or Copy to clipboard instead.' | ||
: exportParams.data | ||
} | ||
/> | ||
</ExportArea> | ||
<FooterRow> | ||
<Button style={{ backgroundColor: 'rgb(0, 105, 217)' }} onClick={downloadData}> | ||
Download | ||
</Button> | ||
<Button style={{ backgroundColor: 'rgb(0, 105, 217)' }} onClick={copyData}> | ||
Copy | ||
</Button> | ||
<Button onClick={props.onClose}>Cancel</Button> | ||
</FooterRow> | ||
</> | ||
); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @flow | ||
/* eslint-env browser */ | ||
|
||
import React from 'react'; | ||
import type { AnyGeoJson } from '@nebula.gl/edit-modes'; | ||
import { EditorModal } from './editor-modal.js'; | ||
import { ExportComponent } from './export-component.js'; | ||
|
||
export type ExportModalProps = { | ||
features: AnyGeoJson, | ||
onClose: () => mixed | ||
}; | ||
|
||
export function ExportModal(props: ExportModalProps) { | ||
return ( | ||
<EditorModal | ||
onClose={props.onClose} | ||
title={'Export'} | ||
content={<ExportComponent features={props.features} onClose={props.onClose} />} | ||
/> | ||
); | ||
} |
Oops, something went wrong.