@@ -51,10 +51,11 @@ ol.format.TopoJSON.EXTENSIONS_ = ['.topojson'];
|
||||
* values indicate arcs need to be reversed.
|
||||
* @param {Array.<Array.<ol.Coordinate>>} arcs Array of arcs (already
|
||||
* transformed).
|
||||
* @return {Array.<Array.<ol.Coordinate>>} Coordinates array.
|
||||
* @return {Array.<ol.Coordinate>} Coordinates array.
|
||||
* @private
|
||||
*/
|
||||
ol.format.TopoJSON.concatenateArcs_ = function(indices, arcs) {
|
||||
/** @type {Array.<ol.Coordinate>} */
|
||||
var coordinates = [];
|
||||
var index, arc;
|
||||
var i, ii;
|
||||
@@ -94,7 +95,7 @@ ol.format.TopoJSON.concatenateArcs_ = function(indices, arcs) {
|
||||
ol.format.TopoJSON.readPointGeometry_ =
|
||||
function(object, scale, translate) {
|
||||
var coordinates = object.coordinates;
|
||||
if (goog.isDef(scale) && goog.isDef(translate)) {
|
||||
if (!goog.isNull(scale) && !goog.isNull(translate)) {
|
||||
ol.format.TopoJSON.transformVertex_(coordinates, scale, translate);
|
||||
}
|
||||
return new ol.geom.Point(coordinates);
|
||||
@@ -114,7 +115,7 @@ ol.format.TopoJSON.readMultiPointGeometry_ = function(object, scale,
|
||||
translate) {
|
||||
var coordinates = object.coordinates;
|
||||
var i, ii;
|
||||
if (goog.isDef(scale) && goog.isDef(translate)) {
|
||||
if (!goog.isNull(scale) && !goog.isNull(translate)) {
|
||||
for (i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
ol.format.TopoJSON.transformVertex_(coordinates[i], scale, translate);
|
||||
}
|
||||
@@ -133,7 +134,7 @@ ol.format.TopoJSON.readMultiPointGeometry_ = function(object, scale,
|
||||
*/
|
||||
ol.format.TopoJSON.readLineStringGeometry_ = function(object, arcs) {
|
||||
var coordinates = ol.format.TopoJSON.concatenateArcs_(object.arcs, arcs);
|
||||
return new ol.geom.LineString(goog.array.flatten(coordinates));
|
||||
return new ol.geom.LineString(coordinates);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -64,6 +64,31 @@ describe('ol.format.TopoJSON', function() {
|
||||
|
||||
describe('#readFeatures()', function() {
|
||||
|
||||
it('parses simple.json', function(done) {
|
||||
afterLoadText('spec/ol/format/topojson/simple.json', function(text) {
|
||||
var features = format.readFeatures(text);
|
||||
expect(features.length).to.be(3);
|
||||
|
||||
var point = features[0].getGeometry();
|
||||
expect(point.getType()).to.be('Point');
|
||||
expect(point.getFlatCoordinates()).to.eql([102, 0.5]);
|
||||
|
||||
var line = features[1].getGeometry();
|
||||
expect(line.getType()).to.be('LineString');
|
||||
expect(line.getFlatCoordinates()).to.eql([
|
||||
102, 0, 103, 1, 104, 0, 105, 1
|
||||
]);
|
||||
|
||||
var polygon = features[2].getGeometry();
|
||||
expect(polygon.getType()).to.be('Polygon');
|
||||
expect(polygon.getFlatCoordinates()).to.eql([
|
||||
100, 0, 100, 1, 101, 1, 101, 0, 100, 0
|
||||
]);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('parses world-110m.json', function(done) {
|
||||
afterLoadText('spec/ol/format/topojson/world-110m.json', function(text) {
|
||||
|
||||
|
||||
39
test/spec/ol/format/topojson/simple.json
Normal file
39
test/spec/ol/format/topojson/simple.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"type": "Topology",
|
||||
"objects": {
|
||||
"example": {
|
||||
"type": "GeometryCollection",
|
||||
"geometries": [
|
||||
{
|
||||
"type": "Point",
|
||||
"properties": {
|
||||
"prop0": "value0"
|
||||
},
|
||||
"coordinates": [102, 0.5]
|
||||
},
|
||||
{
|
||||
"type": "LineString",
|
||||
"properties": {
|
||||
"prop0": "value0",
|
||||
"prop1": 0
|
||||
},
|
||||
"arcs": [0]
|
||||
},
|
||||
{
|
||||
"type": "Polygon",
|
||||
"properties": {
|
||||
"prop0": "value0",
|
||||
"prop1": {
|
||||
"this": "that"
|
||||
}
|
||||
},
|
||||
"arcs": [[-2]]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"arcs": [
|
||||
[[102, 0], [103, 1], [104, 0], [105, 1]],
|
||||
[[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user