Fix TypeScript errors in ol/format/KML

This commit is contained in:
Kevin Schmidt
2018-09-27 08:34:26 -06:00
parent 2752541ff1
commit f8d3c8e140

View File

@@ -656,7 +656,7 @@ class KML extends XMLFeature {
* @return {string|undefined} Name. * @return {string|undefined} Name.
*/ */
readNameFromDocument(doc) { readNameFromDocument(doc) {
for (let n = doc.firstChild; n; n = n.nextSibling) { for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) { if (n.nodeType == Node.ELEMENT_NODE) {
const name = this.readNameFromNode(/** @type {Element} */ (n)); const name = this.readNameFromNode(/** @type {Element} */ (n));
if (name) { if (name) {
@@ -722,7 +722,7 @@ class KML extends XMLFeature {
*/ */
readNetworkLinksFromDocument(doc) { readNetworkLinksFromDocument(doc) {
const networkLinks = []; const networkLinks = [];
for (let n = doc.firstChild; n; n = n.nextSibling) { for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) { if (n.nodeType == Node.ELEMENT_NODE) {
extend(networkLinks, this.readNetworkLinksFromNode(/** @type {Element} */ (n))); extend(networkLinks, this.readNetworkLinksFromNode(/** @type {Element} */ (n)));
} }
@@ -784,7 +784,7 @@ class KML extends XMLFeature {
*/ */
readRegionFromDocument(doc) { readRegionFromDocument(doc) {
const regions = []; const regions = [];
for (let n = doc.firstChild; n; n = n.nextSibling) { for (let n = /** @type {Node} */ (doc.firstChild); n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) { if (n.nodeType == Node.ELEMENT_NODE) {
extend(regions, this.readRegionFromNode(/** @type {Element} */ (n))); extend(regions, this.readRegionFromNode(/** @type {Element} */ (n)));
} }
@@ -838,6 +838,7 @@ class KML extends XMLFeature {
kml.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION); kml.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
const /** @type {import("../xml.js").NodeStackItem} */ context = {node: kml}; const /** @type {import("../xml.js").NodeStackItem} */ context = {node: kml};
/** @type {!Object<string, (Array<Feature>|Feature|undefined)>} */
const properties = {}; const properties = {};
if (features.length > 1) { if (features.length > 1) {
properties['Document'] = features; properties['Document'] = features;
@@ -931,7 +932,7 @@ function createFeatureStyleFunction(style, styleUrl, defaultStyle, sharedStyles,
if (drawName) { if (drawName) {
name = /** @type {string} */ (feature.get('name')); name = /** @type {string} */ (feature.get('name'));
drawName = drawName && name; drawName = drawName && !!name;
} }
if (style) { if (style) {
@@ -1714,11 +1715,13 @@ function readStyle(node, objectStack) {
if (fill !== undefined && !fill) { if (fill !== undefined && !fill) {
fillStyle = null; fillStyle = null;
} }
let imageStyle = /** @type {import("../style/Image.js").default} */ let imageStyle;
('imageStyle' in styleObject ? if ('imageStyle' in styleObject) {
styleObject['imageStyle'] : DEFAULT_IMAGE_STYLE); if (styleObject['imageStyle'] != DEFAULT_NO_IMAGE_STYLE) {
if (imageStyle == DEFAULT_NO_IMAGE_STYLE) { imageStyle = styleObject['imageStyle'];
imageStyle = undefined; }
} else {
imageStyle = DEFAULT_IMAGE_STYLE;
} }
const textStyle = /** @type {Text} */ const textStyle = /** @type {Text} */
('textStyle' in styleObject ? ('textStyle' in styleObject ?
@@ -2666,7 +2669,7 @@ function writePlacemark(node, feature, objectStack) {
// set id // set id
if (feature.getId()) { if (feature.getId()) {
node.setAttribute('id', feature.getId()); node.setAttribute('id', /** @type {string} */ (feature.getId()));
} }
// serialize properties (properties unknown to KML are not serialized) // serialize properties (properties unknown to KML are not serialized)
@@ -2713,7 +2716,7 @@ function writePlacemark(node, feature, objectStack) {
const options = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[0]); const options = /** @type {import("./Feature.js").WriteOptions} */ (objectStack[0]);
let geometry = feature.getGeometry(); let geometry = feature.getGeometry();
if (geometry) { if (geometry) {
geometry = transformWithOptions(geometry, true, options); geometry = /** @type {import("../geom/Geometry.js").default} */ (transformWithOptions(geometry, true, options));
} }
pushSerializeAndPop(context, PLACEMARK_SERIALIZERS, pushSerializeAndPop(context, PLACEMARK_SERIALIZERS,
GEOMETRY_NODE_FACTORY, [geometry], objectStack); GEOMETRY_NODE_FACTORY, [geometry], objectStack);
@@ -2918,8 +2921,8 @@ function writeStyle(node, style, objectStack) {
* @param {Vec2} vec2 Vec2. * @param {Vec2} vec2 Vec2.
*/ */
function writeVec2(node, vec2) { function writeVec2(node, vec2) {
node.setAttribute('x', vec2.x); node.setAttribute('x', String(vec2.x));
node.setAttribute('y', vec2.y); node.setAttribute('y', String(vec2.y));
node.setAttribute('xunits', vec2.xunits); node.setAttribute('xunits', vec2.xunits);
node.setAttribute('yunits', vec2.yunits); node.setAttribute('yunits', vec2.yunits);
} }