Skip to content

Commit 303758d

Browse files
committed
new: add zoomControl and attributionControl props
1 parent f5b27fc commit 303758d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/LeafletView/index.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export type LeafletViewProps = {
5252
webviewStyle?: WebViewProps;
5353
injectedJavaScript?: string;
5454
source?: WebViewProps['source'];
55+
zoomControl?: boolean;
56+
attributionControl?: boolean;
5557
};
5658

5759
const LeafletView: React.FC<LeafletViewProps> = ({
@@ -71,6 +73,8 @@ const LeafletView: React.FC<LeafletViewProps> = ({
7173
webviewStyle,
7274
injectedJavaScript,
7375
source,
76+
zoomControl = true,
77+
attributionControl = true,
7478
}) => {
7579
const webViewRef = useRef<WebView>(null);
7680
const [initialized, setInitialized] = useState(false);
@@ -118,6 +122,24 @@ const LeafletView: React.FC<LeafletViewProps> = ({
118122
}
119123
startupMessage.zoom = zoom;
120124

125+
if (!zoomControl) {
126+
const hideZoomControlsJS = `
127+
document.querySelectorAll('.leaflet-bar a').forEach(element => {
128+
element.style.display = 'none';
129+
});
130+
`;
131+
webViewRef.current?.injectJavaScript(hideZoomControlsJS);
132+
}
133+
134+
if (!attributionControl) {
135+
const hideAttributionControlsJS = `
136+
document.querySelectorAll('.leaflet-control-attribution').forEach(element => {
137+
element.style.display = 'none';
138+
});
139+
`;
140+
webViewRef.current?.injectJavaScript(hideAttributionControlsJS);
141+
}
142+
121143
sendMessage(startupMessage);
122144
setInitialized(true);
123145
logMessage('sending initial message');

0 commit comments

Comments
 (0)