Remove label style caches

This commit is contained in:
mike-000
2019-10-22 12:04:06 +01:00
committed by GitHub
parent 7edd10d66f
commit 110c17cf9e
+34 -40
View File
@@ -318,10 +318,23 @@ class Graticule extends VectorLayer {
options.latLabelPosition; options.latLabelPosition;
/** /**
* @type {Object.<string,Style>} * @type {Style}
* @private * @private
*/ */
this.lonLabelStyleCache_ = {}; this.lonLabelStyleBase_ = new Style({
text: options.lonLabelStyle !== undefined ? options.lonLabelStyle.clone() :
new Text({
font: '12px Calibri,sans-serif',
textBaseline: 'bottom',
fill: new Fill({
color: 'rgba(0,0,0,1)'
}),
stroke: new Stroke({
color: 'rgba(255,255,255,1)',
width: 3
})
})
});
/** /**
* @private * @private
@@ -330,31 +343,28 @@ class Graticule extends VectorLayer {
*/ */
this.lonLabelStyle_ = function(feature) { this.lonLabelStyle_ = function(feature) {
const label = feature.get('graticule_label'); const label = feature.get('graticule_label');
if (!this.lonLabelStyleCache_[label]) { this.lonLabelStyleBase_.getText().setText(label);
this.lonLabelStyleCache_[label] = new Style({ return this.lonLabelStyleBase_;
text: options.lonLabelStyle !== undefined ? options.lonLabelStyle.clone() :
new Text({
font: '12px Calibri,sans-serif',
textBaseline: 'bottom',
fill: new Fill({
color: 'rgba(0,0,0,1)'
}),
stroke: new Stroke({
color: 'rgba(255,255,255,1)',
width: 3
})
})
});
this.lonLabelStyleCache_[label].getText().setText(label);
}
return this.lonLabelStyleCache_[label];
}.bind(this); }.bind(this);
/** /**
* @type {Object.<string,Style>} * @type {Style}
* @private * @private
*/ */
this.latLabelStyleCache_ = {}; this.latLabelStyleBase_ = new Style({
text: options.latLabelStyle !== undefined ? options.latLabelStyle.clone() :
new Text({
font: '12px Calibri,sans-serif',
textAlign: 'right',
fill: new Fill({
color: 'rgba(0,0,0,1)'
}),
stroke: new Stroke({
color: 'rgba(255,255,255,1)',
width: 3
})
})
});
/** /**
* @private * @private
@@ -363,24 +373,8 @@ class Graticule extends VectorLayer {
*/ */
this.latLabelStyle_ = function(feature) { this.latLabelStyle_ = function(feature) {
const label = feature.get('graticule_label'); const label = feature.get('graticule_label');
if (!this.latLabelStyleCache_[label]) { this.latLabelStyleBase_.getText().setText(label);
this.latLabelStyleCache_[label] = new Style({ return this.latLabelStyleBase_;
text: options.latLabelStyle !== undefined ? options.latLabelStyle.clone() :
new Text({
font: '12px Calibri,sans-serif',
textAlign: 'right',
fill: new Fill({
color: 'rgba(0,0,0,1)'
}),
stroke: new Stroke({
color: 'rgba(255,255,255,1)',
width: 3
})
})
});
this.latLabelStyleCache_[label].getText().setText(label);
}
return this.latLabelStyleCache_[label];
}.bind(this); }.bind(this);
this.meridiansLabels_ = []; this.meridiansLabels_ = [];