Merge pull request #1063 from oterral/parsing_stylemap

Parsing styleMap (r=@bartvde)
This commit is contained in:
Bart van den Eijnden
2013-10-03 08:01:56 -07:00
5 changed files with 205 additions and 23 deletions

View File

@@ -280,6 +280,31 @@ describe('ol.parser.KML', function() {
done();
});
});
it('handles styleMap (read / write)', function(done) {
var url = 'spec/ol/parser/kml/stylemap.kml';
afterLoadXml(url, function(xml) {
var p = new ol.parser.KML({extractStyles: true});
var obj = p.read(xml);
var output = p.write(obj);
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
var symbolizers = obj.features[0].getSymbolizers();
expect(symbolizers).to.have.length(1);
var symbolizer = symbolizers[0];
expect(symbolizer).to.be.a(ol.style.Icon);
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
expect(literal).to.be.a(ol.style.IconLiteral);
var url = 'http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png';
expect(literal.url).to.eql(url);
expect(literal.width).to.eql(32);
expect(literal.height).to.eql(32);
done();
});
});
});
describe('parsing states.kml', function() {

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd">
<Document>
<Style id="pushpin">
<IconStyle id="mystyle">
<Icon>
<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
</Icon>
</IconStyle>
</Style>
<StyleMap id="pushpinStyleMap">
<Pair>
<key>normal</key>
<styleUrl>#pushpin</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#pushpin</styleUrl>
</Pair>
</StyleMap>
<Placemark>
<name>Pin on a mountaintop</name>
<styleUrl>#pushpinStyleMap</styleUrl>
<Point>
<coordinates>170.1435558771009,-43.60505741890396,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>