-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/scts-2-react-leaflet-base-layer' into feature/s…
…torybook
- Loading branch information
Showing
22 changed files
with
459 additions
and
63 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
import type { ReactNode } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import type { To } from 'react-router-dom'; | ||
import { Heading } from '@amsterdam/design-system-react'; | ||
import styles from './styles.module.css'; | ||
|
||
const RRAmsLink = ({ | ||
to, | ||
children, | ||
}: { | ||
to: To; | ||
children: ReactNode; | ||
}): JSX.Element => ( | ||
<Link className="ams-link ams-link--standalone" to={to}> | ||
{children} | ||
</Link> | ||
); | ||
|
||
const NavigationMenu = (): JSX.Element => ( | ||
<div className={styles.container} data-testid="navigation-menu"> | ||
<Link to="/">Home</Link> | ||
<Link to="/contact">Contact</Link> | ||
</div> | ||
<nav className={styles.container} data-testid="navigation-menu"> | ||
<div> | ||
<Heading level={4}>React + Leaflet</Heading> | ||
<RRAmsLink to="/">Amsterdam Base Layer</RRAmsLink> | ||
</div> | ||
<div> | ||
<Heading level={4}>React + React-Leaflet</Heading> | ||
<RRAmsLink to="/react-leaflet/">Amsterdam Base Layer</RRAmsLink> | ||
</div> | ||
</nav> | ||
); | ||
|
||
export default NavigationMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
left: 0; | ||
position: fixed; | ||
right: 0; | ||
text-align: center; | ||
top: 72px; | ||
z-index: 1000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import BaseMap from './'; | ||
|
||
describe('BaseMap', () => { | ||
it('renders the component', () => { | ||
const { container } = render(<BaseMap />); | ||
expect(container.firstChild).toBeDefined(); | ||
}); | ||
|
||
it('uses the amsterdam base tile', () => { | ||
const { container } = render(<BaseMap />); | ||
|
||
// Only test on the less dynamic part of the URL | ||
const imgSrc = ( | ||
container.querySelector('.leaflet-tile-container img') as HTMLImageElement | ||
)?.src.substring(0, 38); | ||
|
||
expect( | ||
imgSrc.match( | ||
/https:\/\/(t1)|(t2)|(t3)|(t4)\.data.amsterdam.nl\/topo_rd\//g | ||
) | ||
).not.toEqual(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import type { FunctionComponent } from 'react'; | ||
import L from 'leaflet'; | ||
import 'leaflet/dist/leaflet.css'; | ||
import getCrsRd from '@/utils/getCrsRd'; | ||
import styles from './styles.module.css'; | ||
|
||
const BaseLayer: FunctionComponent = () => { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const mapRef = useRef<L.Map | null>(null); | ||
|
||
useEffect(() => { | ||
if (containerRef.current === null) { | ||
return; | ||
} | ||
|
||
mapRef.current = new L.Map(containerRef.current, { | ||
center: L.latLng([52.370216, 4.895168]), | ||
zoom: 12, | ||
layers: [ | ||
L.tileLayer('https://{s}.data.amsterdam.nl/topo_rd/{z}/{x}/{y}.png', { | ||
attribution: '', | ||
subdomains: ['t1', 't2', 't3', 't4'], | ||
tms: true, | ||
}), | ||
], | ||
zoomControl: false, | ||
|
||
// Copied from Amsterdam-react-maps | ||
maxZoom: 16, | ||
minZoom: 3, | ||
crs: getCrsRd(), | ||
maxBounds: [ | ||
[52.25168, 4.64034], | ||
[52.50536, 5.10737], | ||
], | ||
}); | ||
|
||
// Remove Leaflet link from the map | ||
mapRef.current.attributionControl.setPrefix(false); | ||
|
||
// eslint-disable-next-line consistent-return | ||
return () => { | ||
if (mapRef.current) mapRef.current.remove(); | ||
}; | ||
}, []); | ||
|
||
return <div className={styles.container} ref={containerRef} />; | ||
}; | ||
|
||
export default BaseLayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.container { | ||
height: 100%; | ||
min-height: 100%; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { render } from '@testing-library/react'; | ||
import BaseMap from './'; | ||
|
||
describe('BaseMap', () => { | ||
it('renders the component', () => { | ||
const { container } = render(<BaseMap />); | ||
expect(container.firstChild).toBeDefined(); | ||
}); | ||
|
||
it('uses the amsterdam base tile', () => { | ||
const { container } = render(<BaseMap />); | ||
|
||
// Only test on the less dynamic part of the URL | ||
const imgSrc = ( | ||
container.querySelector('.leaflet-tile-container img') as HTMLImageElement | ||
)?.src.substring(0, 38); | ||
|
||
expect( | ||
imgSrc.match( | ||
/https:\/\/(t1)|(t2)|(t3)|(t4)\.data.amsterdam.nl\/topo_rd\//g | ||
) | ||
).not.toEqual(null); | ||
}); | ||
}); |
Oops, something went wrong.