forked from farmOS/farmOS-map
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Example integrating ol-side-panel
- Loading branch information
1 parent
3ea171d
commit 1c3af74
Showing
8 changed files
with
146 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import LayerSwitcher from 'ol-layerswitcher'; | ||
|
||
import layersHalfIcon from 'bootstrap-icons/icons/layers-half.svg'; | ||
|
||
// layer switcher in side panel behavior. | ||
export default { | ||
attach(instance) { | ||
const existingLayerSwitcherControl = instance.map.getControls().getArray() | ||
.find(control => typeof control.renderPanel === 'function'); | ||
|
||
const sidePanel = instance.map.getControls().getArray() | ||
.find(control => typeof control.definePane === 'function'); | ||
|
||
if (!sidePanel) { | ||
return; | ||
} | ||
|
||
const layersPane = sidePanel.definePane({ | ||
paneId: 'layers', | ||
name: 'Layers', | ||
icon: layersHalfIcon, | ||
}); | ||
|
||
const layersDiv = document.createElement('div'); | ||
layersDiv.classList = 'layer-switcher'; | ||
|
||
layersPane.addWidgetElement(layersDiv); | ||
|
||
const renderLayerSwitcher = () => LayerSwitcher.renderPanel( | ||
instance.map, | ||
layersDiv, | ||
{ reverse: true }, | ||
); | ||
|
||
renderLayerSwitcher(); | ||
|
||
// When new layers are added, refresh the layer layer switcher | ||
instance.map.on('farmOS-map.layer', () => { | ||
renderLayerSwitcher(); | ||
}); | ||
|
||
instance.map.removeControl(existingLayerSwitcherControl); | ||
|
||
}, | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters