Merge pull request #6556 from KlausBenndorf/kmlinsetpixel

Reading kml xunits/yunits insetPixels
This commit is contained in:
Bart van den Eijnden
2017-05-08 11:02:19 +02:00
committed by GitHub
3 changed files with 128 additions and 4 deletions

View File

@@ -1713,6 +1713,111 @@ describe('ol.format.KML', function() {
expect(style.getZIndex()).to.be(undefined);
});
it('can read a IconStyle\'s hotspot', function() {
var text =
'<kml xmlns="http://earth.google.com/kml/2.2">' +
' <Placemark id="1">' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>http://foo.png</href>' +
' </Icon>' +
' <hotSpot x="0.5" xunits="fraction" y="0.5" yunits="fraction" />' +
' </IconStyle>' +
' </Style>' +
' </Placemark>' +
' <Placemark id="2">' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>http://foo.png</href>' +
' </Icon>' +
' <hotSpot x="5" xunits="pixels" y="5" yunits="pixels" />' +
' </IconStyle>' +
' </Style>' +
' </Placemark>' +
' <Placemark id="3">' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>http://foo.png</href>' +
' </Icon>' +
' <hotSpot x="5" xunits="insetPixels" y="5" yunits="pixels" />' +
' </IconStyle>' +
' </Style>' +
' </Placemark>' +
' <Placemark id="4">' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>http://foo.png</href>' +
' </Icon>' +
' <hotSpot x="5" xunits="pixels" y="5" yunits="insetPixels" />' +
' </IconStyle>' +
' </Style>' +
' </Placemark>' +
' <Placemark id="5">' +
' <Style>' +
' <IconStyle>' +
' <Icon>' +
' <href>http://foo.png</href>' +
' </Icon>' +
' <hotSpot x="5" xunits="insetPixels" y="5" yunits="insetPixels" />' +
' </IconStyle>' +
' </Style>' +
' </Placemark>' +
'</kml>';
var fs = format.readFeatures(text);
expect(fs).to.have.length(5);
fs.forEach(function(f) {
expect(f).to.be.an(ol.Feature);
expect(f.getId()).to.be.within(1, 5);
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(new URL(imageStyle.getSrc()).href).to.eql(new URL('http://foo.png').href);
expect(imageStyle.anchor_).to.be.an(Array);
expect(imageStyle.anchor_).to.have.length(2);
if (f.getId() == 1) {
expect(imageStyle.anchor_[0]).to.be(0.5);
expect(imageStyle.anchor_[1]).to.be(0.5);
expect(imageStyle.anchorOrigin_).to.be(ol.style.IconOrigin.BOTTOM_LEFT);
expect(imageStyle.anchorXUnits_).to.be(ol.style.IconAnchorUnits.FRACTION);
expect(imageStyle.anchorYUnits_).to.be(ol.style.IconAnchorUnits.FRACTION);
} else {
expect(imageStyle.anchor_[0]).to.be(5);
expect(imageStyle.anchor_[1]).to.be(5);
expect(imageStyle.anchorXUnits_).to.be(ol.style.IconAnchorUnits.PIXELS);
expect(imageStyle.anchorYUnits_).to.be(ol.style.IconAnchorUnits.PIXELS);
if (f.getId() == 2) {
expect(imageStyle.anchorOrigin_).to.be(ol.style.IconOrigin.BOTTOM_LEFT);
}
if (f.getId() == 3) {
expect(imageStyle.anchorOrigin_).to.be(ol.style.IconOrigin.BOTTOM_RIGHT);
}
if (f.getId() == 4) {
expect(imageStyle.anchorOrigin_).to.be(ol.style.IconOrigin.TOP_LEFT);
}
if (f.getId() == 5) {
expect(imageStyle.anchorOrigin_).to.be(ol.style.IconOrigin.TOP_RIGHT);
}
}
expect(imageStyle.getRotation()).to.eql(0);
expect(imageStyle.getSize()).to.be(null);
expect(imageStyle.getScale()).to.be(1);
expect(style.getText()).to.be(ol.format.KML.DEFAULT_TEXT_STYLE_);
expect(style.getZIndex()).to.be(undefined);
});
});
it('can read a complex feature\'s IconStyle', function() {
var text =
'<kml xmlns="http://earth.google.com/kml/2.2"' +