Add crossOrigin option for icons

Make the crossOrigin setting for icons configurable to avoid errors when KML files reference images when are not CORS enabled
Pass scope in readPlacemark_
and to handle IconStyle in a placemark style map

Test crossOrigin option for icons
Add tests for IconStyle in style maps and shared styles
This commit is contained in:
mike-000
2019-10-12 16:08:57 +01:00
parent f475387d39
commit f47fa8b407
2 changed files with 423 additions and 12 deletions

View File

@@ -386,6 +386,8 @@ function createStyleDefaults() {
* @property {Array<Style>} [defaultStyle] Default style. The
* default default style is the same as Google Earth.
* @property {boolean} [writeStyles=true] Write styles into KML.
* @property {null|string} [crossOrigin='anonymous'] The `crossOrigin` attribute for loaded images. Note that you must provide a
* `crossOrigin` value if you want to access pixel data with the Canvas renderer.
*/
@@ -458,6 +460,13 @@ class KML extends XMLFeature {
this.showPointNames_ = options.showPointNames !== undefined ?
options.showPointNames : true;
/**
* @private
* @type {null|string}
*/
this.crossOrigin_ = options.crossOrigin !== undefined ?
options.crossOrigin : 'anonymous';
}
/**
@@ -494,7 +503,7 @@ class KML extends XMLFeature {
*/
readPlacemark_(node, objectStack) {
const object = pushParseAndPop({'geometry': null},
PLACEMARK_PARSERS, node, objectStack);
PLACEMARK_PARSERS, node, objectStack, this);
if (!object) {
return undefined;
}
@@ -537,7 +546,7 @@ class KML extends XMLFeature {
readSharedStyle_(node, objectStack) {
const id = node.getAttribute('id');
if (id !== null) {
const style = readStyle(node, objectStack);
const style = readStyle.call(this, node, objectStack);
if (style) {
let styleUri;
let baseURI = node.baseURI;
@@ -565,7 +574,7 @@ class KML extends XMLFeature {
if (id === null) {
return;
}
const styleMapValue = readStyleMapValue(node, objectStack);
const styleMapValue = readStyleMapValue.call(this, node, objectStack);
if (!styleMapValue) {
return;
}
@@ -1118,7 +1127,7 @@ const STYLE_MAP_PARSERS = makeStructureNS(
*/
function readStyleMapValue(node, objectStack) {
return pushParseAndPop(undefined,
STYLE_MAP_PARSERS, node, objectStack);
STYLE_MAP_PARSERS, node, objectStack, this);
}
@@ -1223,7 +1232,7 @@ function iconStyleParser(node, objectStack) {
anchorOrigin: anchorOrigin,
anchorXUnits: anchorXUnits,
anchorYUnits: anchorYUnits,
crossOrigin: 'anonymous', // FIXME should this be configurable?
crossOrigin: this.crossOrigin_,
offset: offset,
offsetOrigin: IconOrigin.BOTTOM_LEFT,
rotation: rotation,
@@ -1725,7 +1734,7 @@ const STYLE_PARSERS = makeStructureNS(
*/
function readStyle(node, objectStack) {
const styleObject = pushParseAndPop(
{}, STYLE_PARSERS, node, objectStack);
{}, STYLE_PARSERS, node, objectStack, this);
if (!styleObject) {
return null;
}
@@ -1883,7 +1892,7 @@ const PAIR_PARSERS = makeStructureNS(
*/
function pairDataParser(node, objectStack) {
const pairObject = pushParseAndPop(
{}, PAIR_PARSERS, node, objectStack);
{}, PAIR_PARSERS, node, objectStack, this);
if (!pairObject) {
return;
}
@@ -1909,7 +1918,7 @@ function pairDataParser(node, objectStack) {
* @param {Array<*>} objectStack Object stack.
*/
function placemarkStyleMapParser(node, objectStack) {
const styleMapValue = readStyleMapValue(node, objectStack);
const styleMapValue = readStyleMapValue.call(this, node, objectStack);
if (!styleMapValue) {
return;
}