Skip to content

Commit 90d6bd8

Browse files
committed
fix: added external draw support for layerswitcher
1 parent 63dcc66 commit 90d6bd8

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
* Make timeline example with https://service.pdok.nl/hwh/luchtfotocir/wms/v1_0?request=GetCapabilities&service=wms
3333
* implement cluster: https://openlayers.org/en/latest/examples/clusters-dynamic.html
3434
* add the custom projections to the ui as property editor
35+
* add option to control elements without the use of buttons
36+
* add bookmark options https://viglino.github.io/ol-ext/examples/control/map.control.geobookmark.html
37+
* add legend https://viglino.github.io/ol-ext/examples/legend/map.control.legends.html
3538

3639

3740
### Bugs

src/GEOComp.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ var GEOComp = (function () {
161161
splitscreen: false,
162162
tracker: false,
163163
timeline: false,
164-
gpsCentered: false,
164+
gpsCentered: true,
165165
north: false,
166166
scale: true,
167167
largeButtons: true,
@@ -180,6 +180,7 @@ var GEOComp = (function () {
180180
"splitscreen:vertical": false,
181181
debug: geoContext.previewMode,
182182
}),
183+
external: jsonObjectExposingStateControl("external"),
183184
};
184185

185186

@@ -207,6 +208,7 @@ var GEOComp = (function () {
207208
startDate: string;
208209
endDate: string;
209210
extent: any;
211+
external: any
210212

211213
test: any
212214
}) => {
@@ -332,6 +334,7 @@ var GEOComp = (function () {
332334
startDate={props.startDate}
333335
endDate={props.endDate}
334336
extent={props.extent}
337+
external={props.external.value}
335338
/>
336339
</div>
337340
</div>
@@ -651,4 +654,5 @@ export default withExposingConfigs(GEOComp, [
651654
new NameConfig("event", trans("component.event")),
652655
new NameConfig("bbox", trans("component.bbox")),
653656
new NameConfig("feature", trans("component.feature")),
657+
new NameConfig("external", trans("component.external")),
654658
]);

src/i18n/comps/locales/en.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export const en = {
3939
"designer": "Designer mode",
4040
"buttons": "Buttons",
4141
"showLogo": "Show logo",
42-
"feature": "feature"
42+
"feature": "feature",
43+
"external": "External control"
4344
},
4445
"methods": {
4546
"xml": "Get XML",

src/vendors/Geo.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ function Geo(props) {
8888
}
8989
}
9090

91+
//Return an external value object
92+
const externalValue = function (name, obj) {
93+
if (!obj) obj = props.external || {}
94+
const names = name.split('.', 2)
95+
if (names.length > 1) {
96+
if (obj[names[0]]) return externalValue(names[1], obj[names[0]])
97+
return null //not found
98+
}
99+
return obj[names[0]]
100+
}
101+
91102
//Fetch the geolocation based on browser or ip when center is not set
92103
const elementRef = useCallback(ref => {
93104
setGeoRef(ref);
@@ -444,9 +455,14 @@ function Geo(props) {
444455
// Add a simple push button to save features
445456
// Add control inside the map
446457
var layerCtrl = new LayerSwitcher({
458+
target: externalValue('layerswitcher.target')
447459
// collapsed: false,
448460
// mouseover: true
449461
});
462+
//Connect external drawer if needed
463+
if (externalValue('layerswitcher.draw')) {
464+
layerCtrl.on('drawlist', externalValue('layerswitcher.draw'))
465+
}
450466
if (featureEnabled('layers')) map.addControl(layerCtrl);
451467

452468
// Swipe control bar
@@ -710,7 +726,7 @@ function Geo(props) {
710726
//Add map init event
711727
fireEvent('map:init', map)
712728
}
713-
}, [props.features, props.extent, props.projection, props.startDate, props.endDate, geoRef]);
729+
}, [props.features, props.extent, props.projection, props.startDate, props.endDate, props.external, geoRef]);
714730

715731

716732
useEffect(() => {
@@ -821,6 +837,7 @@ Geo.propTypes = {
821837
startDate: PropTypes.string,
822838
endDate: PropTypes.string,
823839
extent: PropTypes.array,
840+
external: PropTypes.object,
824841
}
825842

826843
export default Geo;

0 commit comments

Comments
 (0)