-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scale update units #6138
Closed
Closed
Scale update units #6138
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9749515
Add ScaleControl method to update unit of measure
64e9140
Add ScaleControl test file
914c57e
Update documentation
15fbbed
Update name of method and example code
6d7b572
Add test for setUnit method
80f2791
Correct param documentation for setUnit method
ff9c13f
Fix param documentation for setUnit method
fb650c2
Read unit from scale's html
f8bc7b3
Simplify regex in scale test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇 thank you for adding these tests! Could you also add one that tests the new
updateUnit()
method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @anandthakker I will work on this in the next day or so. Thanks for the feedback.