diff --git a/index.html b/index.html new file mode 100644 index 00000000000..869c88cc371 --- /dev/null +++ b/index.html @@ -0,0 +1,37 @@ + + + + +Display a map + + + + + + + +
+ + + + diff --git a/test/unit/ui/marker.test.js b/test/unit/ui/marker.test.js index 99d2920e225..c47e2c4af41 100644 --- a/test/unit/ui/marker.test.js +++ b/test/unit/ui/marker.test.js @@ -465,3 +465,69 @@ test('Marker with draggable:true does not error if removed on mousedown', (t) => t.ok(map.fire('mouseup')); t.end(); }); + +test('Marker can set rotationAlignment and pitchAlignment', (t) => { + const map = createMap(t); + const marker = new Marker({rotationAlignment: 'map', pitchAlignment: 'map'}) + .setLngLat([0, 0]) + .addTo(map); + + t.equal(marker.getRotationAlignment(), 'map'); + t.equal(marker.getPitchAlignment(), 'map'); + + map.remove(); + t.end(); +}); + +test('Marker can set and update rotation', (t) => { + const map = createMap(t); + const marker = new Marker({rotation: 45}) + .setLngLat([0, 0]) + .addTo(map); + + t.equal(marker.getRotation(), 45); + + marker.setRotation(90); + t.equal(marker.getRotation(), 90); + + map.remove(); + t.end(); +}); + +test('Marker transforms rotation with the map', (t) => { + const map = createMap(t); + const marker = new Marker({rotationAlignment: 'map'}) + .setLngLat([0, 0]) + .addTo(map); + + const rotationRegex = /rotateZ\(-?([0-9]+)deg\)/; + const initialRotation = marker.getElement().style.transform.match(rotationRegex)[1]; + + map.setBearing(map.getBearing() + 180); + + const finalRotation = marker.getElement().style.transform.match(rotationRegex)[1]; + t.notEqual(initialRotation, finalRotation); + + map.remove(); + t.end(); +}); + +test('Marker transforms pitch with the map', (t) => { + const map = createMap(t); + const marker = new Marker({pitchAlignment: 'map'}) + .setLngLat([0, 0]) + .addTo(map); + + map.setPitch(0); + + const rotationRegex = /rotateX\(-?([0-9]+)deg\)/; + const initialPitch = marker.getElement().style.transform.match(rotationRegex)[1]; + + map.setPitch(45); + + const finalPitch = marker.getElement().style.transform.match(rotationRegex)[1]; + t.notEqual(initialPitch, finalPitch); + + map.remove(); + t.end(); +});