Optionally stroke and fill polygons (closes #475)

This also removes the unsupported width property from PolyStyle (closes #891).
This commit is contained in:
Tim Schaub
2013-08-05 11:16:32 -06:00
parent 993e76e3a1
commit 5d0b4563a8
2 changed files with 68 additions and 42 deletions

View File

@@ -185,42 +185,46 @@ describe('ol.parser.kml', function() {
expect(symbolizer.strokeOpacity).to.eql(0.5294117647058824);
expect(symbolizer.strokeWidth).to.eql(10);
});
it('Test style fill (read / write)', function() {
var test_style_fill = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
it('reads PolyStyle fill', function() {
var kml = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
'<Document><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
'<color>870000ff</color></PolyStyle> </Style>' +
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
'5.001370157823406,49.26855713824488 8.214706453896161,' +
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
'</outerBoundaryIs></Polygon></Placemark><Placemark> <Style> ' +
'<PolyStyle><fill>0</fill><color>870000ff</color><width>10</width> ' +
'<PolyStyle><fill>0</fill><color>870000ff</color>' +
'</PolyStyle> </Style>' +
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
'5.001370157823406,49.26855713824488 8.214706453896161,' +
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
var style_fill_write = '<kml xmlns="http://www.opengis.net/kml/2.2" ' +
var p = new ol.parser.KML({extractStyles: true});
var obj = p.read(kml);
var symbolizer1 = obj.features[0].getSymbolizerLiterals()[0];
var symbolizer2 = obj.features[1].getSymbolizerLiterals()[0];
expect(symbolizer1.strokeColor).to.be('#ff0000');
expect(symbolizer2.fillOpacity).to.be(undefined);
});
it('writes PolyStyle fill and outline', function() {
var kml = '<kml xmlns="http://www.opengis.net/kml/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><Placemark> <Style> <PolyStyle> <fill>1</fill> ' +
'<color>870000ff</color> <width>10</width> </PolyStyle> </Style>' +
'<Document><Placemark><Style><PolyStyle>' +
'<fill>1</fill><outline>0</outline>' +
'<color>870000ff</color></PolyStyle> </Style>' +
'<Polygon><outerBoundaryIs><LinearRing><coordinates>' +
'5.001370157823406,49.26855713824488 8.214706453896161,' +
'49.630662409673505 8.397385910100951,48.45172350357396 ' +
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
'</outerBoundaryIs></Polygon></Placemark></Document></kml>';
var p = new ol.parser.KML({extractStyles: true});
var obj = p.read(test_style_fill);
var output = p.write(p.read(style_fill_write));
expect(goog.dom.xml.loadXml(style_fill_write)).to.xmleql(
var output = p.write(p.read(kml));
expect(goog.dom.xml.loadXml(kml)).to.xmleql(
goog.dom.xml.loadXml(output));
var symbolizer1 = obj.features[0].getSymbolizerLiterals()[0];
var symbolizer2 = obj.features[1].getSymbolizerLiterals()[0];
expect(symbolizer1.fillColor).to.eql('#ff0000');
expect(symbolizer2.opacity).to.eql(0);
});
it('Test iconStyle (read / write)', function(done) {
var url = 'spec/ol/parser/kml/iconstyle.kml';