Skip to content

Commit

Permalink
Add hasControl method (#10035)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen authored Oct 21, 2020
1 parent 2311a03 commit ff8e087
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,23 @@ class Map extends Camera {
return this;
}

/**
* Checks if a control exists on the map.
*
* @param {IControl} control The {@link IControl} to check.
* @returns {boolean} True if map contains control.
* @example
* // Define a new navigation control.
* var navigation = new mapboxgl.NavigationControl();
* // Add zoom and rotation controls to the map.
* map.addControl(navigation);
* // Check that the navigation control exists on the map.
* map.hasControl(navigation);
*/
hasControl(control: IControl) {
return this._controls.indexOf(control) > -1;
}

/**
* Resizes the map according to the dimensions of its
* `container` element.
Expand Down
16 changes: 16 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,22 @@ test('Map', (t) => {

});

t.test('#hasControl', (t) => {
const map = createMap(t);
function Ctrl() {}
Ctrl.prototype = {
onAdd(_) {
return window.document.createElement('div');
}
};

const control = new Ctrl();
t.equal(map.hasControl(control), false, 'Reference to control is not found');
map.addControl(control);
t.equal(map.hasControl(control), true, 'Reference to control is found');
t.end();
});

t.test('#project', (t) => {
const map = createMap(t);
t.deepEqual(map.project([0, 0]), {x: 100, y: 100});
Expand Down

0 comments on commit ff8e087

Please sign in to comment.