Merge pull request #1607 from oterral/kml_crossorigin
Lets ol.style.Icon to define default values
This commit is contained in:
@@ -476,25 +476,22 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
|
|||||||
anchor = [0.5, 1];
|
anchor = [0.5, 1];
|
||||||
anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
|
anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
|
||||||
anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
|
anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
|
||||||
} else {
|
|
||||||
anchor = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var rotation;
|
var rotation;
|
||||||
var heading = /** @type {number|undefined} */
|
var heading = /** @type {number|undefined} */
|
||||||
(goog.object.get(object, 'heading'));
|
(goog.object.get(object, 'heading'));
|
||||||
if (goog.isDef(heading)) {
|
if (goog.isDef(heading)) {
|
||||||
rotation = goog.math.toRadians(heading);
|
rotation = goog.math.toRadians(heading);
|
||||||
} else {
|
|
||||||
rotation = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var scale = /** @type {number|undefined} */
|
var scale = /** @type {number|undefined} */
|
||||||
(goog.object.get(object, 'scale'));
|
(goog.object.get(object, 'scale'));
|
||||||
var size;
|
var size;
|
||||||
if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
|
if (src == ol.format.KML.DEFAULT_IMAGE_STYLE_SRC_) {
|
||||||
size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
|
size = ol.format.KML.DEFAULT_IMAGE_STYLE_SIZE_;
|
||||||
} else {
|
|
||||||
size = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var imageStyle = new ol.style.Icon({
|
var imageStyle = new ol.style.Icon({
|
||||||
anchor: anchor,
|
anchor: anchor,
|
||||||
anchorXUnits: anchorXUnits,
|
anchorXUnits: anchorXUnits,
|
||||||
|
|||||||
@@ -526,6 +526,42 @@ describe('ol.format.KML', function() {
|
|||||||
expect(style.getStroke().getWidth()).to.be(1);
|
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() {
|
it('can read a feature\'s LineStyle', function() {
|
||||||
var text =
|
var text =
|
||||||
'<kml xmlns="http://earth.google.com/kml/2.2">' +
|
'<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.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.style.Fill');
|
goog.require('ol.style.Fill');
|
||||||
|
goog.require('ol.style.Icon');
|
||||||
goog.require('ol.style.Stroke');
|
goog.require('ol.style.Stroke');
|
||||||
goog.require('ol.style.Style');
|
goog.require('ol.style.Style');
|
||||||
|
|||||||
Reference in New Issue
Block a user