Skip to content

Commit

Permalink
Reverted WKT coordinate parsing to first read latitude and then longi…
Browse files Browse the repository at this point in the history
…tude (#877)

* Changed WKT parent object to read coordinates as lat-long

* Changed WKT unit test to receive coordinates as 'lat,long'

* Styled Custom WKT string entry textbox to align it with the Destination one

* Reordered tags for WKT entry button
  • Loading branch information
Beak-man authored May 10, 2022
1 parent e7eff8d commit aa13d8f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 37 deletions.
10 changes: 6 additions & 4 deletions examples/WKT.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ <h4>Destination</h4>
</button>
</span>
</div>
<h4>WKT</h4>
<div>
<input type="text" id="wkt" />
<input type="button" id="showWkt" value="Show" />
<h4>Custom WKT entry</h4>
<div class="input-group">
<input type="text" class="form-control" id="wkt" />
<span class="input-group-btn">
<input id="showWkt" class="btn btn-primary" type="button" value="Show"/>
</span>
</div>
</div>
<div class="col-sm-9" id="globe">
Expand Down
2 changes: 1 addition & 1 deletion examples/WKT.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ requirejs(['./WorldWindShim',
wwd.addLayer(customCallbackLayer);

// Allow for parsing of Well-Known Text from the app's text box (entered by the user).
var wktLayer = new WorldWind.RenderableLayer('WKT Custom');
var wktLayer = new WorldWind.RenderableLayer('Custom WKT');
$('#showWkt').click(function () {
new WorldWind.Wkt($('#wkt').val()).load(null, null, wktLayer);
});
Expand Down
4 changes: 2 additions & 2 deletions src/formats/wkt/geom/WktObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ define([
*/
WktObject.prototype.addCoordinates = function (coordinates) {
if (this._is3d) {
this.coordinates.push(new Position(coordinates[1], coordinates[0], coordinates[2] || 0));
this.coordinates.push(new Position(coordinates[0], coordinates[1], coordinates[2] || 0));
} else {
this.coordinates.push(new Location(coordinates[1], coordinates[0]));
this.coordinates.push(new Location(coordinates[0], coordinates[1]));
}
};

Expand Down
60 changes: 30 additions & 30 deletions test/formats/wkt/WktTokens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define([
describe("WktTokens", function () {
describe("Point", function () {
it('correctly parses 2D point', function () {
var point2D = 'POINT (50 14.5)';
var point2D = 'POINT (14.5 50)';
var wktObjects = new WktTokens(point2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -66,7 +66,7 @@ define([
});

it('correctly parses 3D point', function () {
var point3D = 'POINT Z(50 14.5 13)';
var point3D = 'POINT Z(14.5 50 13)';
var wktObjects = new WktTokens(point3D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -75,7 +75,7 @@ define([
});

it('correctly ignores the LRS for 2D point', function () {
var point2DLrs = 'POINT M (50 14.5 10)';
var point2DLrs = 'POINT M (14.5 50 10)';
var wktObjects = new WktTokens(point2DLrs).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -84,7 +84,7 @@ define([
});

it('correctly ignores the LRS for 3D point', function () {
var point3DLrs = 'POINT MZ (50 14.5 10 13)';
var point3DLrs = 'POINT MZ (14.5 50 10 13)';
var wktObjects = new WktTokens(point3DLrs).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -95,7 +95,7 @@ define([

describe('Polygon', function () {
it('correctly parses 2D polygon', function () {
var polygon2D = 'POLYGON ((-70 40, -80 45, -90 40))';
var polygon2D = 'POLYGON ((40 -70, 45 -80, 40 -90))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -105,7 +105,7 @@ define([
});

it('correctly parses 3D polygon with inner boundaries', function(){
var polygon = 'POLYGON Z ((-70 40 10, -80 45 10, -90 40 10), (-75 42 10, 44 -78 10, 42 -73 10))';
var polygon = 'POLYGON Z ((40 -70 10, 45 -80 10, 40 -90 10), (42 -75 10, 44 -78 10, 42 -73 10))';
var wktObjects = new WktTokens(polygon).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -114,7 +114,7 @@ define([
});

it('correctly ignores LRS for 2D polygon', function () {
var polygon2D = 'POLYGON M((-70 40 10, -80 45 10, -90 40 10))';
var polygon2D = 'POLYGON M((40 -70 10, 45 -80 10, 40 -90 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -124,7 +124,7 @@ define([
});

it('correctly parses 3D polygon', function () {
var polygon2D = 'POLYGON Z ((-70 40 10, -80 45 10, -90 40 10))';
var polygon2D = 'POLYGON Z ((40 -70 10, 45 -80 10, 40 -90 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -134,7 +134,7 @@ define([
});

it('correctly ignores LRS for 3D polygon', function () {
var polygon2D = 'POLYGON MZ ((-70 40 10, -80 45 10, -90 40 10))';
var polygon2D = 'POLYGON MZ ((40 -70 10, 45 -80 10, 40 -90 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -155,7 +155,7 @@ define([
});

it('correctly parses 2D line string', function () {
var polygon2D = 'LINESTRING ((-75 33, -80 37, -85 33))';
var polygon2D = 'LINESTRING ((33 -75, 37 -80, 33 -85))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -165,7 +165,7 @@ define([
});

it('correctly ignores LRS for 2D line string', function () {
var polygon2D = 'LINESTRING M((-75 33 10, -80 37 10, -85 33 10))';
var polygon2D = 'LINESTRING M((33 -75 10, 37 -80 10, 33 -85 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -175,7 +175,7 @@ define([
});

it('correctly parses 3D line string', function () {
var polygon2D = 'LINESTRINGZ((-75 33 10, -80 37 10, -85 33 10))';
var polygon2D = 'LINESTRINGZ((33 -75 10, 37 -80 10, 33 -85 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -185,7 +185,7 @@ define([
});

it('correctly ignores LRS for 3D line string', function () {
var polygon2D = 'LINESTRING MZ((-75 33 10 10, -80 37 10 10, -85 33 10 10))';
var polygon2D = 'LINESTRING MZ((33 -75 10 10, 37 -80 10 10, 33 -85 10 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -197,7 +197,7 @@ define([

describe('Triangle', function () {
it('correctly parses 2D triangle', function () {
var polygon2D = 'TRIANGLE ((-70 40, -80 45, -90 40))';
var polygon2D = 'TRIANGLE ((40 -70, 45 -80, 40 -90))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -207,7 +207,7 @@ define([
});

it('correctly ignores LRS for 2D triangle', function () {
var polygon2D = 'TRIANGLE M((-70 40 10, -80 45 10, -90 40 10))';
var polygon2D = 'TRIANGLE M((40 -70 10, 45 -80 10, 40 -90 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -217,7 +217,7 @@ define([
});

it('correctly parses 3D triangle', function () {
var polygon2D = 'TRIANGLE Z((-70 40 10, -80 45 10, -90 40 10))';
var polygon2D = 'TRIANGLE Z((40 -70 10, 45 -80 10, 40 -90 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -227,7 +227,7 @@ define([
});

it('correctly ignores LRS for 3D triangle', function () {
var polygon2D = 'TRIANGLE MZ((-70 40 10 10, -80 45 10 10, -90 40 10 10))';
var polygon2D = 'TRIANGLE MZ((40 -70 10 10, 45 -80 10 10, 40 -90 10 10))';
var wktObjects = new WktTokens(polygon2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -239,7 +239,7 @@ define([

describe('MultiPoint', function () {
it('correctly parses 2D point', function () {
var point2D = 'MULTIPOINT ((49.3 17),(49 -17))';
var point2D = 'MULTIPOINT ((17 49.3),(-17 49))';
var wktObjects = new WktTokens(point2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -250,7 +250,7 @@ define([
});

it('correctly parses 3D point', function () {
var point2D = 'MULTIPOINT Z((49.3 17 10),(49 -17 1))';
var point2D = 'MULTIPOINT Z((17 49.3 10),(-17 49 1))';
var wktObjects = new WktTokens(point2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -261,7 +261,7 @@ define([
});

it('correctly ignores the LRS for 2D point', function () {
var point2DLrs = 'MULTIPOINT M((49.3 17 10),(49 -17 1))';
var point2DLrs = 'MULTIPOINT M((17 49.3 10),(-17 49 1))';
var wktObjects = new WktTokens(point2DLrs).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -272,7 +272,7 @@ define([
});

it('correctly ignores the LRS for 3D point', function () {
var point2D = 'MULTIPOINT MZ((49.3 17 10 1),(49 -17 1 100))';
var point2D = 'MULTIPOINT MZ((17 49.3 10 1),(-17 49 1 100))';
var wktObjects = new WktTokens(point2D).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -285,7 +285,7 @@ define([

describe('MultiLineString', function () {
it('correctly parses 2D Multi Line String', function(){
var multiLineString = 'MULTILINESTRING ((-70 38, -75 42, -80 38),(-65 43, -70 47, -75 43))';
var multiLineString = 'MULTILINESTRING ((38 -70, 42 -75, 38 -80),(43 -65, 47 -70, 43 -75))';
var wktObjects = new WktTokens(multiLineString).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -298,7 +298,7 @@ define([
});

it('correctly parses 2D Multi Line String with LRS', function(){
var multiLineString = 'MULTILINESTRING M((-70 38 10, -75 42 10, -80 38 10),(-65 43 10, -70 47 10, -75 43 10))';
var multiLineString = 'MULTILINESTRING M((38 -70 10, 42 -75 10, 38 -80 10),(43 -65 10, 47 -70 10, 43 -75 10))';
var wktObjects = new WktTokens(multiLineString).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -311,7 +311,7 @@ define([
});

it('correctly parses 3D Line String', function(){
var multiLineString = 'MULTILINESTRING Z((-70 38 10, -75 42 10, -80 38 10),(-65 43 10, -70 47 10, -75 43 10))';
var multiLineString = 'MULTILINESTRING Z((38 -70 10, 42 -75 10, 38 -80 10),(43 -65 10, 47 -70 10, 43 -75 10))';
var wktObjects = new WktTokens(multiLineString).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -324,7 +324,7 @@ define([
});

it('correctly parses 3D Line String with LRS', function(){
var multiLineString = 'MULTILINESTRING MZ((-70 38 10 12, -75 42 10 12, -80 38 10 12),(-65 43 10 12, -70 47 10 12, -75 43 10 12))';
var multiLineString = 'MULTILINESTRING MZ((38 -70 10 12, 42 -75 10 12, 38 -80 10 12),(43 -65 10 12, 47 -70 10 12, 43 -75 10 12))';
var wktObjects = new WktTokens(multiLineString).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -339,7 +339,7 @@ define([

describe('MultiPolygon', function () {
it('correctly parses 2D Multi polygon', function(){
var multiPolygon = 'MULTIPOLYGON (((-60 50, -70 55, -80 50)),((-60 30, -70 35, -80 30)))';
var multiPolygon = 'MULTIPOLYGON (((50 -60, 55 -70, 50 -80)),((30 -60, 35 -70, 30 -80)))';
var wktObjects = new WktTokens(multiPolygon).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -355,7 +355,7 @@ define([
});

it('correctly parses 3D Multi polygon with inner boundaries', function(){
var multiPolygon = 'MULTIPOLYGON Z (((-60 50 10, -70 55 10, -80 50 10)),((-70 40 10, -80 45 10, -90 40 10), (-75 42 10, 44 -78 10, 42 -73 10)))';
var multiPolygon = 'MULTIPOLYGON Z (((50 -60 10, 55 -70 10, 50 -80 10)),((40 -70 10, 45 -80 10, 40 -90 10), (42 -75 10, 44 -78 10, 42 -73 10)))';
var wktObjects = new WktTokens(multiPolygon).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -367,7 +367,7 @@ define([
});

it('correctly parses 2D Multi polygon with LRS', function(){
var multiPolygon = 'MULTIPOLYGON M (((-60 50 10, -70 55 10, -80 50 10)),((-60 30 10, -70 35 10, -80 30 10)))';
var multiPolygon = 'MULTIPOLYGON M (((50 -60 10, 55 -70 10, 50 -80 10)),((30 -60 10, 35 -70 10, 30 -80 10)))';
var wktObjects = new WktTokens(multiPolygon).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -380,7 +380,7 @@ define([
});

it('correctly parses 3D Multi Polygon', function(){
var multiPolygon = 'MULTIPOLYGON Z (((-60 50 10, -70 55 10, -80 50 10)),((-60 30 10, -70 35 10, -80 30 10)))';
var multiPolygon = 'MULTIPOLYGON Z (((50 -60 10, 55 -70 10, 50 -80 10)),((30 -60 10, 35 -70 10, 30 -80 10)))';
var wktObjects = new WktTokens(multiPolygon).objects();

expect(wktObjects.length).toBe(1);
Expand All @@ -393,7 +393,7 @@ define([
});

it('correctly parses 3D Multi Polygon with LRS', function(){
var multiPolygon = 'MULTIPOLYGON MZ (((-60 50 10 10, -70 55 10 10, -80 50 10 10)),((-60 30 10 10, -70 35 10 10, -80 30 10 10)))';
var multiPolygon = 'MULTIPOLYGON MZ (((50 -60 10 10, 55 -70 10 10, 50 -80 10 10)),((30 -60 10 10, 35 -70 10 10, 30 -80 10 10)))';
var wktObjects = new WktTokens(multiPolygon).objects();

expect(wktObjects.length).toBe(1);
Expand Down

0 comments on commit aa13d8f

Please sign in to comment.