Skip to content

Commit

Permalink
Merge pull request #19 from aloxe/rainbow-fix
Browse files Browse the repository at this point in the history
fix rainbow when uploading multifeature gpx
  • Loading branch information
aloxe authored Jul 16, 2024
2 parents 85d5d94 + 08dec95 commit 24bca51
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/components/FileUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const FileUpload = ({ isLogged, setIsLogged, setGeojsonList }) => {
const geojson = await loadGeoJsonFromGpx(name);
const l = geojson.features.length;
geojson.features.map((feature, i) => feature.properties.color = calcColor(l,i));
geojson.gpx = true;
setCurrentGeoJson(geojson);
setGeojsonList([geojson]);
}
Expand Down Expand Up @@ -72,6 +73,7 @@ const FileUpload = ({ isLogged, setIsLogged, setGeojsonList }) => {
};

const uploadjson = async () => {
delete currentGeoJson.gpx;
currentGeoJson.date = form.date;
currentGeoJson.title = form.title;
currentGeoJson.countries = form.countries;
Expand Down
2 changes: 1 addition & 1 deletion src/components/MainMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const MainMap = ({geojsonList, tileName, handleClickPopup, currentGeoJson}) => {
// removing display for points.
return { strokeWidth: "0", stroke: "black", r: '0', };
}
if (geojson.slug && geojson.slug === currentGeoJson?.slug) { // sellected path
if (geojson.gpx || geojson.slug && geojson.slug === currentGeoJson?.slug) { // gpx or sellected path
if (geojson.features.length > 1) { // rainbow colours for multi paths geojson
return {
strokeWidth: "4",
Expand Down
31 changes: 31 additions & 0 deletions src/components/Popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,35 @@
cursor: pointer;
}

.collapse-button {
position: absolute;
right: 20px;
margin: -20px 0 0;
border: 0;
font: 24px sans-serif;
font-weight: normal;
color: #c3c3c3;
text-decoration: none;
font-weight: bold;
background: transparent;
cursor: pointer;
transition: all .5s ease-in-out;
}

.collapse-button.up {
transform: rotate(-90deg);
}

.popup-names {
max-height: 0;
transition: all 1s ease-in-out;
overflow: hidden;
}

.popup-names.show {
max-height: 400px;
}

.popup-names.hide {
max-height: 1px;
}
38 changes: 24 additions & 14 deletions src/components/Popup.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
import { useState } from 'react';
import { countryCodeToFlag } from '../helpers/countryUtil';
import { formatDate } from '../helpers/timeUtil';
import Elevation from './Elevation';
import './Popup.css';


const Popup = ({geojson, handleClickPopup}) => {
const [collapsed, setCollapsed] = useState(false);

const handleClick = () => {
handleClickPopup("close")
}

if (!geojson.title) return
return (
<>
<div className='popup-wraper'>
<div className='popup-wraper'>
<button className="popup-close-button" onClick={handleClick}>×</button>
<div className='popup-content-wrapper'>
<div className='popup-content'>
<div className='popup-title'>🚲 {geojson?.title || ''}</div>
<div className='popup-date'>{(formatDate(undefined, "ddMMYYYY", geojson?.date) || '') + ' ' + geojson?.countries.map(cc => countryCodeToFlag(cc)).join(' ')}</div>
<Elevation geojson={geojson} key="elev" />
<div>{`${geojson?.distance}km`}</div>
</div>
</div>
<div className='popup-tip-container'>
<div className='tip'></div>
<div className='popup-content-wrapper'>
<div className='popup-content'>
<div className='popup-title'>🚲 {geojson?.title || ''}</div>
<div className='popup-date'>{(formatDate(undefined, "ddMMYYYY", geojson?.date) || '') + ' ' + geojson?.countries.map(cc => countryCodeToFlag(cc)).join(' ')}</div>
<Elevation geojson={geojson} key="elev" />
<div>{`${geojson?.distance}km`}</div>
{geojson.features.length > 1 && <>
<button className={`collapse-button ${collapsed ? "up" : "right" }`} onClick={() => setCollapsed(!collapsed)}></button>
<div className={`popup-names ${collapsed ? "show" : "hide" }`}>
{geojson.features.map((feature, index) => (
<div key={index}>
<span style={{color: feature.properties.color ?? "indogo"}}></span> {feature.properties.name}
</div>
))}
</div>
</>}
</div>
</div>
</>
<div className='popup-tip-container'>
<div className='tip'></div>
</div>
</div>
);
}
}

export default Popup;

0 comments on commit 24bca51

Please sign in to comment.