Skip to content

Commit

Permalink
Remove hard mapgl dependency (#24)
Browse files Browse the repository at this point in the history
* Remove hard mapgl dependency

* fix formatting

* 2.0.4
  • Loading branch information
kalyanov authored Nov 3, 2022
1 parent 92b7039 commit d4a0f04
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@2gis/mapgl-ruler",
"version": "2.0.3",
"version": "2.0.4",
"description": "",
"license": "BSD-2-Clause",
"main": "dist/ruler.js",
Expand Down
71 changes: 71 additions & 0 deletions src/control/control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Class for the map's controls creating.
*/
export class Control {
/**
* @hidden
* @internal
*/
protected _wrap: HTMLDivElement;

private _controlPane: any;
private _container: HTMLDivElement;
private _position: mapgl.ControlPosition;

/**
* Example:
* ```js
* const control = new mapgl.Control(
* map,
* '<button>Some text</button>',
* { position: 'topLeft' },
* );
* ```
* @param map The map instance.
* @param content Control HTML content.
* @param options Control options.
*/
constructor(map: mapgl.Map, content: string, options: mapgl.ControlOptions) {
const { position } = options;
this._wrap = document.createElement('div');
this._wrap.style.userSelect = 'none';
this._wrap.innerHTML = content;

this._position = position;
this._controlPane = (map as any)._controlPane;
this._container = this._controlPane.getContainerByPosition(position);
this._container?.append(this._wrap);
}

/**
* Destroys the control.
*/
public destroy(): void {
this._wrap.remove();
}

/**
* Returns the position of the control.
*/
public getPosition(): mapgl.ControlPosition {
return this._position;
}

/**
* Sets the position of the control.
* @param position Required position of the control.
*/
public setPosition(position: mapgl.ControlPosition): void {
this._container.removeChild(this._wrap);
this._container = this._controlPane.getContainerByPosition(position);
this._container.append(this._wrap);
this._position = position;
}

/**
* Returns the container of the control.
*/
public getContainer(): HTMLDivElement {
return this._wrap;
}
}
3 changes: 2 additions & 1 deletion src/control/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styles from './index.module.css';
import icon_distance from 'raw-loader!./icon_distance.svg';
import icon_area from 'raw-loader!./icon_area.svg';
import { DEFAULT_RULER_MODE } from '../constants';
import { Control } from './control';

export interface RulerControlOptions extends mapgl.ControlOptions {
/**
Expand All @@ -19,7 +20,7 @@ export interface RulerControlOptions extends mapgl.ControlOptions {
/**
* A class that provides a ruler control on the map.
*/
export class RulerControl extends mapgl.Control {
export class RulerControl extends Control {
private readonly ruler: Ruler;
private readonly icon: any;
private isEnabled: boolean;
Expand Down

0 comments on commit d4a0f04

Please sign in to comment.