Skip to content

Commit b521b38

Browse files
authored
Merge pull request #44 from mblomdahl/feature/min-radius
Feature/minRadius and maxRadius
2 parents 5813a4d + e5103da commit b521b38

6 files changed

Lines changed: 3114 additions & 6052 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ myCircle.on('contextmenu', function (mapMouseEvent) {
7878
- `options.fillOpacity` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Fill opacity (optional, default `0.25`)
7979
- `options.refineStroke` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Adjust circle polygon precision based on radius and zoom
8080
(i.e. prettier circles at the expense of performance) (optional, default `false`)
81+
- `options.minRadius` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Minimum radius (optional, default `10`)
82+
- `options.maxRadius` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Maximum radius (optional, default `1100000`)
8183
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Property metadata for Mapbox GL JS circle object (optional, default `{}`)
8284

8385
#### on

example/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const editableOpts = {
6161
strokeOpacity: 0.85,
6262
fillColor: '#29AB87',
6363
fillOpacity: 0.2,
64+
minRadius: 100,
65+
maxRadius: 500000,
6466
debugEl: document.body.appendChild(document.createElement('div'))
6567
};
6668

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140

141141
var editableCircleOpts = {
142142
editable: true,
143+
minRadius: 50,
143144
debugEl: document.getElementById('debug')
144145
};
145146

lib/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class MapboxCircle {
126126

127127
/** @param {number} newRadius Meter radius. */
128128
set radius(newRadius) {
129-
this._currentRadius = Math.min(Math.max(this._minRadius, newRadius), this._maxRadius);
129+
this._currentRadius = Math.min(Math.max(this.options.minRadius, newRadius), this.options.maxRadius);
130130
this._updateCircle();
131131
this._animate();
132132
}
@@ -157,6 +157,8 @@ class MapboxCircle {
157157
* @param {?number} [options.fillOpacity=0.25] Fill opacity
158158
* @param {?boolean} [options.refineStroke=false] Adjust circle polygon precision based on radius and zoom
159159
* (i.e. prettier circles at the expense of performance)
160+
* @param {?number} [options.minRadius=10] Minimum radius
161+
* @param {?number} [options.maxRadius=1100000] Maximum radius
160162
* @param {?Object} [options.properties={}] Property metadata for Mapbox GL JS circle object
161163
* @public
162164
*/
@@ -170,8 +172,6 @@ class MapboxCircle {
170172

171173
/** @const {[number,number]} */ this._lastCenterLngLat = [centerLng, centerLat];
172174
/** @const {[number,number]} */ this._currentCenterLngLat = [centerLng, centerLat];
173-
/** @const {number} */ this._minRadius = 1e1;
174-
/** @const {number} */ this._maxRadius = 1.1e6;
175175
/** @const {number} */ this._lastRadius = Math.round(radius);
176176
/** @const {number} */ this._currentRadius = Math.round(radius);
177177
/** @const {Object} */ this.options = _.extend({
@@ -182,6 +182,8 @@ class MapboxCircle {
182182
fillColor: '#FB6A4A',
183183
fillOpacity: 0.25,
184184
refineStroke: false,
185+
minRadius: 10,
186+
maxRadius: 1.1e6,
185187
properties: {},
186188
debugEl: null
187189
}, options);

0 commit comments

Comments
 (0)