-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert controls to ES6 class syntax; ditch util.setOptions
- Loading branch information
Showing
7 changed files
with
71 additions
and
137 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,46 @@ | ||
'use strict'; | ||
|
||
const util = require('../../util/util'); | ||
const Evented = require('../../util/evented'); | ||
module.exports = Control; | ||
|
||
/** | ||
* The base class for map-related interface elements. | ||
* | ||
* The `Control` class mixes in [`Evented`](#Evented) methods. | ||
* | ||
* @class Control | ||
* The `Control` class inherits event methods from [`Evented`](#Evented). | ||
*/ | ||
function Control() {} | ||
|
||
Control.prototype = util.inherit(Evented, { | ||
class Control extends Evented { | ||
/** | ||
* Adds the control to a map. | ||
* | ||
* @param {Map} map The Mapbox GL JS map to add the control to. | ||
* @returns {Control} `this` | ||
*/ | ||
addTo: function(map) { | ||
addTo(map) { | ||
this._map = map; | ||
const container = this._container = this.onAdd(map); | ||
if (this.options && this.options.position) { | ||
const pos = this.options.position; | ||
const corner = map._controlCorners[pos]; | ||
if (this._position) { | ||
const corner = map._controlCorners[this._position]; | ||
container.className += ' mapboxgl-ctrl'; | ||
if (pos.indexOf('bottom') !== -1) { | ||
if (this._position.indexOf('bottom') !== -1) { | ||
corner.insertBefore(container, corner.firstChild); | ||
} else { | ||
corner.appendChild(container); | ||
} | ||
} | ||
|
||
return this; | ||
}, | ||
} | ||
|
||
/** | ||
* Removes the control from the map it has been added to. | ||
* | ||
* @returns {Control} `this` | ||
*/ | ||
remove: function() { | ||
remove() { | ||
this._container.parentNode.removeChild(this._container); | ||
if (this.onRemove) this.onRemove(this._map); | ||
this._map = null; | ||
return this; | ||
} | ||
}); | ||
} | ||
|
||
module.exports = Control; |
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.