From 258bfeaecc688e2deef827fa9059ed96a94ab75b Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Sat, 18 Jan 2020 19:37:18 +0000 Subject: [PATCH 1/9] Make feature styles compatible with declutter Return a single style object for image and text for point features as concatenating two styles in an array is not compatible with decluttering --- src/ol/format/KML.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index 11c1ec076c..b3273fcf42 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -911,9 +911,8 @@ function createNameStyleFunction(foundStyle, name) { textStyle.setOffsetY(textOffset[1]); textStyle.setTextAlign(textAlign); - const nameStyle = new Style({ - text: textStyle - }); + const nameStyle = foundStyle.clone(); + nameStyle.setText(textStyle); return nameStyle; } @@ -932,12 +931,11 @@ function createFeatureStyleFunction(style, styleUrl, defaultStyle, sharedStyles, /** * @param {Feature} feature feature. * @param {number} resolution Resolution. - * @return {Array' + - ' ' + - ' ' + - ' normal' + - ' #sn_ylw-pushpin' + - ' ' + - ' ' + - ' highlight' + - ' #sh_ylw-pushpin' + - ' ' + - ' ' + - ' ' + - ' Test' + - ' #msn_ylw-pushpin0' + - ' ' + - ' 1,2' + - ' ' + - ' ' + - ''; - const fs = format.readFeatures(text); - expect(fs).to.have.length(1); - const f = fs[0]; - expect(f).to.be.an(Feature); - const styleFunction = f.getStyleFunction(); - expect(styleFunction).not.to.be(undefined); - const styleArray = styleFunction(f, 0); - expect(styleArray).to.be.an(Array); - expect(styleArray).to.have.length(2); - const style = styleArray[1]; + const style = styleFunction(f, 0); expect(style).to.be.an(Style); expect(style.getText().getText()).to.eql(f.getProperties()['name']); }); From 9493d682170cbed1013d15b71f5332a690db14d6 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Sat, 18 Jan 2020 20:19:56 +0000 Subject: [PATCH 3/9] Make feature styles compatible with declutter Remove type def relating to deleted line --- src/ol/format/KML.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index b3273fcf42..0c2a2b2186 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -935,7 +935,6 @@ function createFeatureStyleFunction(style, styleUrl, defaultStyle, sharedStyles, */ function(feature, resolution) { let drawName = showPointNames; - /** @type {Style|undefined} */ let name = ''; if (drawName) { const geometry = feature.getGeometry(); From 23858dc09d381c8121ca08751712748d8b710334 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Sun, 19 Jan 2020 11:28:05 +0000 Subject: [PATCH 4/9] Convert any html character codes in labels --- src/ol/format/KML.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index 0c2a2b2186..2773f53392 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -946,6 +946,12 @@ function createFeatureStyleFunction(style, styleUrl, defaultStyle, sharedStyles, if (drawName) { name = /** @type {string} */ (feature.get('name')); drawName = drawName && !!name; + // convert any html character codes + if (drawName && name.search(/&[^&]+;/) > -1) { + const text = document.createElement('textarea'); + text.innerHTML = name; + name = text.value; + } } if (style) { From bf23dca068f82d8af9968720d3a07e3bdb77da71 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Sun, 19 Jan 2020 11:42:59 +0000 Subject: [PATCH 5/9] Include html character code in text style test --- test/spec/ol/format/kml.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/ol/format/kml.test.js b/test/spec/ol/format/kml.test.js index 926327abdd..ded663c858 100644 --- a/test/spec/ol/format/kml.test.js +++ b/test/spec/ol/format/kml.test.js @@ -2238,7 +2238,7 @@ describe('ol.format.KML', function() { expect(style.getZIndex()).to.be(undefined); }); - it('can create text style for named point placemarks', function() { + it('can create text style for named point placemarks (including html character codes)', function() { const text = '' + ' ' + ' ' + - ' Test' + + ' Joe's Test' + ' #msn_ylw-pushpin0' + ' ' + ' 1,2' + @@ -2281,7 +2281,7 @@ describe('ol.format.KML', function() { expect(styleFunction).not.to.be(undefined); const style = styleFunction(f, 0); expect(style).to.be.an(Style); - expect(style.getText().getText()).to.eql(f.getProperties()['name']); + expect(style.getText().getText()).to.eql('Joe's Test'); }); it('can write an feature\'s icon style', function() { From e2b42c100fc682f3d5fb8c59e134bdc2d90e8b01 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Sun, 19 Jan 2020 12:02:16 +0000 Subject: [PATCH 6/9] Include html character code in text style test --- test/spec/ol/format/kml.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/ol/format/kml.test.js b/test/spec/ol/format/kml.test.js index ded663c858..6f4e2fe2d6 100644 --- a/test/spec/ol/format/kml.test.js +++ b/test/spec/ol/format/kml.test.js @@ -2281,7 +2281,7 @@ describe('ol.format.KML', function() { expect(styleFunction).not.to.be(undefined); const style = styleFunction(f, 0); expect(style).to.be.an(Style); - expect(style.getText().getText()).to.eql('Joe's Test'); + expect(style.getText().getText()).to.eql('Joe\'s Test'); }); it('can write an feature\'s icon style', function() { From c221cc7a46124144c26d5325337bf790001563f7 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jan 2020 10:24:57 +0000 Subject: [PATCH 7/9] Convert any html character codes in labels reuse single textarea element --- src/ol/format/KML.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index 2773f53392..e77f33afc1 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -378,6 +378,11 @@ function createStyleDefaults() { } +/** + * @type {HTMLElement} + */ +let TEXTAREA; + /** * @typedef {Object} Options @@ -948,9 +953,11 @@ function createFeatureStyleFunction(style, styleUrl, defaultStyle, sharedStyles, drawName = drawName && !!name; // convert any html character codes if (drawName && name.search(/&[^&]+;/) > -1) { - const text = document.createElement('textarea'); - text.innerHTML = name; - name = text.value; + if (!TEXTAREA) { + TEXTAREA = document.createElement('textarea'); + } + TEXTAREA.innerHTML = name; + name = TEXTAREA.value; } } From 83d65b61e16bac0880e09b016da24743cebf4bbd Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jan 2020 10:30:44 +0000 Subject: [PATCH 8/9] Convert any html character codes in labels fix typedef --- src/ol/format/KML.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index e77f33afc1..d29ef7b4f4 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -379,7 +379,7 @@ function createStyleDefaults() { } /** - * @type {HTMLElement} + * @type {Textarea} */ let TEXTAREA; From 5830a361316b06b2deb5978d639238836e55e397 Mon Sep 17 00:00:00 2001 From: mike-000 <49240900+mike-000@users.noreply.github.com> Date: Mon, 20 Jan 2020 10:37:04 +0000 Subject: [PATCH 9/9] Convert any html character codes in labels fix typedef --- src/ol/format/KML.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol/format/KML.js b/src/ol/format/KML.js index d29ef7b4f4..77dc5a7aff 100644 --- a/src/ol/format/KML.js +++ b/src/ol/format/KML.js @@ -379,7 +379,7 @@ function createStyleDefaults() { } /** - * @type {Textarea} + * @type {HTMLTextAreaElement} */ let TEXTAREA;