mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-30 20:40:33 +01:00
Merge remote-tracking branch 'upstream/master' into fix/issue-110-update-mapbox-style-spec
This commit is contained in:
commit
d94ee2ba98
6 changed files with 84 additions and 7 deletions
|
@ -46,7 +46,20 @@ class OpenModal extends React.Component {
|
||||||
onStyleOpen: React.PropTypes.func.isRequired,
|
onStyleOpen: React.PropTypes.func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
clearError() {
|
||||||
|
this.setState({
|
||||||
|
error: null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onStyleSelect(styleUrl) {
|
onStyleSelect(styleUrl) {
|
||||||
|
this.clearError();
|
||||||
|
|
||||||
request({
|
request({
|
||||||
url: styleUrl,
|
url: styleUrl,
|
||||||
withCredentials: false,
|
withCredentials: false,
|
||||||
|
@ -64,15 +77,32 @@ class OpenModal extends React.Component {
|
||||||
onUpload(_, files) {
|
onUpload(_, files) {
|
||||||
const [e, file] = files[0];
|
const [e, file] = files[0];
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
this.clearError();
|
||||||
|
|
||||||
reader.readAsText(file, "UTF-8");
|
reader.readAsText(file, "UTF-8");
|
||||||
reader.onload = e => {
|
reader.onload = e => {
|
||||||
let mapStyle = JSON.parse(e.target.result)
|
let mapStyle;
|
||||||
|
try {
|
||||||
|
mapStyle = JSON.parse(e.target.result)
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
this.setState({
|
||||||
|
error: err.toString()
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
mapStyle = style.ensureStyleValidity(mapStyle)
|
mapStyle = style.ensureStyleValidity(mapStyle)
|
||||||
this.props.onStyleOpen(mapStyle);
|
this.props.onStyleOpen(mapStyle);
|
||||||
}
|
}
|
||||||
reader.onerror = e => console.log(e.target);
|
reader.onerror = e => console.log(e.target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onOpenToggle() {
|
||||||
|
this.clearError();
|
||||||
|
this.props.onOpenToggle();
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const styleOptions = publicStyles.map(style => {
|
const styleOptions = publicStyles.map(style => {
|
||||||
return <PublicStyle
|
return <PublicStyle
|
||||||
|
@ -84,11 +114,22 @@ class OpenModal extends React.Component {
|
||||||
/>
|
/>
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let errorElement;
|
||||||
|
if(this.state.error) {
|
||||||
|
errorElement = (
|
||||||
|
<div className="maputnik-modal-error">
|
||||||
|
{this.state.error}
|
||||||
|
<a href="#" onClick={() => this.clearError()} className="maputnik-modal-error-close">×</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return <Modal
|
return <Modal
|
||||||
isOpen={this.props.isOpen}
|
isOpen={this.props.isOpen}
|
||||||
onOpenToggle={this.props.onOpenToggle}
|
onOpenToggle={() => this.onOpenToggle()}
|
||||||
title={'Open Style'}
|
title={'Open Style'}
|
||||||
>
|
>
|
||||||
|
{errorElement}
|
||||||
<section className="maputnik-modal-section">
|
<section className="maputnik-modal-section">
|
||||||
<h2>Upload Style</h2>
|
<h2>Upload Style</h2>
|
||||||
<p>Upload a JSON style from your computer.</p>
|
<p>Upload a JSON style from your computer.</p>
|
||||||
|
@ -96,7 +137,7 @@ class OpenModal extends React.Component {
|
||||||
<Button className="maputnik-upload-button"><FileUploadIcon /> Upload</Button>
|
<Button className="maputnik-upload-button"><FileUploadIcon /> Upload</Button>
|
||||||
</FileReaderInput>
|
</FileReaderInput>
|
||||||
</section>
|
</section>
|
||||||
<section className="maputnik-modal-section">
|
<section className="maputnik-modal-section maputnik-modal-section--shrink">
|
||||||
<h2>Gallery Styles</h2>
|
<h2>Gallery Styles</h2>
|
||||||
<p>
|
<p>
|
||||||
Open one of the publicly available styles to start from.
|
Open one of the publicly available styles to start from.
|
||||||
|
|
|
@ -70,7 +70,7 @@ function replaceAccessToken(mapStyle) {
|
||||||
}
|
}
|
||||||
const changedStyle = {
|
const changedStyle = {
|
||||||
...mapStyle,
|
...mapStyle,
|
||||||
glyphs: mapStyle.glyphs.replace('{key}', accessToken),
|
glyphs: mapStyle.glyphs ? mapStyle.glyphs.replace('{key}', accessToken) : mapStyle.glyphs,
|
||||||
sources: changedSources
|
sources: changedSources
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
top: 20px;
|
top: 20px;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 120px;
|
width: 120px;
|
||||||
z-index: 3;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
left: 0;
|
left: 0;
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
width: 200px;
|
width: 200px;
|
||||||
overflow: hidden;
|
|
||||||
background-color: $color-black;
|
background-color: $color-black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,3 +12,10 @@
|
||||||
|
|
||||||
@include vendor-prefix(flex-direction, row);
|
@include vendor-prefix(flex-direction, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@mixin flex-column {
|
||||||
|
display: flex;
|
||||||
|
display: -ms-flexbox;
|
||||||
|
|
||||||
|
@include vendor-prefix(flex-direction, column);
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,17 @@
|
||||||
.maputnik-modal-section {
|
.maputnik-modal-section {
|
||||||
padding-top: $margin-3;
|
padding-top: $margin-3;
|
||||||
padding-bottom: $margin-3;
|
padding-bottom: $margin-3;
|
||||||
|
|
||||||
|
/* Bug fix: <http://stackoverflow.com/questions/28636832/firefox-overflow-y-not-working-with-nested-flexbox> */
|
||||||
|
min-height: 0;
|
||||||
|
|
||||||
|
@include flex-column;
|
||||||
|
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.maputnik-modal-section--shrink {
|
||||||
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.maputnik-modal-header {
|
.maputnik-modal-header {
|
||||||
|
@ -30,6 +41,9 @@
|
||||||
|
|
||||||
.maputnik-modal-content {
|
.maputnik-modal-content {
|
||||||
padding: $margin-3;
|
padding: $margin-3;
|
||||||
|
max-height: 90vh;
|
||||||
|
|
||||||
|
@include flex-column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.maputnik-modal-header-space {
|
.maputnik-modal-header-space {
|
||||||
|
@ -66,8 +80,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.maputnik-style-gallery-container {
|
.maputnik-style-gallery-container {
|
||||||
max-height: 400px;
|
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.maputnik-public-style {
|
.maputnik-public-style {
|
||||||
|
@ -199,3 +213,19 @@
|
||||||
color: $color-lowgray;
|
color: $color-lowgray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.maputnik-modal-error {
|
||||||
|
border: solid 2px #ef5350;
|
||||||
|
color: #ef5350;
|
||||||
|
padding: 8px;
|
||||||
|
padding-right: 32px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.maputnik-modal-error-close {
|
||||||
|
position: absolute;
|
||||||
|
right: 8px;
|
||||||
|
top: 8px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #ef5350;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue