|
| 1 | +require('../../../src/common/format/WKT'); |
| 2 | + |
| 3 | +describe('WKT', function () { |
| 4 | + //point的read、write方法 |
| 5 | + it('read, write_point', function () { |
| 6 | + var wkt = new SuperMap.Format.WKT({keepData: true}); |
| 7 | + var data = "POINT(6 10)"; |
| 8 | + var feature = wkt.read(data); |
| 9 | + expect(feature).not.toBeNull(); |
| 10 | + expect(feature.CLASS_NAME).toEqual("SuperMap.Feature.Vector"); |
| 11 | + expect(feature.id).toContain("SuperMap.Feature"); |
| 12 | + expect(feature.geometry.id).toContain("SuperMap.Geometry"); |
| 13 | + expect(feature.geometry.type).toEqual("Point"); |
| 14 | + expect(feature.geometry.x).toEqual(6); |
| 15 | + expect(feature.geometry.y).toEqual(10); |
| 16 | + var pointWkt = wkt.write(feature); |
| 17 | + expect(pointWkt).toEqual("POINT(6 10)"); |
| 18 | + }); |
| 19 | + |
| 20 | + //multipoint的read、write方法 |
| 21 | + it('read, write_multipoint的read', function () { |
| 22 | + var wkt = new SuperMap.Format.WKT({keepData: true}); |
| 23 | + var data = "MULTIPOINT((3.5 5.6),(4.8 10.5))"; |
| 24 | + var feature = wkt.read(data); |
| 25 | + expect(feature).not.toBeNull(); |
| 26 | + expect(feature.geometry.componentTypes.length).toEqual(1); |
| 27 | + expect(feature.geometry.componentTypes[0]).toEqual("SuperMap.Geometry.Point"); |
| 28 | + expect(feature.geometry.components.length).toEqual(2); |
| 29 | + expect(feature.geometry.components[0].type).toEqual("Point"); |
| 30 | + expect(feature.geometry.components[0].x).toEqual(3.5); |
| 31 | + expect(feature.geometry.components[0].y).toEqual(5.6); |
| 32 | + expect(feature.geometry.components[1].type).toEqual("Point"); |
| 33 | + expect(feature.geometry.components[1].x).toEqual(4.8); |
| 34 | + expect(feature.geometry.components[1].y).toEqual(10.5); |
| 35 | + var newWkt = wkt.write(feature); |
| 36 | + expect(newWkt).toEqual("MULTIPOINT((3.5 5.6),(4.8 10.5))"); |
| 37 | + }); |
| 38 | + |
| 39 | + //multilinestring 的read、write方法 |
| 40 | + it('read, write_multilinestring', function () { |
| 41 | + var wkt = new SuperMap.Format.WKT({keepData: true}); |
| 42 | + var data = "MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))"; |
| 43 | + var feature = wkt.read(data); |
| 44 | + expect(feature).not.toBeNull(); |
| 45 | + expect(feature.id).not.toBeNull(); |
| 46 | + expect(feature.geometry.CLASS_NAME).toEqual("SuperMap.Geometry.MultiLineString"); |
| 47 | + expect(feature.geometry.componentTypes[0]).toEqual("SuperMap.Geometry.LineString"); |
| 48 | + expect(feature.geometry.components[0].components.length).toEqual(3); |
| 49 | + for (var i = 0; i < feature.geometry.components[0].components.length; i++) { |
| 50 | + expect(feature.geometry.components[0].components[i].type).toEqual("Point"); |
| 51 | + } |
| 52 | + expect(feature.geometry.components[0].components[0].x).toEqual(3); |
| 53 | + expect(feature.geometry.components[0].components[0].y).toEqual(4); |
| 54 | + expect(feature.geometry.components[0].components[1].x).toEqual(10); |
| 55 | + expect(feature.geometry.components[0].components[1].y).toEqual(50); |
| 56 | + expect(feature.geometry.components[0].components[2].x).toEqual(20); |
| 57 | + expect(feature.geometry.components[0].components[2].y).toEqual(25); |
| 58 | + var newWkt = wkt.write(feature); |
| 59 | + expect(newWkt).toEqual("MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))"); |
| 60 | + }); |
| 61 | + |
| 62 | + //polygon 的read、write方法 |
| 63 | + it('read, write_polygon', function () { |
| 64 | + var wkt = new SuperMap.Format.WKT({keepData: true}); |
| 65 | + var data = "POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))"; |
| 66 | + var feature = wkt.read(data); |
| 67 | + expect(feature).not.toBeNull(); |
| 68 | + expect(feature.id).not.toBeNull(); |
| 69 | + expect(feature.geometry.componentTypes[0]).toEqual("SuperMap.Geometry.LinearRing"); |
| 70 | + expect(feature.geometry.components.length).toEqual(2); |
| 71 | + for (var i = 0; i < feature.geometry.components.length; i++) { |
| 72 | + expect(feature.geometry.components[i].components.length).toEqual(5); |
| 73 | + for (var j = 0; j < 5; j++) { |
| 74 | + expect(feature.geometry.components[i].components[j].type).toEqual("Point"); |
| 75 | + } |
| 76 | + } |
| 77 | + var newWkt = wkt.write(feature); |
| 78 | + expect(newWkt).toEqual("POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))"); |
| 79 | + }); |
| 80 | + |
| 81 | + //multipolygon 的read、write方法 |
| 82 | + it('read, write_multipolygon', function () { |
| 83 | + var wkt = new SuperMap.Format.WKT({keepData: true}); |
| 84 | + var data = "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6 3)))"; |
| 85 | + var feature = wkt.read(data); |
| 86 | + expect(feature).not.toBeNull(); |
| 87 | + expect(feature.id).not.toBeNull(); |
| 88 | + expect(feature.geometry.componentTypes[0]).toEqual("SuperMap.Geometry.Polygon"); |
| 89 | + expect(feature.geometry.components.length).toEqual(2); |
| 90 | + expect(feature.geometry.components[0].components.length).toEqual(2); |
| 91 | + for (var i = 0; i < 2; i++) { |
| 92 | + expect(feature.geometry.components[0].components[i].CLASS_NAME).toEqual("SuperMap.Geometry.LinearRing"); |
| 93 | + var pointComponents = feature.geometry.components[0].components[i].components; |
| 94 | + expect(pointComponents.length).toEqual(5); |
| 95 | + for (var j = 0; j < pointComponents.length; j++) { |
| 96 | + expect(pointComponents[i].type).toEqual("Point"); |
| 97 | + } |
| 98 | + } |
| 99 | + var newWkt = wkt.write(feature); |
| 100 | + expect(newWkt).toEqual("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6 3)))"); |
| 101 | + }); |
| 102 | + |
| 103 | + //geometrycollection的read、write方法 |
| 104 | + it('read, write_geometrycollection', function () { |
| 105 | + var wkt = new SuperMap.Format.WKT({keepData: true}); |
| 106 | + var data = "GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))"; |
| 107 | + var feature = wkt.read(data); |
| 108 | + expect(feature).not.toBeNull(); |
| 109 | + expect(feature.length).toEqual(2); |
| 110 | + expect(feature[0].id).toContain("SuperMap.Feature"); |
| 111 | + expect(feature[0].geometry.id).toContain("SuperMap.Geometry"); |
| 112 | + expect(feature[0].geometry.type).toEqual("Point"); |
| 113 | + expect(feature[0].geometry.x).toEqual(4); |
| 114 | + expect(feature[0].geometry.y).toEqual(6); |
| 115 | + expect(feature[1].id).toContain("SuperMap.Feature"); |
| 116 | + expect(feature[1].geometry.id).toContain("SuperMap.Geometry"); |
| 117 | + expect(feature[1].geometry.componentTypes[0]).toEqual("SuperMap.Geometry.Point"); |
| 118 | + expect(feature[1].geometry.componentTypes[1]).toEqual("SuperMap.PointWithMeasure"); |
| 119 | + expect(feature[1].geometry.components.length).toEqual(2); |
| 120 | + expect(feature[1].geometry.components[0].type).toEqual("Point"); |
| 121 | + expect(feature[1].geometry.components[0].x).toEqual(4); |
| 122 | + expect(feature[1].geometry.components[0].y).toEqual(6); |
| 123 | + expect(feature[1].geometry.components[1].type).toEqual("Point"); |
| 124 | + expect(feature[1].geometry.components[1].x).toEqual(7); |
| 125 | + expect(feature[1].geometry.components[1].y).toEqual(10); |
| 126 | + var newWkt = wkt.write(feature); |
| 127 | + expect(newWkt).toEqual("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))"); |
| 128 | + }); |
| 129 | +}); |
0 commit comments