You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
650 B
19 lines
650 B
2 years ago
|
import { useEffect, useRef } from 'react';
|
||
|
export function useAttribution(map, attribution) {
|
||
|
const attributionRef = useRef(attribution);
|
||
|
useEffect(function updateAttribution() {
|
||
|
if (attribution !== attributionRef.current && map.attributionControl != null) {
|
||
|
if (attributionRef.current != null) {
|
||
|
map.attributionControl.removeAttribution(attributionRef.current);
|
||
|
}
|
||
|
if (attribution != null) {
|
||
|
map.attributionControl.addAttribution(attribution);
|
||
|
}
|
||
|
}
|
||
|
attributionRef.current = attribution;
|
||
|
}, [
|
||
|
map,
|
||
|
attribution
|
||
|
]);
|
||
|
}
|