import React from 'react' import PropTypes from 'prop-types' import Slugify from 'slugify' import {saveAs} from 'file-saver' import {version} from 'maplibre-gl' import {format} from '@maplibre/maplibre-gl-style-spec' import FieldString from './FieldString' import InputButton from './InputButton' import Modal from './Modal' import {MdFileDownload} from 'react-icons/md' import style from '../libs/style' import fieldSpecAdditional from '../libs/field-spec-additional' const MAPLIBRE_GL_VERSION = version; export default class ModalExport extends React.Component { static propTypes = { mapStyle: PropTypes.object.isRequired, onStyleChanged: PropTypes.func.isRequired, isOpen: PropTypes.bool.isRequired, onOpenToggle: PropTypes.func.isRequired, } constructor(props) { super(props); } tokenizedStyle () { return format( style.stripAccessTokens( style.replaceAccessTokens(this.props.mapStyle) ) ); } exportName () { if(this.props.mapStyle.name) { return Slugify(this.props.mapStyle.name, { replacement: '_', remove: /[*\-+~.()'"!:]/g, lower: true }); } else { return this.props.mapStyle.id } } downloadHtml() { const tokenStyle = this.tokenizedStyle(); const htmlTitle = this.props.mapStyle.name || "Map"; const html = `
Download a JSON style to your computer.