use goog.global, restructure to have ol.parser.KML instead of ol.parser.ogc.KML
This commit is contained in:
@@ -4,7 +4,7 @@ goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.ogc.KML');
|
||||
goog.require('ol.parser.KML');
|
||||
goog.require('ol.projection');
|
||||
goog.require('ol.source.TiledWMS');
|
||||
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});
|
||||
|
||||
$.ajax({
|
||||
|
||||
3
src/ol/parser/kml.exports
Normal file
3
src/ol/parser/kml.exports
Normal 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.async.Deferred');
|
||||
goog.require('goog.async.DeferredList');
|
||||
@@ -38,7 +38,7 @@ goog.require('ol.style.PolygonLiteral');
|
||||
* dimension: (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.StringFeatureParser}
|
||||
* @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}
|
||||
*/
|
||||
ol.parser.ogc.KML = function(opt_options) {
|
||||
ol.parser.KML = function(opt_options) {
|
||||
if (goog.isDef(opt_options)) {
|
||||
goog.object.extend(this, opt_options);
|
||||
}
|
||||
@@ -802,7 +802,7 @@ ol.parser.ogc.KML = function(opt_options) {
|
||||
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.
|
||||
* @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) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
this.read(obj, callback);
|
||||
@@ -824,7 +824,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromObjectAsync =
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Reader options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
*/
|
||||
ol.parser.ogc.KML.prototype.readFeaturesFromString =
|
||||
ol.parser.KML.prototype.readFeaturesFromString =
|
||||
function(str, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(str).features;
|
||||
@@ -837,7 +837,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromString =
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
*/
|
||||
ol.parser.ogc.KML.prototype.readFeaturesFromNode =
|
||||
ol.parser.KML.prototype.readFeaturesFromNode =
|
||||
function(node, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
return this.read(node).features;
|
||||
@@ -849,7 +849,7 @@ ol.parser.ogc.KML.prototype.readFeaturesFromNode =
|
||||
* @param {ol.parser.ReadFeaturesOptions=} opt_options Feature reading options.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
*/
|
||||
ol.parser.ogc.KML.prototype.readFeaturesFromObject =
|
||||
ol.parser.KML.prototype.readFeaturesFromObject =
|
||||
function(obj, opt_options) {
|
||||
this.readFeaturesOptions_ = opt_options;
|
||||
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 {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;
|
||||
if (this.depth_ < this.maxDepth) {
|
||||
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) {
|
||||
if (e.target.isSuccess()) {
|
||||
var data = e.target.getResponseXml();
|
||||
e.target.dispose();
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
@@ -901,7 +902,7 @@ ol.parser.ogc.KML.prototype.parseLinks = function(deferreds, obj, done) {
|
||||
* is done.
|
||||
* @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') {
|
||||
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=} opt_symbolizers Optional symbolizers.
|
||||
*/
|
||||
ol.parser.ogc.KML.prototype.applyStyle_ = function(feature, styles,
|
||||
ol.parser.KML.prototype.applyStyle_ = function(feature, styles,
|
||||
opt_symbolizers) {
|
||||
var symbolizers = opt_symbolizers;
|
||||
var i, ii;
|
||||
@@ -978,7 +979,7 @@ ol.parser.ogc.KML.prototype.applyStyle_ = function(feature, styles,
|
||||
* @param {ol.geom.SharedVertices=} opt_vertices Shared vertices.
|
||||
* @return {ol.geom.Geometry} The geometry created.
|
||||
*/
|
||||
ol.parser.ogc.KML.prototype.createGeometry_ = function(container,
|
||||
ol.parser.KML.prototype.createGeometry_ = function(container,
|
||||
opt_vertices) {
|
||||
var geometry = null, coordinates, i, ii;
|
||||
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.
|
||||
* @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);
|
||||
return goog.dom.xml.serialize(root);
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
@exportSymbol ol.parser.ogc.KML
|
||||
@exportProperty ol.parser.ogc.KML.prototype.read
|
||||
@exportProperty ol.parser.ogc.KML.prototype.write
|
||||
@@ -9,7 +9,7 @@ goog.require('ol.parser.Parser');
|
||||
* @extends {ol.parser.Parser}
|
||||
*/
|
||||
ol.parser.XML = function() {
|
||||
if (window.ActiveXObject) {
|
||||
if (goog.global.ActiveXObject) {
|
||||
this.xmldom = new ActiveXObject('Microsoft.XMLDOM');
|
||||
}
|
||||
this.regExes = {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
goog.provide('ol.test.parser.ogc.kml');
|
||||
goog.provide('ol.test.parser.kml');
|
||||
|
||||
describe('ol.parser.kml', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.KML();
|
||||
var parser = new ol.parser.KML();
|
||||
|
||||
describe('Test KML parser', 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) {
|
||||
var obj = parser.read(xml);
|
||||
var output = parser.write(obj);
|
||||
@@ -33,7 +33,7 @@ describe('ol.parser.kml', 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) {
|
||||
var obj = parser.read(xml);
|
||||
var output = parser.write(obj);
|
||||
@@ -54,7 +54,7 @@ describe('ol.parser.kml', 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) {
|
||||
var obj = parser.read(xml);
|
||||
var output = parser.write(obj);
|
||||
@@ -72,9 +72,9 @@ describe('ol.parser.kml', function() {
|
||||
});
|
||||
});
|
||||
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) {
|
||||
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
|
||||
var obj = p.read(xml, function(features) {
|
||||
expect(features.length).to.eql(3);
|
||||
@@ -83,9 +83,9 @@ describe('ol.parser.kml', function() {
|
||||
});
|
||||
});
|
||||
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) {
|
||||
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
|
||||
var obj = p.read(xml, function(features) {
|
||||
expect(features.length).to.eql(2);
|
||||
@@ -94,9 +94,9 @@ describe('ol.parser.kml', function() {
|
||||
});
|
||||
});
|
||||
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) {
|
||||
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
|
||||
var obj = p.read(xml, function(features) {
|
||||
// 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() {
|
||||
var url = 'spec/ol/parser/ogc/xml/kml_extended_data.kml';
|
||||
var url = 'spec/ol/parser/kml/extended_data.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
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() {
|
||||
var url = 'spec/ol/parser/ogc/xml/kml_extended_data2.kml';
|
||||
var url = 'spec/ol/parser/kml/extended_data2.kml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var feature = obj.features[0];
|
||||
@@ -127,7 +127,7 @@ describe('ol.parser.kml', 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) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
@@ -146,7 +146,7 @@ describe('ol.parser.kml', 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) {
|
||||
var obj = parser.read(xml);
|
||||
var geom = obj.features[0].getGeometry();
|
||||
@@ -157,9 +157,9 @@ describe('ol.parser.kml', 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) {
|
||||
var p = new ol.parser.ogc.KML({extractStyles: true,
|
||||
var p = new ol.parser.KML({extractStyles: true,
|
||||
trackAttributes: ['speed', 'num']});
|
||||
var obj = p.read(xml);
|
||||
expect(obj.features.length).to.eql(170);
|
||||
@@ -198,7 +198,7 @@ describe('ol.parser.kml', function() {
|
||||
'<width>10</width> </LineStyle> </Style> <LineString> ' +
|
||||
'<coordinates> -112,36 -113,37 </coordinates> </LineString>' +
|
||||
'</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 output = p.write(obj);
|
||||
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 ' +
|
||||
'5.001370157823406,49.26855713824488</coordinates></LinearRing>' +
|
||||
'</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 output = p.write(obj);
|
||||
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);
|
||||
});
|
||||
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) {
|
||||
var p = new ol.parser.ogc.KML({extractStyles: true});
|
||||
var p = new ol.parser.KML({extractStyles: true});
|
||||
var obj = p.read(xml);
|
||||
var output = p.write(obj);
|
||||
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.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.ogc.KML');
|
||||
goog.require('ol.parser.KML');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<kml xmlns="http://www.opengis.net/kml/2.2">
|
||||
<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>
|
||||
</kml>
|
||||
@@ -9,7 +9,7 @@
|
||||
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
|
||||
</Point>
|
||||
</Placemark>
|
||||
<NetworkLink><Link><href>spec/ol/parser/ogc/xml/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/polygon.kml</href></Link></NetworkLink>
|
||||
<NetworkLink><Link><href>spec/ol/parser/kml/point.kml</href></Link></NetworkLink>
|
||||
</Document>
|
||||
</kml>
|
||||
@@ -9,6 +9,6 @@
|
||||
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
|
||||
</Point>
|
||||
</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>
|
||||
</kml>
|
||||
Reference in New Issue
Block a user