Skip to content

Commit e9f96c5

Browse files
committed
WIP add imagery attribution
1 parent d7eb484 commit e9f96c5

File tree

1 file changed

+45
-2
lines changed
  • examples/live-examples-nextjs/src/app/tasks/building-detection

1 file changed

+45
-2
lines changed

examples/live-examples-nextjs/src/app/tasks/building-detection/page.tsx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export default function BuildingDetection() {
3636
const mapContainer = useRef<HTMLDivElement>(null);
3737
const map = useRef<maplibregl.Map | null>(null);
3838
const draw = useRef<MaplibreDraw | null>(null);
39-
39+
// Keep a ref to the Maplibre attribution control so we can (re)attach it when styles change
40+
const attrControl = useRef<maplibregl.AttributionControl | null>(null);
41+
42+
// Attribution HTML used in the map's attribution control
43+
const attributionHTML = `Imagery: <a href="https://opengeoai.org/" target="_blank" rel="noreferrer" className="underline">geoai</a>`;
44+
4045
// GeoAI hook
4146
const {
4247
isInitialized,
@@ -128,6 +133,17 @@ export default function BuildingDetection() {
128133
zoom: mapInitConfig.zoom,
129134
});
130135

136+
// Add Maplibre attribution control (uses the built-in attribution UI instead of a custom div)
137+
attrControl.current = new maplibregl.AttributionControl({ compact: false, customAttribution: attributionHTML });
138+
map.current.addControl(attrControl.current, 'bottom-left');
139+
// Ensure the attribution control DOM contains our HTML (fixes cases where it's rendered empty)
140+
try {
141+
const el = map.current.getContainer().querySelector('.maplibregl-ctrl-attrib');
142+
if (el) el.innerHTML = attributionHTML;
143+
} catch (e) {
144+
// ignore
145+
}
146+
131147
// Add draw control
132148
draw.current = new MaplibreDraw({
133149
displayControlsDefault: false,
@@ -200,6 +216,26 @@ export default function BuildingDetection() {
200216
map.current?.setZoom(currentZoom);
201217
map.current?.setBearing(currentBearing);
202218
map.current?.setPitch(currentPitch);
219+
220+
// Re-add (or refresh) our attribution control after style changes to ensure it is present
221+
if (map.current) {
222+
try {
223+
if (attrControl.current) {
224+
map.current.removeControl(attrControl.current);
225+
}
226+
} catch (e) {
227+
// ignore
228+
}
229+
attrControl.current = new maplibregl.AttributionControl({ compact: false, customAttribution: attributionHTML });
230+
map.current.addControl(attrControl.current, 'bottom-left');
231+
// Ensure the attribution control DOM contains our HTML after style changes
232+
try {
233+
const el = map.current.getContainer().querySelector('.maplibregl-ctrl-attrib');
234+
if (el) el.innerHTML = attributionHTML;
235+
} catch (e) {
236+
// ignore
237+
}
238+
}
203239
});
204240
}, [mapProvider]);
205241

@@ -235,6 +271,7 @@ export default function BuildingDetection() {
235271

236272
return (
237273
<main className="w-full h-screen flex overflow-hidden bg-gradient-to-br from-gray-50 via-white to-gray-100 relative">
274+
{/* Maplibre AttributionControl only — no manual fallback */}
238275
<BackgroundEffects />
239276

240277
{/* Sidebar */}
@@ -265,7 +302,7 @@ export default function BuildingDetection() {
265302
{/* Map Container */}
266303
<div className="flex-1 h-full relative">
267304
{/* Map overlay with subtle border */}
268-
<div className="absolute inset-2 rounded-lg overflow-hidden border border-gray-200/50 shadow-2xl">
305+
<div className="absolute inset-2 rounded-lg overflow-hidden border border-gray-200/50 shadow-2xl z-0">
269306
<div ref={mapContainer} className="w-full h-full" />
270307
</div>
271308

@@ -293,6 +330,12 @@ export default function BuildingDetection() {
293330
{/* Corner decorations */}
294331
<div className="absolute top-4 right-4 w-20 h-20 border-t-2 border-r-2 border-green-400/40 rounded-tr-lg"></div>
295332
<div className="absolute bottom-4 left-4 w-20 h-20 border-b-2 border-l-2 border-emerald-400/40 rounded-bl-lg"></div>
333+
334+
{/* {mapProvider === "geobase" && (<div className="absolute bottom-6 left-6 z-40 text-xs text-white bg-black/60 backdrop-blur-sm rounded px-3 py-1">
335+
<span>
336+
Imagery: <a href="https://opengeoai.org/" target="_blank" rel="noreferrer" className="underline">geoai</a>
337+
</span>
338+
</div>)} */}
296339
</div>
297340
</main>
298341
);

0 commit comments

Comments
 (0)