Use union type instead of enum for feature format
This commit is contained in:
committed by
Andreas Hocevar
parent
03dbe1f9a1
commit
d05204f50b
@@ -1,7 +1,6 @@
|
||||
/**
|
||||
* @module ol/featureloader
|
||||
*/
|
||||
import FormatType from './format/FormatType.js';
|
||||
import {VOID} from './functions.js';
|
||||
|
||||
/**
|
||||
@@ -72,7 +71,7 @@ export function loadFeaturesXhr(
|
||||
typeof url === 'function' ? url(extent, resolution, projection) : url,
|
||||
true
|
||||
);
|
||||
if (format.getType() == FormatType.ARRAY_BUFFER) {
|
||||
if (format.getType() == 'arraybuffer') {
|
||||
xhr.responseType = 'arraybuffer';
|
||||
}
|
||||
xhr.withCredentials = withCredentials;
|
||||
@@ -86,9 +85,9 @@ export function loadFeaturesXhr(
|
||||
const type = format.getType();
|
||||
/** @type {Document|Node|Object|string|undefined} */
|
||||
let source;
|
||||
if (type == FormatType.JSON || type == FormatType.TEXT) {
|
||||
if (type == 'json' || type == 'text') {
|
||||
source = xhr.responseText;
|
||||
} else if (type == FormatType.XML) {
|
||||
} else if (type == 'xml') {
|
||||
source = xhr.responseXML;
|
||||
if (!source) {
|
||||
source = new DOMParser().parseFromString(
|
||||
@@ -96,7 +95,7 @@ export function loadFeaturesXhr(
|
||||
'application/xml'
|
||||
);
|
||||
}
|
||||
} else if (type == FormatType.ARRAY_BUFFER) {
|
||||
} else if (type == 'arraybuffer') {
|
||||
source = /** @type {ArrayBuffer} */ (xhr.response);
|
||||
}
|
||||
if (source) {
|
||||
|
||||
@@ -51,6 +51,10 @@ import {
|
||||
* Default is no rounding.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {'arraybuffer' | 'json' | 'text' | 'xml'} Type
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -134,7 +138,7 @@ class FeatureFormat {
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {import("./FormatType.js").default} Format.
|
||||
* @return {Type} The format type.
|
||||
*/
|
||||
getType() {
|
||||
return abstract();
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* @module ol/format/FormatType
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
ARRAY_BUFFER: 'arraybuffer',
|
||||
JSON: 'json',
|
||||
TEXT: 'text',
|
||||
XML: 'xml',
|
||||
};
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/JSONFeature
|
||||
*/
|
||||
import FeatureFormat from './Feature.js';
|
||||
import FormatType from './FormatType.js';
|
||||
import {abstract} from '../util.js';
|
||||
|
||||
/**
|
||||
@@ -19,10 +18,10 @@ class JSONFeature extends FeatureFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("./FormatType.js").default} Format.
|
||||
* @return {import("./Feature.js").Type} Format.
|
||||
*/
|
||||
getType() {
|
||||
return FormatType.JSON;
|
||||
return 'json';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
//FIXME Implement projection handling
|
||||
|
||||
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
|
||||
import FormatType from './FormatType.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
import MultiLineString from '../geom/MultiLineString.js';
|
||||
@@ -238,10 +237,10 @@ class MVT extends FeatureFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("./FormatType.js").default} Format.
|
||||
* @return {import("./Feature.js").Type} Format.
|
||||
*/
|
||||
getType() {
|
||||
return FormatType.ARRAY_BUFFER;
|
||||
return 'arraybuffer';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/TextFeature
|
||||
*/
|
||||
import FeatureFormat from '../format/Feature.js';
|
||||
import FormatType from '../format/FormatType.js';
|
||||
import {abstract} from '../util.js';
|
||||
|
||||
/**
|
||||
@@ -19,10 +18,10 @@ class TextFeature extends FeatureFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("./FormatType.js").default} Format.
|
||||
* @return {import("./Feature.js").Type} Format.
|
||||
*/
|
||||
getType() {
|
||||
return FormatType.TEXT;
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import Feature from '../Feature.js';
|
||||
import FeatureFormat, {transformGeometryWithOptions} from './Feature.js';
|
||||
import FormatType from './FormatType.js';
|
||||
import GeometryCollection from '../geom/GeometryCollection.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
@@ -691,10 +690,10 @@ class WKB extends FeatureFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("./FormatType.js").default} Format.
|
||||
* @return {import("./Feature.js").Type} Format.
|
||||
*/
|
||||
getType() {
|
||||
return this.hex_ ? FormatType.TEXT : FormatType.ARRAY_BUFFER;
|
||||
return this.hex_ ? 'text' : 'arraybuffer';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* @module ol/format/XMLFeature
|
||||
*/
|
||||
import FeatureFormat from '../format/Feature.js';
|
||||
import FormatType from '../format/FormatType.js';
|
||||
import {abstract} from '../util.js';
|
||||
import {extend} from '../array.js';
|
||||
import {getXMLSerializer, isDocument, parse} from '../xml.js';
|
||||
@@ -27,10 +26,10 @@ class XMLFeature extends FeatureFormat {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("./FormatType.js").default} Format.
|
||||
* @return {import("./Feature.js").Type} Format.
|
||||
*/
|
||||
getType() {
|
||||
return FormatType.XML;
|
||||
return 'xml';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import Event from '../events/Event.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import FormatType from '../format/FormatType.js';
|
||||
import Interaction from './Interaction.js';
|
||||
import {TRUE} from '../functions.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
@@ -143,7 +142,7 @@ class DragAndDrop extends Interaction {
|
||||
}
|
||||
this.formats_.push(format);
|
||||
this.readAsBuffer_ =
|
||||
this.readAsBuffer_ || format.getType() === FormatType.ARRAY_BUFFER;
|
||||
this.readAsBuffer_ || format.getType() === 'arraybuffer';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +191,7 @@ class DragAndDrop extends Interaction {
|
||||
for (let i = 0, ii = formats.length; i < ii; ++i) {
|
||||
const format = formats[i];
|
||||
let input = result;
|
||||
if (this.readAsBuffer_ && format.getType() !== FormatType.ARRAY_BUFFER) {
|
||||
if (this.readAsBuffer_ && format.getType() !== 'arraybuffer') {
|
||||
if (text === undefined) {
|
||||
text = new TextDecoder().decode(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user