Skip to content

Commit

Permalink
Merge branch 'fcieminski-download-svg'
Browse files Browse the repository at this point in the history
  • Loading branch information
damonsk committed Dec 11, 2023
2 parents ee7e2f3 + c639578 commit 190d728
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function App() {

const [highlightLine, setHighlightLine] = useState(0);
const mapRef = useRef(null);
const svgRef = useRef(null);
const [mainViewHeight, setMainViewHeight] = useState(100);
const [errorLine, setErrorLine] = useState(-1);
const [showLineNumbers, setShowLineNumbers] = useState(false);
Expand Down Expand Up @@ -180,6 +181,19 @@ function App() {
});
}

const downloadMapSvg = () => {
const svg = svgRef.current;
const svgData = new XMLSerializer().serializeToString(svg);
const svgBlob = new Blob([svgData], {
type: 'image/svg+xml;charset=utf-8',
});
const svgUrl = URL.createObjectURL(svgBlob);
const link = document.createElement('a');
link.download = mapTitle;
link.href = svgUrl;
link.click();
};

React.useEffect(() => {
try {
setErrorLine([]);
Expand Down Expand Up @@ -276,6 +290,7 @@ function App() {
newMapClick={newMap}
saveMapClick={saveMap}
downloadMapImage={downloadMap}
downloadMapSvg={downloadMapSvg}
showLineNumbers={showLineNumbers}
setShowLineNumbers={setShowLineNumbers}
showLinkedEvolved={showLinkedEvolved}
Expand Down Expand Up @@ -342,6 +357,7 @@ function App() {
mapDimensions={mapDimensions}
mapEvolutionStates={mapEvolutionStates}
mapRef={mapRef}
svgRef={svgRef}
mapText={mapText}
mutateMapText={mutateMapText}
setMetaText={setMetaText}
Expand Down
6 changes: 5 additions & 1 deletion src/components/editor/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Controls(props) {
setMetaText,
newMapClick,
downloadMapImage,
downloadMapSvg,
currentUrl,
setShowLineNumbers,
showLineNumbers,
Expand Down Expand Up @@ -86,7 +87,10 @@ function Controls(props) {
<Dropdown.Item eventKey="1" onClick={downloadMapImage}>
Download as PNG
</Dropdown.Item>
<Dropdown.Item eventKey="2" onClick={() => setModalShow(true)}>
<Dropdown.Item eventKey="2" onClick={downloadMapSvg}>
Download as SVG
</Dropdown.Item>
<Dropdown.Item eventKey="3" onClick={() => setModalShow(true)}>
Get Clone URL
</Dropdown.Item>
<Dropdown.Item
Expand Down
1 change: 1 addition & 0 deletions src/components/map/MapCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function MapCanvas(props) {
fontSize={props.mapStyleDefs.fontSize}
className={props.mapStyleDefs.className}
id="svgMap"
ref={props.svgRef}
width={props.mapDimensions.width + 2 * props.mapPadding}
height={props.mapDimensions.height + 4 * props.mapPadding}
viewBox={
Expand Down
1 change: 1 addition & 0 deletions src/constants/mapstyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const mergeIntoDefault = style => merge({}, Plain, style);

export const Plain = {
className: 'plain',
backgroundColor: 'white',
fontFamily: '"Helvetica Neue",Helvetica,Arial,sans-serif',
fontSize: '13px',
stroke: 'black',
Expand Down

0 comments on commit 190d728

Please sign in to comment.