Initial commit

This commit is contained in:
zhongjin
2020-06-13 18:34:34 +08:00
commit 52aaa9f15d
655 changed files with 96796 additions and 0 deletions
@@ -0,0 +1,148 @@
var _ = require('underscore');
var GeometryFactory = require('../../../../src/geo/geometry-models/geometry-factory');
var Point = require('../../../../src/geo/geometry-models/point');
var Polyline = require('../../../../src/geo/geometry-models/polyline');
var Polygon = require('../../../../src/geo/geometry-models/polygon');
var MultiPoint = require('../../../../src/geo/geometry-models/multi-point');
var MultiPolygon = require('../../../../src/geo/geometry-models/multi-polygon');
var MultiPolyline = require('../../../../src/geo/geometry-models/multi-polyline');
var geometryAsFeature = function (geometry) {
return {
'type': 'Feature',
'properties': {},
'geometry': geometry
};
};
describe('src/geo/geometry-models/geometry-factory', function () {
describe('.createGeometryFromGeoJSON', function () {
var pointGeometry = {
'type': 'Point',
'coordinates': [
-3.779296875,
40.245991504199026
]
};
_.each([ pointGeometry, geometryAsFeature(pointGeometry) ], function (geoJSON) {
it('should create a point', function () {
var geometry = GeometryFactory.createGeometryFromGeoJSON(geoJSON);
expect(geometry instanceof Point).toBeTruthy();
expect(geometry.getCoordinates()).toEqual([ 40.245991504199026, -3.779296875 ]);
});
});
var polylineGeometry = {
'type': 'LineString',
'coordinates': [
[
-2.021484375,
43.51668853502906
],
[
3.6035156249999996,
42.293564192170095
]
]
};
_.each([ polylineGeometry, geometryAsFeature(polylineGeometry) ], function (geoJSON) {
it('should create a polyline', function () {
var geometry = GeometryFactory.createGeometryFromGeoJSON(geoJSON);
expect(geometry instanceof Polyline).toBeTruthy();
expect(geometry.getCoordinates()).toEqual([
[ 43.51668853502906, -2.021484375 ],
[ 42.293564192170095, 3.6035156249999996 ]
]);
});
});
var polygonGeometry = {
'type': 'Polygon',
'coordinates': [
[
[
-8.96484375,
41.918628865183045
],
[
-7.84423828125,
43.74728909225908
],
[
-1.69189453125,
43.34914966389313
],
[
-8.96484375,
41.918628865183045
]
]
]
};
_.each([ polygonGeometry, geometryAsFeature(polygonGeometry) ], function (geoJSON) {
it('should create a polygon', function () {
var geometry = GeometryFactory.createGeometryFromGeoJSON(geoJSON);
expect(geometry instanceof Polygon).toBeTruthy();
expect(geometry.getCoordinates()).toEqual([
[ 41.918628865183045, -8.96484375 ],
[ 43.74728909225908, -7.84423828125 ],
[ 43.34914966389313, -1.69189453125 ]
]);
});
});
var multiPointGeometry = {
'type': 'MultiPoint',
'coordinates': [ [100.0, 0.0], [101.0, 1.0] ]
};
it('should create a multipoint', function () {
var geometry = GeometryFactory.createGeometryFromGeoJSON(multiPointGeometry);
expect(geometry instanceof MultiPoint).toBeTruthy();
expect(geometry.geometries.length).toEqual(2);
expect(geometry.geometries.at(0).getCoordinates()).toEqual([ 0, 100 ]);
expect(geometry.geometries.at(1).getCoordinates()).toEqual([ 1, 101 ]);
});
var multiPolygonGeometry = {
'type': 'MultiPolygon',
'coordinates': [
[ [ [102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0] ] ],
[ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ]
]
};
it('should create a multipolygon', function () {
var geometry = GeometryFactory.createGeometryFromGeoJSON(multiPolygonGeometry);
expect(geometry instanceof MultiPolygon).toBeTruthy();
expect(geometry.geometries.length).toEqual(2);
expect(geometry.geometries.at(0).getCoordinates()).toEqual([ [ 2, 102 ], [ 2, 103 ], [ 3, 103 ], [ 3, 102 ] ]);
expect(geometry.geometries.at(1).getCoordinates()).toEqual([ [ 0, 100 ], [ 0, 101 ], [ 1, 101 ], [ 1, 100 ] ]);
});
var multiPolylineGeometry = {
'type': 'MultiLineString',
'coordinates': [
[ [100.0, 0.0], [101.0, 1.0] ],
[ [102.0, 2.0], [103.0, 3.0] ]
]
};
it('should create a multipolyline', function () {
var geometry = GeometryFactory.createGeometryFromGeoJSON(multiPolylineGeometry);
expect(geometry instanceof MultiPolyline).toBeTruthy();
expect(geometry.geometries.length).toEqual(2);
expect(geometry.geometries.at(0).getCoordinates()).toEqual([ [ 0, 100 ], [ 1, 101 ] ]);
expect(geometry.geometries.at(1).getCoordinates()).toEqual([ [ 2, 102 ], [ 3, 103 ] ]);
});
});
});
@@ -0,0 +1,32 @@
var MultiPoint = require('../../../../src/geo/geometry-models/multi-point');
describe('src/geo/geometry-models/multi-point', function () {
beforeEach(function () {
this.multiPoint = new MultiPoint(null, {
latlngs: [
[0, 1],
[1, 2]
]
});
});
describe('.toGeoJSON', function () {
it('should generate the GeoJSON correctly', function () {
expect(this.multiPoint.toGeoJSON()).toEqual({
type: 'MultiPoint',
coordinates: [ [ 1, 0 ], [ 2, 1 ] ]
});
});
});
describe('.setCoordinatesFromGeoJSON', function () {
it('should update the coordinates', function () {
var newAndExpectedGeoJSON = {
type: 'MultiPoint',
coordinates: [ [ 0, 0 ], [ 10, 10 ] ]
};
this.multiPoint.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
expect(this.multiPoint.toGeoJSON()).toEqual(newAndExpectedGeoJSON);
});
});
});
@@ -0,0 +1,54 @@
var MultiPolygon = require('../../../../src/geo/geometry-models/multi-polygon');
describe('src/geo/geometry-models/multi-polygon', function () {
beforeEach(function () {
this.multiPolygon = new MultiPolygon(null, {
latlngs: [
[
[0, 1],
[1, 2],
[2, 3],
[3, 4]
],
[
[0, 10],
[10, 20],
[20, 30],
[30, 40]
]
]
});
});
describe('.toGeoJSON', function () {
it('should generate the GeoJSON correctly', function () {
expect(this.multiPolygon.toGeoJSON()).toEqual({
type: 'MultiPolygon',
coordinates: [
[
[ [ 1, 0 ], [ 2, 1 ], [ 3, 2 ], [ 4, 3 ], [ 1, 0 ] ]
], [
[ [ 10, 0 ], [ 20, 10 ], [ 30, 20 ], [ 40, 30 ], [ 10, 0 ] ]
]
]
});
});
});
describe('.setCoordinatesFromGeoJSON', function () {
it('should update the coordinates', function () {
var newAndExpectedGeoJSON = {
type: 'MultiPolygon',
coordinates: [
[
[ [ 0, 0 ], [ 2, 1 ], [ 3, 2 ], [ 4, 3 ], [ 0, 0 ] ]
], [
[ [ 100, 0 ], [ 20, 10 ], [ 30, 20 ], [ 40, 30 ], [ 100, 0 ] ]
]
]
};
this.multiPolygon.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
expect(this.multiPolygon.toGeoJSON()).toEqual(newAndExpectedGeoJSON);
});
});
});
@@ -0,0 +1,54 @@
var MultiPolyline = require('../../../../src/geo/geometry-models/multi-polyline');
describe('src/geo/geometry-models/multi-polyline', function () {
beforeEach(function () {
this.multiPolyline = new MultiPolyline(null, {
latlngs: [
[
[0, 1],
[1, 2],
[2, 3],
[3, 4]
],
[
[0, 10],
[10, 20],
[20, 30],
[30, 40]
]
]
});
});
describe('.toGeoJSON', function () {
it('should generate the GeoJSON correctly', function () {
expect(this.multiPolyline.toGeoJSON()).toEqual({
type: 'MultiLineString',
coordinates: [
[
[ 1, 0 ], [ 2, 1 ], [ 3, 2 ], [ 4, 3 ]
], [
[ 10, 0 ], [ 20, 10 ], [ 30, 20 ], [ 40, 30 ]
]
]
});
});
});
describe('.setCoordinatesFromGeoJSON', function () {
it('should update the coordinates', function () {
var newAndExpectedGeoJSON = {
type: 'MultiLineString',
coordinates: [
[
[ 100, 0 ], [ 2, 1 ], [ 3, 2 ], [ 40, 30 ]
], [
[ 100, 0 ], [ 20, 10 ], [ 30, 20 ], [ 40, 30 ]
]
]
};
this.multiPolyline.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
expect(this.multiPolyline.toGeoJSON()).toEqual(newAndExpectedGeoJSON);
});
});
});
@@ -0,0 +1,58 @@
var Point = require('../../../../src/geo/geometry-models/point');
describe('src/geo/geometry-models/point', function () {
beforeEach(function () {
this.point = new Point({
latlng: [100, 200]
});
});
describe('.toGeoJSON', function () {
it('should generate the GeoJSON correctly', function () {
expect(this.point.toGeoJSON()).toEqual({
type: 'Point',
coordinates: [ 200, 100 ]
});
});
});
describe('.setCoordinatesFromGeoJSON', function () {
beforeEach(function () {
this.changeCallback = jasmine.createSpy('changeCallback');
this.point.on('change', this.changeCallback);
});
describe('when given a GeoJSON with the same coordinates', function () {
beforeEach(function () {
var newAndExpectedGeoJSON = this.point.toGeoJSON();
this.point.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
});
it('should NOT trigger a "change" event', function () {
expect(this.changeCallback).not.toHaveBeenCalled();
});
});
describe('when given a GeoJSON with different coordinates', function () {
beforeEach(function () {
var newAndExpectedGeoJSON = {
type: 'Point',
coordinates: [ 0, 300 ]
};
this.point.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
expect(this.point.toGeoJSON()).toEqual(newAndExpectedGeoJSON);
});
it('should trigger a "change" event', function () {
expect(this.changeCallback).toHaveBeenCalled();
});
it('should update the coordinates', function () {
expect(this.point.toGeoJSON()).toEqual({
type: 'Point',
coordinates: [ 0, 300 ]
});
});
});
});
});
@@ -0,0 +1,66 @@
var Polygon = require('../../../../src/geo/geometry-models/polygon');
describe('src/geo/geometry-models/polygon', function () {
beforeEach(function () {
this.polygon = new Polygon(null, {
latlngs: [
[-1, 1], [1, 2], [3, 4]
]
});
});
describe('.toGeoJSON', function () {
it('should generate the GeoJSON correctly', function () {
expect(this.polygon.toGeoJSON()).toEqual({
type: 'Polygon',
coordinates: [
[ [ 1, -1 ], [ 2, 1 ], [ 4, 3 ], [ 1, -1 ] ]
]
});
});
});
describe('.setCoordinatesFromGeoJSON', function () {
beforeEach(function () {
this.changeCallback = jasmine.createSpy('changeCallback');
this.polygon.on('change', this.changeCallback);
});
describe('when given a GeoJSON with the same coordinates', function () {
beforeEach(function () {
var newAndExpectedGeoJSON = this.polygon.toGeoJSON();
this.polygon.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
});
it('should NOT trigger a "change" event', function () {
expect(this.changeCallback).not.toHaveBeenCalled();
});
});
describe('when given a GeoJSON with different coordinates', function () {
beforeEach(function () {
var newAndExpectedGeoJSON = {
type: 'Polygon',
coordinates: [
[ [ 0, 0 ], [ 10, 10 ], [ 20, 20 ], [ 0, 0 ] ]
]
};
this.polygon.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
expect(this.polygon.toGeoJSON()).toEqual(newAndExpectedGeoJSON);
});
it('should trigger a "change" event', function () {
expect(this.changeCallback).toHaveBeenCalled();
});
it('should update the coordinates', function () {
expect(this.polygon.toGeoJSON()).toEqual({
type: 'Polygon',
coordinates: [
[ [ 0, 0 ], [ 10, 10 ], [ 20, 20 ], [ 0, 0 ] ]
]
});
});
});
});
});
@@ -0,0 +1,64 @@
var Polyline = require('../../../../src/geo/geometry-models/polyline');
describe('src/geo/geometry-models/polyline', function () {
beforeEach(function () {
this.polyline = new Polyline(null, {
latlngs: [
[-1, 1], [1, 2], [3, 4]
]
});
});
describe('.toGeoJSON', function () {
it('should generate the GeoJSON correctly', function () {
expect(this.polyline.toGeoJSON()).toEqual({
type: 'LineString',
coordinates: [
[ 1, -1 ], [ 2, 1 ], [ 4, 3 ]
]
});
});
});
describe('.setCoordinatesFromGeoJSON', function () {
beforeEach(function () {
this.changeCallback = jasmine.createSpy('changeCallback');
this.polyline.on('change', this.changeCallback);
});
describe('when given a GeoJSON with the same coordinates', function () {
beforeEach(function () {
var newAndExpectedGeoJSON = this.polyline.toGeoJSON();
this.polyline.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
});
it('should NOT trigger a "change" event', function () {
expect(this.changeCallback).not.toHaveBeenCalled();
});
});
describe('when given a GeoJSON with different coordinates', function () {
beforeEach(function () {
var newAndExpectedGeoJSON = {
type: 'LineString',
coordinates: [
[ 0, 0 ], [ 1, 1 ], [ 2, 2 ]
]
};
this.polyline.setCoordinatesFromGeoJSON(newAndExpectedGeoJSON);
expect(this.polyline.toGeoJSON()).toEqual(newAndExpectedGeoJSON);
});
it('should trigger a "change" event', function () {
expect(this.changeCallback).toHaveBeenCalled();
});
it('should update the coordinates', function () {
expect(this.polyline.toGeoJSON()).toEqual({
type: 'LineString',
coordinates: [ [ 0, 0 ], [ 1, 1 ], [ 2, 2 ] ]
});
});
});
});
});