/** * @module ol/format/KML */ import Feature from '../Feature.js'; import Fill from '../style/Fill.js'; import GeometryCollection from '../geom/GeometryCollection.js'; import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryType from '../geom/GeometryType.js'; import Icon from '../style/Icon.js'; import IconAnchorUnits from '../style/IconAnchorUnits.js'; import IconOrigin from '../style/IconOrigin.js'; import LineString from '../geom/LineString.js'; import MultiLineString from '../geom/MultiLineString.js'; import MultiPoint from '../geom/MultiPoint.js'; import MultiPolygon from '../geom/MultiPolygon.js'; import Point from '../geom/Point.js'; import Polygon from '../geom/Polygon.js'; import Stroke from '../style/Stroke.js'; import Style from '../style/Style.js'; import Text from '../style/Text.js'; import XMLFeature from './XMLFeature.js'; import { OBJECT_PROPERTY_NODE_FACTORY, XML_SCHEMA_INSTANCE_URI, createElementNS, getAllTextContent, isDocument, makeArrayExtender, makeArrayPusher, makeChildAppender, makeObjectPropertySetter, makeReplacer, makeSequence, makeSimpleNodeFactory, makeStructureNS, parse, parseNode, pushParseAndPop, pushSerializeAndPop, } from '../xml.js'; import {asArray} from '../color.js'; import {assert} from '../asserts.js'; import {extend, includes} from '../array.js'; import {get as getProjection} from '../proj.js'; import { readBoolean, readDecimal, readString, writeBooleanTextNode, writeCDATASection, writeDecimalTextNode, writeStringTextNode, } from './xsd.js'; import {toRadians} from '../math.js'; import {transformGeometryWithOptions} from './Feature.js'; /** * @typedef {Object} Vec2 * @property {number} x X coordinate. * @property {import("../style/IconAnchorUnits").default} xunits Units of x. * @property {number} y Y coordinate. * @property {import("../style/IconAnchorUnits").default} yunits Units of Y. * @property {import("../style/IconOrigin.js").default} [origin] Origin. */ /** * @typedef {Object} GxTrackObject * @property {Array>} coordinates Coordinates. * @property {Array} whens Whens. */ /** * @const * @type {Array} */ const GX_NAMESPACE_URIS = ['http://www.google.com/kml/ext/2.2']; /** * @const * @type {Array} */ const NAMESPACE_URIS = [ null, 'http://earth.google.com/kml/2.0', 'http://earth.google.com/kml/2.1', 'http://earth.google.com/kml/2.2', 'http://www.opengis.net/kml/2.2', ]; /** * @const * @type {string} */ const SCHEMA_LOCATION = 'http://www.opengis.net/kml/2.2 ' + 'https://developers.google.com/kml/schema/kml22gx.xsd'; /** * @type {Object} */ const ICON_ANCHOR_UNITS_MAP = { 'fraction': IconAnchorUnits.FRACTION, 'pixels': IconAnchorUnits.PIXELS, 'insetPixels': IconAnchorUnits.PIXELS, }; /** * @const * @type {Object>} */ // @ts-ignore const PLACEMARK_PARSERS = makeStructureNS( NAMESPACE_URIS, { 'ExtendedData': extendedDataParser, 'Region': regionParser, 'MultiGeometry': makeObjectPropertySetter(readMultiGeometry, 'geometry'), 'LineString': makeObjectPropertySetter(readLineString, 'geometry'), 'LinearRing': makeObjectPropertySetter(readLinearRing, 'geometry'), 'Point': makeObjectPropertySetter(readPoint, 'geometry'), 'Polygon': makeObjectPropertySetter(readPolygon, 'geometry'), 'Style': makeObjectPropertySetter(readStyle), 'StyleMap': placemarkStyleMapParser, 'address': makeObjectPropertySetter(readString), 'description': makeObjectPropertySetter(readString), 'name': makeObjectPropertySetter(readString), 'open': makeObjectPropertySetter(readBoolean), 'phoneNumber': makeObjectPropertySetter(readString), 'styleUrl': makeObjectPropertySetter(readStyleURL), 'visibility': makeObjectPropertySetter(readBoolean), }, makeStructureNS(GX_NAMESPACE_URIS, { 'MultiTrack': makeObjectPropertySetter(readGxMultiTrack, 'geometry'), 'Track': makeObjectPropertySetter(readGxTrack, 'geometry'), }) ); /** * @const * @type {Object>} */ // @ts-ignore const NETWORK_LINK_PARSERS = makeStructureNS(NAMESPACE_URIS, { 'ExtendedData': extendedDataParser, 'Region': regionParser, 'Link': linkParser, 'address': makeObjectPropertySetter(readString), 'description': makeObjectPropertySetter(readString), 'name': makeObjectPropertySetter(readString), 'open': makeObjectPropertySetter(readBoolean), 'phoneNumber': makeObjectPropertySetter(readString), 'visibility': makeObjectPropertySetter(readBoolean), }); /** * @const * @type {Object>} */ // @ts-ignore const LINK_PARSERS = makeStructureNS(NAMESPACE_URIS, { 'href': makeObjectPropertySetter(readURI), }); /** * @const * @type {Object>} */ // @ts-ignore const REGION_PARSERS = makeStructureNS(NAMESPACE_URIS, { 'LatLonAltBox': latLonAltBoxParser, 'Lod': lodParser, }); /** * @const * @type {Object>} */ // @ts-ignore const KML_SEQUENCE = makeStructureNS(NAMESPACE_URIS, ['Document', 'Placemark']); /** * @const * @type {Object>} */ // @ts-ignore const KML_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, { 'Document': makeChildAppender(writeDocument), 'Placemark': makeChildAppender(writePlacemark), }); /** * @type {import("../color.js").Color} */ let DEFAULT_COLOR; /** * @type {Fill} */ let DEFAULT_FILL_STYLE = null; /** * Get the default fill style (or null if not yet set). * @return {Fill} The default fill style. */ export function getDefaultFillStyle() { return DEFAULT_FILL_STYLE; } /** * @type {import("../size.js").Size} */ let DEFAULT_IMAGE_STYLE_ANCHOR; /** * @type {import("../style/IconAnchorUnits").default} */ let DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS; /** * @type {import("../style/IconAnchorUnits").default} */ let DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS; /** * @type {import("../size.js").Size} */ let DEFAULT_IMAGE_STYLE_SIZE; /** * @type {string} */ let DEFAULT_IMAGE_STYLE_SRC; /** * @type {number} */ let DEFAULT_IMAGE_SCALE_MULTIPLIER; /** * @type {import("../style/Image.js").default} */ let DEFAULT_IMAGE_STYLE = null; /** * Get the default image style (or null if not yet set). * @return {import("../style/Image.js").default} The default image style. */ export function getDefaultImageStyle() { return DEFAULT_IMAGE_STYLE; } /** * @type {string} */ let DEFAULT_NO_IMAGE_STYLE; /** * @type {Stroke} */ let DEFAULT_STROKE_STYLE = null; /** * Get the default stroke style (or null if not yet set). * @return {Stroke} The default stroke style. */ export function getDefaultStrokeStyle() { return DEFAULT_STROKE_STYLE; } /** * @type {Stroke} */ let DEFAULT_TEXT_STROKE_STYLE; /** * @type {Text} */ let DEFAULT_TEXT_STYLE = null; /** * Get the default text style (or null if not yet set). * @return {Text} The default text style. */ export function getDefaultTextStyle() { return DEFAULT_TEXT_STYLE; } /** * @type {Style} */ let DEFAULT_STYLE = null; /** * Get the default style (or null if not yet set). * @return {Style} The default style. */ export function getDefaultStyle() { return DEFAULT_STYLE; } /** * @type {Array