Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ol-map-adapter): make compatible with ol v9
- Loading branch information
Showing
11 changed files
with
105 additions
and
283 deletions.
There are no files selected for viewing
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
65 changes: 31 additions & 34 deletions
65
packages/ol-map-adapter/src/controls/createButtonControl.ts
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 |
---|---|---|
@@ -1,47 +1,44 @@ | ||
import './createButtonControl.css'; | ||
|
||
import Control from 'ol/control/Control'; | ||
|
||
import type { ButtonControlOptions } from '@nextgis/webmap'; | ||
|
||
export function createButtonControl(options: ButtonControlOptions): Control { | ||
const newControl = (function (C) { | ||
function NewControl(this: Control) { | ||
const button = document.createElement('button'); | ||
button.className = 'custom-button-control'; | ||
if (typeof options.html === 'string') { | ||
button.innerHTML = options.html; | ||
} else if (options.html) { | ||
button.appendChild(options.html); | ||
} | ||
if (typeof options.title === 'string') { | ||
button.title = options.title; | ||
class NewControl extends Control { | ||
constructor() { | ||
super({ element: createControlElement(options) }); | ||
if (options.onClick) { | ||
this.element | ||
.querySelector('button')! | ||
.addEventListener('click', options.onClick, false); | ||
} | ||
|
||
const element = document.createElement('div'); | ||
element.className = | ||
(options.addClass ? options.addClass + ' ' : '') + | ||
'ol-unselectable webmap-ctrl-group'; | ||
element.appendChild(button); | ||
|
||
C.call(this, { element }); | ||
|
||
button.addEventListener('click', () => options.onClick(), false); | ||
} | ||
|
||
if (C) { | ||
NewControl.__proto__ = C; | ||
handleRotateNorth() { | ||
this.getMap()?.getView().setRotation(0); | ||
} | ||
NewControl.prototype = Object.create(Control && Control.prototype); | ||
NewControl.prototype.constructor = NewControl; | ||
|
||
NewControl.prototype.handleRotateNorth = function handleRotateNorth() { | ||
this.getMap().getView().setRotation(0); | ||
}; | ||
} | ||
|
||
return NewControl; | ||
})(Control); | ||
return new NewControl(); | ||
} | ||
|
||
// @ts-ignore | ||
return new newControl(); | ||
function createControlElement(options: ButtonControlOptions) { | ||
const button = document.createElement('button'); | ||
button.className = 'custom-button-control'; | ||
if (typeof options.html === 'string') { | ||
button.innerHTML = options.html; | ||
} else if (options.html instanceof HTMLElement) { | ||
button.appendChild(options.html); | ||
} | ||
if (typeof options.title === 'string') { | ||
button.title = options.title; | ||
} | ||
|
||
const element = document.createElement('div'); | ||
element.className = | ||
(options.addClass ? options.addClass + ' ' : '') + | ||
'ol-unselectable webmap-ctrl-group'; | ||
element.appendChild(button); | ||
|
||
return element; | ||
} |
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
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
Oops, something went wrong.