-
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.
Add setter for units on ScaleControl (#6274)
* Add ScaleControl method to update unit of measure * Add ScaleControl test file * Update documentation * Update name of method and example code * Add test for setUnit method * Correct param documentation for setUnit method * Fix param documentation for setUnit method * Read unit from scale's html * Simplify regex in scale test Co-authored by: ryanhamley <rhamley@skycatch.com>
- Loading branch information
1 parent
bebcfb6
commit b012595
Showing
2 changed files
with
74 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const test = require('mapbox-gl-js-test').test; | ||
const window = require('../../../../src/util/window'); | ||
const Map = require('../../../../src/ui/map'); | ||
const ScaleControl = require('../../../../src/ui/control/scale_control'); | ||
|
||
function createMap() { | ||
const container = window.document.createElement('div'); | ||
return new Map({ | ||
container, | ||
style: { | ||
version: 8, | ||
sources: {}, | ||
layers: [] | ||
}, | ||
hash: true | ||
}); | ||
|
||
} | ||
|
||
test('ScaleControl appears in bottom-left by default', (t) => { | ||
const map = createMap(); | ||
map.addControl(new ScaleControl()); | ||
|
||
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale').length, 1); | ||
t.end(); | ||
}); | ||
|
||
test('ScaleControl appears in the position specified by the position option', (t) => { | ||
const map = createMap(); | ||
map.addControl(new ScaleControl(), 'top-left'); | ||
|
||
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left .mapboxgl-ctrl-scale').length, 1); | ||
t.end(); | ||
}); | ||
|
||
test('ScaleControl should change unit of distance after calling setUnit', (t) => { | ||
const map = createMap(); | ||
const scale = new ScaleControl(); | ||
const selector = '.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-scale'; | ||
map.addControl(scale); | ||
|
||
let contents = map.getContainer().querySelector(selector).innerHTML; | ||
t.match(contents, /km/); | ||
|
||
scale.setUnit('imperial'); | ||
contents = map.getContainer().querySelector(selector).innerHTML; | ||
t.match(contents, /mi/); | ||
t.end(); | ||
}); |