Skip to content

Commit e7673a8

Browse files
authored
add attribution settings (#32)
* add attribution settings * linting
1 parent 050a008 commit e7673a8

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

demo/src/DemoToggleCompare.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default defineComponent({
105105
const availableStyles = [
106106
openStreetMapStyle,
107107
naipStyle,
108-
nyImagery
108+
nyImagery,
109109
]
110110
111111
const selectedStyleIndexA = ref(0)
@@ -115,7 +115,7 @@ export default defineComponent({
115115
const selectedLayersA = ref<string[]>([])
116116
const selectedLayersB = ref<string[]>([])
117117
118-
const handleMapReady = (map: MaplibreMap) => {
118+
const handleMapAReady = (map: MaplibreMap) => {
119119
mapAInstance.value = map;
120120
mapAInstance.value.setStyle(availableStyles[selectedStyleIndexA.value]);
121121
}
@@ -145,7 +145,7 @@ export default defineComponent({
145145
selectedStyleIndexB,
146146
selectedLayersA,
147147
selectedLayersB,
148-
handleMapReady,
148+
handleMapAReady,
149149
handleToggleCompare,
150150
}
151151
}
@@ -214,7 +214,7 @@ export default defineComponent({
214214
:camera="{ center: [-74.1847, 43.1339], zoom: 9, bearing: 0, pitch: 0 }"
215215
:swiperOptions="swiperOptions"
216216
:compareEnabled="compareEnabled"
217-
@map-ready="handleMapReady"
217+
@map-ready-a="handleMapAReady"
218218
/>
219219
</div>
220220
</div>

src/components/LayerCompare.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import {
33
defineComponent, PropType,
44
} from 'vue';
5-
import { StyleSpecification, RequestParameters, ResourceType } from 'maplibre-gl';
5+
import {
6+
AttributionControlOptions, StyleSpecification, RequestParameters, ResourceType,
7+
} from 'maplibre-gl';
68
import 'maplibre-gl/dist/maplibre-gl.css';
79
import type { SwiperOptions, CameraData } from './MapCompare.vue';
810
import MapCompare from './MapCompare.vue';
@@ -73,6 +75,11 @@ export default defineComponent({
7375
arrowColor: '#666',
7476
}),
7577
},
78+
attributionControl: {
79+
type: [Object, Boolean] as PropType<AttributionControlOptions | false>,
80+
required: false,
81+
default: () => undefined,
82+
},
7683
},
7784
emits: ['panend', 'zoomend', 'pitchend', 'rotateend'],
7885
setup(_props, { emit }) {
@@ -113,6 +120,7 @@ export default defineComponent({
113120
:layer-order="layerOrder"
114121
:headers="headers"
115122
:transform-request="transformRequest"
123+
:attribution-control="attributionControl"
116124
@panend="handlePanEnd"
117125
@zoomend="handleZoomEnd"
118126
@pitchend="handlePitchEnd"

src/components/MapCompare.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ export default defineComponent({
9898
darkMode: false,
9999
}),
100100
},
101+
attributionControl: {
102+
type: [Object, Boolean] as PropType<maplibregl.AttributionControlOptions | false>,
103+
required: false,
104+
default: () => undefined,
105+
},
101106
},
102107
emits: ['panend', 'zoomend', 'pitchend', 'rotateend', 'loading-complete'],
103108
setup(props, { slots, emit }) {
@@ -225,6 +230,7 @@ export default defineComponent({
225230
url,
226231
headers: props.headers,
227232
}),
233+
attributionControl: props.attributionControl,
228234
});
229235
230236
// Initialize Map B
@@ -239,6 +245,7 @@ export default defineComponent({
239245
url,
240246
headers: props.headers,
241247
}),
248+
attributionControl: props.attributionControl,
242249
});
243250
244251
// Enforce absolute positioning immediately after map creation

src/components/ToggleCompare.vue

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
PropType,
99
computed,
1010
nextTick,
11-
defineExpose,
1211
} from 'vue';
1312
import maplibregl, { Map as MaplibreMap, StyleSpecification } from 'maplibre-gl';
1413
import 'maplibre-gl/dist/maplibre-gl.css';
@@ -123,8 +122,17 @@ export default defineComponent({
123122
darkMode: false,
124123
}),
125124
},
125+
mapContainerId: {
126+
type: String,
127+
default: 'mapContainer',
128+
},
129+
attributionControl: {
130+
type: [Object, Boolean] as PropType<maplibregl.AttributionControlOptions | false>,
131+
required: false,
132+
default: () => undefined,
133+
},
126134
},
127-
emits: ['panend', 'zoomend', 'pitchend', 'rotateend', 'loading-complete', 'map-ready'],
135+
emits: ['panend', 'zoomend', 'pitchend', 'rotateend', 'loading-complete', 'map-ready-a', 'map-ready-b'],
128136
setup(props, { slots, emit }) {
129137
const containerRef = ref<HTMLElement>();
130138
const mapARef = ref<HTMLElement>();
@@ -143,12 +151,6 @@ export default defineComponent({
143151
let mapAPitchEndHandler: (() => void) | null = null;
144152
let mapARotateEndHandler: (() => void) | null = null;
145153
146-
// Expose mapA instance
147-
const getMapA = () => mapA;
148-
defineExpose({
149-
getMapA,
150-
});
151-
152154
// Helper function to enforce absolute positioning on map containers
153155
const enforceAbsolutePosition = () => {
154156
if (mapARef.value) {
@@ -274,6 +276,7 @@ export default defineComponent({
274276
url,
275277
headers: props.headers,
276278
}),
279+
attributionControl: props.attributionControl,
277280
});
278281
279282
// Enforce absolute positioning immediately after map creation
@@ -353,7 +356,7 @@ export default defineComponent({
353356
mapA!.on('rotateend', mapARotateEndHandler);
354357
355358
// Emit map-ready event
356-
emit('map-ready', mapA);
359+
emit('map-ready-a', mapA);
357360
};
358361
359362
const initializeMapB = async () => {
@@ -370,6 +373,7 @@ export default defineComponent({
370373
url,
371374
headers: props.headers,
372375
}),
376+
attributionControl: props.attributionControl,
373377
});
374378
375379
// Enforce absolute positioning immediately after map creation
@@ -422,6 +426,7 @@ export default defineComponent({
422426
enforceAbsolutePosition();
423427
};
424428
mapB!.on('resize', mapBResizeHandler);
429+
emit('map-ready-b', mapB);
425430
};
426431
427432
const initializeMaps = async () => {
@@ -581,6 +586,7 @@ export default defineComponent({
581586

582587
<template>
583588
<div
589+
:id="mapContainerId"
584590
ref="containerRef"
585591
class="map-compare-container"
586592
:style="{

0 commit comments

Comments
 (0)