use goog.global, restructure to have ol.parser.KML instead of ol.parser.ogc.KML

This commit is contained in:
Bart van den Eijnden
2013-04-10 10:17:28 +02:00
parent 577ebd6abe
commit 8cc70f35d9
18 changed files with 47 additions and 46 deletions
+2 -2
View File
@@ -4,7 +4,7 @@ goog.require('ol.RendererHint');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.layer.TileLayer'); goog.require('ol.layer.TileLayer');
goog.require('ol.layer.Vector'); goog.require('ol.layer.Vector');
goog.require('ol.parser.ogc.KML'); goog.require('ol.parser.KML');
goog.require('ol.projection'); goog.require('ol.projection');
goog.require('ol.source.TiledWMS'); goog.require('ol.source.TiledWMS');
goog.require('ol.source.Vector'); goog.require('ol.source.Vector');
@@ -40,7 +40,7 @@ var map = new ol.Map({
}) })
}); });
var kml = new ol.parser.ogc.KML({ var kml = new ol.parser.KML({
maxDepth: 1, dimension: 2, extractStyles: true, extractAttributes: true}); maxDepth: 1, dimension: 2, extractStyles: true, extractAttributes: true});
$.ajax({ $.ajax({
+3
View File
@@ -0,0 +1,3 @@
@exportSymbol ol.parser.KML
@exportProperty ol.parser.KML.prototype.read
@exportProperty ol.parser.KML.prototype.write
@@ -1,4 +1,4 @@
goog.provide('ol.parser.ogc.KML'); goog.provide('ol.parser.KML');
goog.require('goog.array'); goog.require('goog.array');
goog.require('goog.async.Deferred'); goog.require('goog.async.Deferred');
goog.require('goog.async.DeferredList'); goog.require('goog.async.DeferredList');
@@ -38,7 +38,7 @@ goog.require('ol.style.PolygonLiteral');
* dimension: (number|undefined), * dimension: (number|undefined),
* maxDepth: (number|undefined)}} * maxDepth: (number|undefined)}}
*/ */
ol.parser.ogc.KMLOptions; ol.parser.KMLOptions;
@@ -47,10 +47,10 @@ ol.parser.ogc.KMLOptions;
* @implements {ol.parser.DomFeatureParser} * @implements {ol.parser.DomFeatureParser}
* @implements {ol.parser.StringFeatureParser} * @implements {ol.parser.StringFeatureParser}
* @implements {ol.parser.AsyncObjectFeatureParser} * @implements {ol.parser.AsyncObjectFeatureParser}
* @param {ol.parser.ogc.KMLOptions=} opt_options Optional configuration object. * @param {ol.parser.KMLOptions=} opt_options Optional configuration object.
* @extends {ol.parser.XML} * @extends {ol.parser.XML}
*/ */
ol.parser.ogc.KML = function(opt_options) { ol.parser.KML = function(opt_options) {
if (goog.isDef(opt_options)) { if (goog.isDef(opt_options)) {
goog.object.extend(this, opt_options); goog.object.extend(this, opt_options);
} }
@@ -802,7 +802,7 @@ ol.parser.ogc.KML = function(opt_options) {
straightBracket: (/\$\[(.*?)\]/g) straightBracket: (/\$\[(.*?)\]/g)
}); });
}; };
goog.inherits(ol.parser.ogc.KML, ol.parser.XML); goog.inherits(ol.parser.KML, ol.parser.XML);
/** /**
@@ -811,7 +811,7 @@ goog.inherits(ol.parser.ogc.KML, ol.parser.XML);
* after parsing. * after parsing.
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options. * @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
*/ */
ol.parser.ogc.KML.prototype.readFeaturesFromObjectAsync = ol.parser.KML.prototype.readFeaturesFromObjectAsync =
function(obj, callback, opt_options) { function(obj, callback, opt_options) {
this.readFeaturesOptions_ = opt_options; this.readFeaturesOptions_ = opt_options;
this.read(obj, callback); this.read(obj, callback);
@@ -824,7 +824,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromObjectAsync =
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options. * @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
* @return {Array.<ol.Feature>} Array of features. * @return {Array.<ol.Feature>} Array of features.
*/ */
ol.parser.ogc.KML.prototype.readFeaturesFromString = ol.parser.KML.prototype.readFeaturesFromString =
function(str, opt_options) { function(str, opt_options) {
this.readFeaturesOptions_ = opt_options; this.readFeaturesOptions_ = opt_options;
return this.read(str).features; return this.read(str).features;
@@ -837,7 +837,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromString =
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options. * @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
* @return {Array.<ol.Feature>} Array of features. * @return {Array.<ol.Feature>} Array of features.
*/ */
ol.parser.ogc.KML.prototype.readFeaturesFromNode = ol.parser.KML.prototype.readFeaturesFromNode =
function(node, opt_options) { function(node, opt_options) {
this.readFeaturesOptions_ = opt_options; this.readFeaturesOptions_ = opt_options;
return this.read(node).features; return this.read(node).features;
@@ -849,7 +849,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromNode =
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options. * @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
* @return {Array.<ol.Feature>} Array of features. * @return {Array.<ol.Feature>} Array of features.
*/ */
ol.parser.ogc.KML.prototype.readFeaturesFromObject = ol.parser.KML.prototype.readFeaturesFromObject =
function(obj, opt_options) { function(obj, opt_options) {
this.readFeaturesOptions_ = opt_options; this.readFeaturesOptions_ = opt_options;
return this.read(obj).features; return this.read(obj).features;
@@ -861,7 +861,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromObject =
* @param {Object} obj The returned object from the parser. * @param {Object} obj The returned object from the parser.
* @param {Function} done A callback for when all links have been retrieved. * @param {Function} done A callback for when all links have been retrieved.
*/ */
ol.parser.ogc.KML.prototype.parseLinks = function(deferreds, obj, done) { ol.parser.KML.prototype.parseLinks = function(deferreds, obj, done) {
var unvisited; var unvisited;
if (this.depth_ < this.maxDepth) { if (this.depth_ < this.maxDepth) {
this.depth_++; this.depth_++;
@@ -875,6 +875,7 @@ ol.parser.ogc.KML.prototype.parseLinks = function(deferreds, obj, done) {
goog.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) { goog.events.listen(xhr, goog.net.EventType.COMPLETE, function(e) {
if (e.target.isSuccess()) { if (e.target.isSuccess()) {
var data = e.target.getResponseXml(); var data = e.target.getResponseXml();
e.target.dispose();
if (data && data.nodeType == 9) { if (data && data.nodeType == 9) {
data = data.documentElement; data = data.documentElement;
} }
@@ -901,7 +902,7 @@ ol.parser.ogc.KML.prototype.parseLinks = function(deferreds, obj, done) {
* is done. * is done.
* @return {Object} An object representing the document. * @return {Object} An object representing the document.
*/ */
ol.parser.ogc.KML.prototype.read = function(data, opt_callback) { ol.parser.KML.prototype.read = function(data, opt_callback) {
if (typeof data == 'string') { if (typeof data == 'string') {
data = goog.dom.xml.loadXml(data); data = goog.dom.xml.loadXml(data);
} }
@@ -940,7 +941,7 @@ ol.parser.ogc.KML.prototype.read = function(data, opt_callback) {
* @param {Array} styles The style list to search in. * @param {Array} styles The style list to search in.
* @param {Array=} opt_symbolizers Optional symbolizers. * @param {Array=} opt_symbolizers Optional symbolizers.
*/ */
ol.parser.ogc.KML.prototype.applyStyle_ = function(feature, styles, ol.parser.KML.prototype.applyStyle_ = function(feature, styles,
opt_symbolizers) { opt_symbolizers) {
var symbolizers = opt_symbolizers; var symbolizers = opt_symbolizers;
var i, ii; var i, ii;
@@ -978,7 +979,7 @@ ol.parser.ogc.KML.prototype.applyStyle_ = function(feature, styles,
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices. * @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
* @return {ol.geom.Geometry} The geometry created. * @return {ol.geom.Geometry} The geometry created.
*/ */
ol.parser.ogc.KML.prototype.createGeometry_ = function(container, ol.parser.KML.prototype.createGeometry_ = function(container,
opt_vertices) { opt_vertices) {
var geometry = null, coordinates, i, ii; var geometry = null, coordinates, i, ii;
switch (container.geometry.type) { switch (container.geometry.type) {
@@ -1035,7 +1036,7 @@ ol.parser.ogc.KML.prototype.createGeometry_ = function(container,
* @param {Object} obj Object structure to write out as XML. * @param {Object} obj Object structure to write out as XML.
* @return {string} An string representing the XML document. * @return {string} An string representing the XML document.
*/ */
ol.parser.ogc.KML.prototype.write = function(obj) { ol.parser.KML.prototype.write = function(obj) {
var root = this.writeNode('kml', obj); var root = this.writeNode('kml', obj);
return goog.dom.xml.serialize(root); return goog.dom.xml.serialize(root);
}; };
-3
View File
@@ -1,3 +0,0 @@
@exportSymbol ol.parser.ogc.KML
@exportProperty ol.parser.ogc.KML.prototype.read
@exportProperty ol.parser.ogc.KML.prototype.write
+1 -1
View File
@@ -9,7 +9,7 @@ goog.require('ol.parser.Parser');
* @extends {ol.parser.Parser} * @extends {ol.parser.Parser}
*/ */
ol.parser.XML = function() { ol.parser.XML = function() {
if (window.ActiveXObject) { if (goog.global.ActiveXObject) {
this.xmldom = new ActiveXObject('Microsoft.XMLDOM'); this.xmldom = new ActiveXObject('Microsoft.XMLDOM');
} }
this.regExes = { this.regExes = {
@@ -1,12 +1,12 @@
goog.provide('ol.test.parser.ogc.kml'); goog.provide('ol.test.parser.kml');
describe('ol.parser.kml', function() { describe('ol.parser.kml', function() {
var parser = new ol.parser.ogc.KML(); var parser = new ol.parser.KML();
describe('Test KML parser', function() { describe('Test KML parser', function() {
it('Polygon read correctly', function() { it('Polygon read correctly', function() {
var url = 'spec/ol/parser/ogc/xml/kml_polygon.kml'; var url = 'spec/ol/parser/kml/polygon.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
var output = parser.write(obj); var output = parser.write(obj);
@@ -33,7 +33,7 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Linestring read correctly', function() { it('Linestring read correctly', function() {
var url = 'spec/ol/parser/ogc/xml/kml_linestring.kml'; var url = 'spec/ol/parser/kml/linestring.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
var output = parser.write(obj); var output = parser.write(obj);
@@ -54,7 +54,7 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Point read correctly', function() { it('Point read correctly', function() {
var url = 'spec/ol/parser/ogc/xml/kml_point.kml'; var url = 'spec/ol/parser/kml/point.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
var output = parser.write(obj); var output = parser.write(obj);
@@ -72,9 +72,9 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('NetworkLink read correctly', function(done) { it('NetworkLink read correctly', function(done) {
var url = 'spec/ol/parser/ogc/xml/kml_networklink.kml'; var url = 'spec/ol/parser/kml/networklink.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var p = new ol.parser.ogc.KML({maxDepth: 1}); var p = new ol.parser.KML({maxDepth: 1});
// we need to supply a callback to get visited NetworkLinks // we need to supply a callback to get visited NetworkLinks
var obj = p.read(xml, function(features) { var obj = p.read(xml, function(features) {
expect(features.length).to.eql(3); expect(features.length).to.eql(3);
@@ -83,9 +83,9 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('NetworkLink read correctly [recursively]', function(done) { it('NetworkLink read correctly [recursively]', function(done) {
var url = 'spec/ol/parser/ogc/xml/kml_networklink_depth.kml'; var url = 'spec/ol/parser/kml/networklink_depth.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var p = new ol.parser.ogc.KML({maxDepth: 2}); var p = new ol.parser.KML({maxDepth: 2});
// we need to supply a callback to get visited NetworkLinks // we need to supply a callback to get visited NetworkLinks
var obj = p.read(xml, function(features) { var obj = p.read(xml, function(features) {
expect(features.length).to.eql(2); expect(features.length).to.eql(2);
@@ -94,9 +94,9 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('NetworkLink maxDepth', function(done) { it('NetworkLink maxDepth', function(done) {
var url = 'spec/ol/parser/ogc/xml/kml_networklink_depth.kml'; var url = 'spec/ol/parser/kml/networklink_depth.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var p = new ol.parser.ogc.KML({maxDepth: 1}); var p = new ol.parser.KML({maxDepth: 1});
// we need to supply a callback to get visited NetworkLinks // we need to supply a callback to get visited NetworkLinks
var obj = p.read(xml, function(features) { var obj = p.read(xml, function(features) {
// since maxDepth is 1, we will not get to the second feature // since maxDepth is 1, we will not get to the second feature
@@ -106,7 +106,7 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Extended data read correctly', function() { it('Extended data read correctly', function() {
var url = 'spec/ol/parser/ogc/xml/kml_extended_data.kml'; var url = 'spec/ol/parser/kml/extended_data.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
expect(obj.features[0].get('name')).to.eql('Extended data placemark'); expect(obj.features[0].get('name')).to.eql('Extended data placemark');
@@ -117,7 +117,7 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Extended data read correctly [2]', function() { it('Extended data read correctly [2]', function() {
var url = 'spec/ol/parser/ogc/xml/kml_extended_data2.kml'; var url = 'spec/ol/parser/kml/extended_data2.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
var feature = obj.features[0]; var feature = obj.features[0];
@@ -127,7 +127,7 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Multi geometry read correctly', function() { it('Multi geometry read correctly', function() {
var url = 'spec/ol/parser/ogc/xml/kml_multigeometry.kml'; var url = 'spec/ol/parser/kml/multigeometry.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
var geom = obj.features[0].getGeometry(); var geom = obj.features[0].getGeometry();
@@ -146,7 +146,7 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Discrete multi geometry read correctly', function() { it('Discrete multi geometry read correctly', function() {
var url = 'spec/ol/parser/ogc/xml/kml_multigeometry_discrete.kml'; var url = 'spec/ol/parser/kml/multigeometry_discrete.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var obj = parser.read(xml); var obj = parser.read(xml);
var geom = obj.features[0].getGeometry(); var geom = obj.features[0].getGeometry();
@@ -157,9 +157,9 @@ describe('ol.parser.kml', function() {
}); });
}); });
it('Test extract tracks', function() { it('Test extract tracks', function() {
var url = 'spec/ol/parser/ogc/xml/kml_macnoise.kml'; var url = 'spec/ol/parser/kml/macnoise.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var p = new ol.parser.ogc.KML({extractStyles: true, var p = new ol.parser.KML({extractStyles: true,
trackAttributes: ['speed', 'num']}); trackAttributes: ['speed', 'num']});
var obj = p.read(xml); var obj = p.read(xml);
expect(obj.features.length).to.eql(170); expect(obj.features.length).to.eql(170);
@@ -198,7 +198,7 @@ describe('ol.parser.kml', function() {
'<width>10</width> </LineStyle> </Style> <LineString> ' + '<width>10</width> </LineStyle> </Style> <LineString> ' +
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' + '<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
'</Placemark></kml>'; '</Placemark></kml>';
var p = new ol.parser.ogc.KML({extractStyles: true}); var p = new ol.parser.KML({extractStyles: true});
var obj = p.read(test_style); var obj = p.read(test_style);
var output = p.write(obj); var output = p.write(obj);
var expected = '<kml xmlns="http://www.opengis.net/kml/2.2">' + var expected = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
@@ -229,7 +229,7 @@ describe('ol.parser.kml', function() {
'49.630662409673505 8.397385910100951,48.45172350357396 ' + '49.630662409673505 8.397385910100951,48.45172350357396 ' +
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' + '5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
'</outerBoundaryIs></Polygon></Placemark></kml>'; '</outerBoundaryIs></Polygon></Placemark></kml>';
var p = new ol.parser.ogc.KML({extractStyles: true}); var p = new ol.parser.KML({extractStyles: true});
var obj = p.read(test_style_fill); var obj = p.read(test_style_fill);
var output = p.write(obj); var output = p.write(obj);
var expected = '<kml xmlns="http://www.opengis.net/kml/2.2"><Document>' + var expected = '<kml xmlns="http://www.opengis.net/kml/2.2"><Document>' +
@@ -253,9 +253,9 @@ describe('ol.parser.kml', function() {
expect(symbolizer2.opacity).to.eql(0); expect(symbolizer2.opacity).to.eql(0);
}); });
it('Test iconStyle', function() { it('Test iconStyle', function() {
var url = 'spec/ol/parser/ogc/xml/kml_iconstyle.kml'; var url = 'spec/ol/parser/kml/iconstyle.kml';
afterLoadXml(url, function(xml) { afterLoadXml(url, function(xml) {
var p = new ol.parser.ogc.KML({extractStyles: true}); var p = new ol.parser.KML({extractStyles: true});
var obj = p.read(xml); var obj = p.read(xml);
var output = p.write(obj); var output = p.write(obj);
var expected = '<kml xmlns="http://www.opengis.net/kml/2.2">' + var expected = '<kml xmlns="http://www.opengis.net/kml/2.2">' +
@@ -285,5 +285,5 @@ goog.require('ol.geom.LineString');
goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.MultiLineString');
goog.require('ol.geom.Point'); goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon'); goog.require('ol.geom.Polygon');
goog.require('ol.parser.ogc.KML'); goog.require('ol.parser.KML');
goog.require('ol.style.LineLiteral'); goog.require('ol.style.LineLiteral');
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"> <kml xmlns="http://www.opengis.net/kml/2.2">
<Document> <Document>
<NetworkLink><Link><href>spec/ol/parser/ogc/xml/kml_polygon.kml</href></Link></NetworkLink> <NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
</Document> </Document>
</kml> </kml>
@@ -9,7 +9,7 @@
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates> <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
</Point> </Point>
</Placemark> </Placemark>
<NetworkLink><Link><href>spec/ol/parser/ogc/xml/kml_polygon.kml</href></Link></NetworkLink> <NetworkLink><Link><href>spec/ol/parser/kml/polygon.kml</href></Link></NetworkLink>
<NetworkLink><Link><href>spec/ol/parser/ogc/xml/kml_point.kml</href></Link></NetworkLink> <NetworkLink><Link><href>spec/ol/parser/kml/point.kml</href></Link></NetworkLink>
</Document> </Document>
</kml> </kml>
@@ -9,6 +9,6 @@
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates> <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
</Point> </Point>
</Placemark> </Placemark>
<NetworkLink><Link><href>spec/ol/parser/ogc/xml/kml_depth.kml</href></Link></NetworkLink> <NetworkLink><Link><href>spec/ol/parser/kml/depth.kml</href></Link></NetworkLink>
</Document> </Document>
</kml> </kml>