Skip to content

Commit ad9ab34

Browse files
authored
feat: MapControls: TrafficControl and TrafficLegendControl (#91)
* add TrafficControl and TrafficLegendControl * remove redundant indent * feat: tests for traffic controls * fix: dummy commit to trigger CI check
1 parent 207aeaa commit ad9ab34

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

__mocks__/azure-maps-control.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ module.exports = {
6464
CompassControl: jest.fn(() => ({ compassOption: 'option' })),
6565
PitchControl: jest.fn(() => ({ pitchOption: 'option' })),
6666
StyleControl: jest.fn(() => ({ styleOption: 'option' })),
67-
ZoomControl: jest.fn(() => ({ zoomOption: 'option' }))
67+
ZoomControl: jest.fn(() => ({ zoomOption: 'option' })),
68+
TrafficControl: jest.fn(() => ({ trafficOption: 'option' })),
69+
TrafficLegendControl: jest.fn(() => ({ trafficLegendOption: 'option' }))
6870
},
6971
layer: {
7072
ImageLayer: jest.fn((options, id) => ({ layer: 'ImageLayer', options, id })),

src/components/AzureMap/useCreateMapControl.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ describe('Control hooks', () => {
8080
expect(createdControl).toEqual({ compassOption: 'option' })
8181
})
8282

83+
it('should return TrafficControl if type equal TrafficControl', () => {
84+
const createdControl = createControl('TrafficControl', {})
85+
expect(createdControl).toEqual({ trafficOption: 'option' })
86+
})
87+
88+
it('should return TrafficLegendControl if type equal TrafficLegendControl', () => {
89+
const createdControl = createControl('TrafficLegendControl', {})
90+
expect(createdControl).toEqual({ trafficLegendOption: 'option' })
91+
})
92+
8393
it('should return undefined if there is no control with type', () => {
8494
const createdControl = createControl('SomeOtherType', {})
8595
expect(createdControl).toEqual(undefined)

src/components/AzureMap/useCreateMapControls.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import atlas, {
44
ControlOptions,
55
PitchControlOptions,
66
StyleControlOptions,
7+
TrafficControlOptions,
78
ZoomControlOptions
89
} from 'azure-maps-control'
910

@@ -32,6 +33,10 @@ export const createControl = (
3233
return new atlas.control.StyleControl(options as StyleControlOptions)
3334
case 'ZoomControl':
3435
return new atlas.control.ZoomControl(options as ZoomControlOptions)
36+
case 'TrafficControl':
37+
return new atlas.control.TrafficControl(options as TrafficControlOptions)
38+
case 'TrafficLegendControl':
39+
return new atlas.control.TrafficLegendControl()
3540
default:
3641
console.warn('Check the type and passed props properties or try CustomControl')
3742
}
@@ -45,3 +50,4 @@ export const useCreateMapCustomControls = (
4550
mapRef.controls.add(control, controlOptions)
4651
})
4752
}
53+

0 commit comments

Comments
 (0)