Set constants of KML format even if a default style is provided
This commit is contained in:
@@ -51,6 +51,10 @@ ol.format.KML = function(opt_options) {
|
|||||||
|
|
||||||
ol.format.XMLFeature.call(this);
|
ol.format.XMLFeature.call(this);
|
||||||
|
|
||||||
|
if (!ol.format.KML.DEFAULT_STYLE_ARRAY_) {
|
||||||
|
ol.format.KML.createStyleDefaults_();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -61,8 +65,7 @@ ol.format.KML = function(opt_options) {
|
|||||||
* @type {Array.<ol.style.Style>}
|
* @type {Array.<ol.style.Style>}
|
||||||
*/
|
*/
|
||||||
this.defaultStyle_ = options.defaultStyle ?
|
this.defaultStyle_ = options.defaultStyle ?
|
||||||
options.defaultStyle :
|
options.defaultStyle : ol.format.KML.DEFAULT_STYLE_ARRAY_;
|
||||||
(ol.format.KML.DEFAULT_STYLE_ARRAY_ || ol.format.KML.createStyleDefaults_());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
@@ -26,10 +26,56 @@ goog.require('ol.xml');
|
|||||||
describe('ol.format.KML', function() {
|
describe('ol.format.KML', function() {
|
||||||
|
|
||||||
var format;
|
var format;
|
||||||
|
|
||||||
|
describe('using defaultStyle', function() {
|
||||||
|
|
||||||
|
var dfltStyle = new ol.style.Style();
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
format = new ol.format.KML({
|
||||||
|
defaultStyle: [dfltStyle]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('set constant variables', function() {
|
||||||
|
expect(ol.format.KML.DEFAULT_STYLE_ARRAY_).to.be.an(Array);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#readFeatures', function() {
|
||||||
|
|
||||||
|
it('can apply a default style to a feature', function() {
|
||||||
|
var text =
|
||||||
|
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
||||||
|
' <Document>' +
|
||||||
|
' <Placemark/>' +
|
||||||
|
' </Document>' +
|
||||||
|
'</kml>';
|
||||||
|
var fs = format.readFeatures(text);
|
||||||
|
expect(fs).to.have.length(1);
|
||||||
|
var f = fs[0];
|
||||||
|
expect(f).to.be.an(ol.Feature);
|
||||||
|
var styleFunction = f.getStyleFunction();
|
||||||
|
expect(styleFunction).not.to.be(undefined);
|
||||||
|
var styleArray = styleFunction.call(f, 0);
|
||||||
|
expect(styleArray).to.be.an(Array);
|
||||||
|
expect(styleArray).to.have.length(1);
|
||||||
|
var style = styleArray[0];
|
||||||
|
expect(style).to.be.an(ol.style.Style);
|
||||||
|
expect(style).to.be(dfltStyle);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('without parameters', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
format = new ol.format.KML();
|
format = new ol.format.KML();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('set constant variables', function() {
|
||||||
|
expect(ol.format.KML.DEFAULT_STYLE_ARRAY_).to.be.an(Array);
|
||||||
|
});
|
||||||
|
|
||||||
describe('#readProjection', function() {
|
describe('#readProjection', function() {
|
||||||
it('returns the default projection from document', function() {
|
it('returns the default projection from document', function() {
|
||||||
var projection = format.readProjectionFromDocument();
|
var projection = format.readProjectionFromDocument();
|
||||||
@@ -2887,5 +2933,5 @@ describe('ol.format.KML', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user