Improve Draw type to mode conversion
Throw error if Draw is configured with an invalid type.
This commit is contained in:
+14
-16
@@ -1227,23 +1227,21 @@ export function createBox() {
|
|||||||
* @return {Mode} Drawing mode.
|
* @return {Mode} Drawing mode.
|
||||||
*/
|
*/
|
||||||
function getMode(type) {
|
function getMode(type) {
|
||||||
let mode;
|
switch (type) {
|
||||||
if (type === GeometryType.POINT || type === GeometryType.MULTI_POINT) {
|
case GeometryType.POINT:
|
||||||
mode = Mode.POINT;
|
case GeometryType.MULTI_POINT:
|
||||||
} else if (
|
return Mode.POINT;
|
||||||
type === GeometryType.LINE_STRING ||
|
case GeometryType.LINE_STRING:
|
||||||
type === GeometryType.MULTI_LINE_STRING
|
case GeometryType.MULTI_LINE_STRING:
|
||||||
) {
|
return Mode.LINE_STRING;
|
||||||
mode = Mode.LINE_STRING;
|
case GeometryType.POLYGON:
|
||||||
} else if (
|
case GeometryType.MULTI_POLYGON:
|
||||||
type === GeometryType.POLYGON ||
|
return Mode.POLYGON;
|
||||||
type === GeometryType.MULTI_POLYGON
|
case GeometryType.CIRCLE:
|
||||||
) {
|
return Mode.CIRCLE;
|
||||||
mode = Mode.POLYGON;
|
default:
|
||||||
} else if (type === GeometryType.CIRCLE) {
|
throw new Error('Invalid type: ' + type);
|
||||||
mode = Mode.CIRCLE;
|
|
||||||
}
|
}
|
||||||
return /** @type {!Mode} */ (mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Draw;
|
export default Draw;
|
||||||
|
|||||||
@@ -1381,7 +1381,7 @@ describe('ol.interaction.Draw', function () {
|
|||||||
|
|
||||||
describe('#getOverlay', function () {
|
describe('#getOverlay', function () {
|
||||||
it('returns the feature overlay layer', function () {
|
it('returns the feature overlay layer', function () {
|
||||||
const draw = new Draw({});
|
const draw = new Draw({type: 'Point'});
|
||||||
expect(draw.getOverlay()).to.eql(draw.overlay_);
|
expect(draw.getOverlay()).to.eql(draw.overlay_);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user