diff --git a/src/components/inputs/StringInput.jsx b/src/components/inputs/StringInput.jsx
index e160d69..87bdd31 100644
--- a/src/components/inputs/StringInput.jsx
+++ b/src/components/inputs/StringInput.jsx
@@ -8,10 +8,15 @@ class StringInput extends React.Component {
style: PropTypes.object,
default: PropTypes.string,
onChange: PropTypes.func,
+ onInput: PropTypes.func,
multi: PropTypes.bool,
required: PropTypes.bool,
}
+ static defaultProps = {
+ onInput: () => {},
+ }
+
constructor(props) {
super(props)
this.state = {
@@ -57,7 +62,9 @@ class StringInput extends React.Component {
this.setState({
editing: true,
value: e.target.value
- })
+ }, () => {
+ this.props.onInput(this.state.value);
+ });
},
onBlur: () => {
if(this.state.value!==this.props.value) {
diff --git a/src/components/inputs/UrlInput.jsx b/src/components/inputs/UrlInput.jsx
new file mode 100644
index 0000000..335d3ff
--- /dev/null
+++ b/src/components/inputs/UrlInput.jsx
@@ -0,0 +1,77 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import StringInput from './StringInput'
+import SmallError from '../util/SmallError'
+
+
+function validate (url) {
+ let error;
+ const getProtocol = (url) => {
+ try {
+ const urlObj = new URL(url);
+ return urlObj.protocol;
+ }
+ catch (err) {
+ return undefined;
+ }
+ };
+ const protocol = getProtocol(url);
+ if (
+ protocol &&
+ protocol === "http:" &&
+ window.location.protocol === "https:"
+ ) {
+ error = (
+
+ CORS policy won't allow fetching resources served over http from https, use a https://
domain
+
+ );
+ }
+
+ return error;
+}
+
+class UrlInput extends React.Component {
+ static propTypes = {
+ "data-wd-key": PropTypes.string,
+ value: PropTypes.string,
+ style: PropTypes.object,
+ default: PropTypes.string,
+ onChange: PropTypes.func,
+ onInput: PropTypes.func,
+ multi: PropTypes.bool,
+ required: PropTypes.bool,
+ }
+
+ static defaultProps = {
+ onInput: () => {},
+ }
+
+ constructor (props) {
+ super(props);
+ this.state = {
+ error: validate(props.value)
+ };
+ }
+
+ onInput = (url) => {
+ this.setState({
+ error: validate(url)
+ });
+ this.props.onInput(url);
+ }
+
+ render () {
+ return (
+
+
+ {this.state.error}
+
+ );
+ }
+}
+
+export default UrlInput
diff --git a/src/components/map/MapboxGlMap.jsx b/src/components/map/MapboxGlMap.jsx
index 87ee61b..7047d6a 100644
--- a/src/components/map/MapboxGlMap.jsx
+++ b/src/components/map/MapboxGlMap.jsx
@@ -181,6 +181,10 @@ export default class MapboxGlMap extends React.Component {
})
})
+ map.on("error", e => {
+ console.log("ERROR", e);
+ })
+
map.on("zoom", e => {
this.setState({
zoom: map.getZoom()
diff --git a/src/components/modals/OpenModal.jsx b/src/components/modals/OpenModal.jsx
index d2c6477..67f289d 100644
--- a/src/components/modals/OpenModal.jsx
+++ b/src/components/modals/OpenModal.jsx
@@ -4,6 +4,7 @@ import LoadingModal from './LoadingModal'
import Modal from './Modal'
import Button from '../Button'
import FileReaderInput from 'react-file-reader-input'
+import UrlInput from '../inputs/UrlInput'
import {MdFileUpload} from 'react-icons/md'
import {MdAddCircleOutline} from 'react-icons/md'
@@ -122,9 +123,8 @@ class OpenModal extends React.Component {
})
}
- onOpenUrl = () => {
- const url = this.styleUrlElement.value;
- this.onStyleSelect(url);
+ onOpenUrl = (url) => {
+ this.onStyleSelect(this.state.styleUrl);
}
onUpload = (_, files) => {
@@ -160,9 +160,9 @@ class OpenModal extends React.Component {
this.props.onOpenToggle();
}
- onChangeUrl = () => {
+ onChangeUrl = (url) => {
this.setState({
- styleUrl: this.styleUrlElement.value
+ styleUrl: url,
});
}
@@ -209,14 +209,13 @@ class OpenModal extends React.Component {
Load from a URL. Note that the URL must have CORS enabled.
- this.styleUrlElement = input}
className="maputnik-input"
- placeholder="Enter URL..."
+ default="Enter URL..."
value={this.state.styleUrl}
- onChange={this.onChangeUrl}
+ onInput={this.onChangeUrl}
/>