Merge pull request #1607 from oterral/kml_crossorigin

Lets ol.style.Icon to define default values
This commit is contained in:
Tom Payne
2014-01-28 04:45:42 -08:00
2 changed files with 40 additions and 6 deletions

View File

@@ -476,25 +476,22 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
anchor = [0.5, 1];
anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
} else {
anchor = null;
}
var rotation;
var heading = /** @type {number|undefined} */
(goog.object.get(object, 'heading'));
if (goog.isDef(heading)) {
rotation = goog.math.toRadians(heading);
} else {
rotation = 0;
}
var scale = /** @type {number|undefined} */
(goog.object.get(object, 'scale'));
var size;
if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
} else {
size = null;
}
var imageStyle = new ol.style.Icon({
anchor: anchor,
anchorXUnits: anchorXUnits,

View File

@@ -526,6 +526,42 @@ describe('ol.format.KML', function() {
expect(style.getStroke().getWidth()).to.be(1);
});
it('can read a feature\'s IconStyle', function() {
var text =
'<kml xmlns="http://earth.google.com/kml/2.2">' +
' <Placemark>' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>http://foo.png</href>' +
' </Icon>' +
' </IconStyle>' +
' </Style>' +
' </Placemark>' +
'</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.getFill()).to.be(ol.format.KML.DEFAULT_FILL_STYLE_);
expect(style.getStroke()).to.be(ol.format.KML.DEFAULT_STROKE_STYLE_);
var imageStyle = style.getImage();
expect(imageStyle).to.be.an(ol.style.Icon);
expect(imageStyle.getSrc()).to.eql('http://foo.png');
expect(imageStyle.getAnchor()).to.eql([0.5, 0.5]);
expect(imageStyle.getRotation()).to.eql(0);
expect(imageStyle.getSize()).to.be(null);
expect(style.getText()).to.be(null);
expect(style.getZIndex()).to.be(undefined);
});
it('can read a feature\'s LineStyle', function() {
var text =
'<kml xmlns="http://earth.google.com/kml/2.2">' +
@@ -1440,5 +1476,6 @@ goog.require('ol.geom.MultiPolygon');
goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
goog.require('ol.style.Fill');
goog.require('ol.style.Icon');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');