Merge pull request #5587 from ahocevar/kml-faster-init
Lazily create KML style defaults
This commit is contained in:
+10
-14
@@ -67,7 +67,8 @@ ol.format.KML = function(opt_options) {
|
||||
* @type {Array.<ol.style.Style>}
|
||||
*/
|
||||
this.defaultStyle_ = options.defaultStyle ?
|
||||
options.defaultStyle : ol.format.KML.DEFAULT_STYLE_ARRAY_;
|
||||
options.defaultStyle :
|
||||
(ol.format.KML.DEFAULT_STYLE_ARRAY_ || ol.format.KML.createStyleDefaults_());
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -141,6 +142,11 @@ ol.format.KML.SCHEMA_LOCATION_ = 'http://www.opengis.net/kml/2.2 ' +
|
||||
'https://developers.google.com/kml/schema/kml22gx.xsd';
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.style.Style>} Default style.
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.createStyleDefaults_ = function() {
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.Color}
|
||||
@@ -148,7 +154,6 @@ ol.format.KML.SCHEMA_LOCATION_ = 'http://www.opengis.net/kml/2.2 ' +
|
||||
*/
|
||||
ol.format.KML.DEFAULT_COLOR_ = [255, 255, 255, 1];
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Fill}
|
||||
@@ -158,7 +163,6 @@ ol.format.KML.DEFAULT_FILL_STYLE_ = new ol.style.Fill({
|
||||
color: ol.format.KML.DEFAULT_COLOR_
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.Size}
|
||||
@@ -166,7 +170,6 @@ ol.format.KML.DEFAULT_FILL_STYLE_ = new ol.style.Fill({
|
||||
*/
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_ = [20, 2]; // FIXME maybe [8, 32] ?
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.IconAnchorUnits}
|
||||
@@ -175,7 +178,6 @@ ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_ = [20, 2]; // FIXME maybe [8, 32] ?
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ =
|
||||
ol.style.IconAnchorUnits.PIXELS;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.IconAnchorUnits}
|
||||
@@ -184,7 +186,6 @@ ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ =
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ =
|
||||
ol.style.IconAnchorUnits.PIXELS;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.Size}
|
||||
@@ -192,7 +193,6 @@ ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ =
|
||||
*/
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_ = [64, 64];
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {string}
|
||||
@@ -201,7 +201,6 @@ ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_ = [64, 64];
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_ =
|
||||
'https://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {number}
|
||||
@@ -209,7 +208,6 @@ ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_ =
|
||||
*/
|
||||
ol.format.KML.DEFAULT_IMAGE_SCALE_MULTIPLIER_ = 0.5;
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Image}
|
||||
@@ -227,7 +225,6 @@ ol.format.KML.DEFAULT_IMAGE_STYLE_ = new ol.style.Icon({
|
||||
src: ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Stroke}
|
||||
@@ -238,7 +235,6 @@ ol.format.KML.DEFAULT_STROKE_STYLE_ = new ol.style.Stroke({
|
||||
width: 1
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Stroke}
|
||||
@@ -249,7 +245,6 @@ ol.format.KML.DEFAULT_TEXT_STROKE_STYLE_ = new ol.style.Stroke({
|
||||
width: 2
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Text}
|
||||
@@ -262,7 +257,6 @@ ol.format.KML.DEFAULT_TEXT_STYLE_ = new ol.style.Text({
|
||||
scale: 0.8
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Style}
|
||||
@@ -276,7 +270,6 @@ ol.format.KML.DEFAULT_STYLE_ = new ol.style.Style({
|
||||
zIndex: 0
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Array.<ol.style.Style>}
|
||||
@@ -284,6 +277,9 @@ ol.format.KML.DEFAULT_STYLE_ = new ol.style.Style({
|
||||
*/
|
||||
ol.format.KML.DEFAULT_STYLE_ARRAY_ = [ol.format.KML.DEFAULT_STYLE_];
|
||||
|
||||
return ol.format.KML.DEFAULT_STYLE_ARRAY_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
|
||||
Reference in New Issue
Block a user