2013-06-25 01:52:05 +08:00
|
|
|
describe("L.GeoJSON", function () {
|
2015-11-18 20:26:01 +08:00
|
|
|
|
2013-06-25 01:52:05 +08:00
|
|
|
describe("addData", function () {
|
2015-12-25 20:57:24 +08:00
|
|
|
var geojson = {
|
2013-06-25 01:52:05 +08:00
|
|
|
type: 'Feature',
|
2013-06-25 02:39:11 +08:00
|
|
|
properties: {},
|
2013-06-25 01:52:05 +08:00
|
|
|
geometry: {
|
|
|
|
type: 'Point',
|
2013-07-03 16:13:00 +08:00
|
|
|
coordinates: [20, 10, 5]
|
2013-06-25 01:52:05 +08:00
|
|
|
}
|
2015-12-25 20:57:24 +08:00
|
|
|
}, geojsonEmpty = {
|
2015-07-02 01:29:08 +08:00
|
|
|
type: 'Feature',
|
|
|
|
properties: {},
|
|
|
|
geometry: null
|
2013-06-25 01:52:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
it("sets feature property on member layers", function () {
|
|
|
|
var layer = new L.GeoJSON();
|
2015-12-25 20:57:24 +08:00
|
|
|
layer.addData(geojson);
|
|
|
|
expect(layer.getLayers()[0].feature).to.eql(geojson);
|
2013-06-25 01:52:05 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("normalizes a geometry to a Feature", function () {
|
|
|
|
var layer = new L.GeoJSON();
|
2015-12-25 20:57:24 +08:00
|
|
|
layer.addData(geojson.geometry);
|
|
|
|
expect(layer.getLayers()[0].feature).to.eql(geojson);
|
2013-06-25 01:52:05 +08:00
|
|
|
});
|
2015-07-02 01:29:08 +08:00
|
|
|
|
|
|
|
it("accepts geojson with null geometry", function () {
|
|
|
|
var layer = new L.GeoJSON();
|
2015-12-25 20:57:24 +08:00
|
|
|
layer.addData(geojsonEmpty);
|
2015-07-02 01:29:08 +08:00
|
|
|
expect(layer.getLayers().length).to.eql(0);
|
|
|
|
});
|
2013-06-25 01:52:05 +08:00
|
|
|
});
|
2015-11-18 20:26:01 +08:00
|
|
|
|
|
|
|
describe('resetStyle', function () {
|
|
|
|
|
|
|
|
it('should reset init options', function () {
|
|
|
|
var feature = {
|
|
|
|
type: 'Feature',
|
|
|
|
geometry: {
|
|
|
|
type: 'LineString',
|
|
|
|
coordinates:[[-2.35, 51.38], [-2.38, 51.38]]
|
|
|
|
}
|
|
|
|
};
|
2015-12-25 20:57:24 +08:00
|
|
|
var geojson = L.geoJSON(feature, {weight: 7, color: 'chocolate'});
|
2015-11-18 20:26:01 +08:00
|
|
|
geojson.setStyle({weight: 22, color: 'coral'});
|
|
|
|
var layer = geojson.getLayers()[0];
|
|
|
|
expect(layer.options.weight).to.be(22);
|
|
|
|
expect(layer.options.color).to.be('coral');
|
|
|
|
geojson.resetStyle(layer);
|
|
|
|
expect(layer.options.weight).to.be(7);
|
|
|
|
expect(layer.options.color).to.be('chocolate');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-06-25 01:52:05 +08:00
|
|
|
});
|
|
|
|
|
2013-02-27 06:54:58 +08:00
|
|
|
describe("L.Marker#toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D Point object", function () {
|
2013-02-27 06:54:58 +08:00
|
|
|
var marker = new L.Marker([10, 20]);
|
2013-06-25 01:52:05 +08:00
|
|
|
expect(marker.toGeoJSON().geometry).to.eql({
|
2013-02-27 06:54:58 +08:00
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D Point object", function () {
|
|
|
|
var marker = new L.Marker([10, 20, 30]);
|
|
|
|
expect(marker.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10, 30]
|
|
|
|
});
|
|
|
|
});
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
|
2013-06-26 00:43:22 +08:00
|
|
|
describe("L.Circle#toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D Point object", function () {
|
2013-06-26 00:43:22 +08:00
|
|
|
var circle = new L.Circle([10, 20], 100);
|
|
|
|
expect(circle.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D Point object", function () {
|
|
|
|
var circle = new L.Circle([10, 20, 30], 100);
|
|
|
|
expect(circle.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10, 30]
|
|
|
|
});
|
|
|
|
});
|
2013-06-26 00:43:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("L.CircleMarker#toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D Point object", function () {
|
2013-06-26 00:43:22 +08:00
|
|
|
var marker = new L.CircleMarker([10, 20]);
|
|
|
|
expect(marker.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D Point object", function () {
|
|
|
|
var marker = new L.CircleMarker([10, 20, 30]);
|
|
|
|
expect(marker.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10, 30]
|
|
|
|
});
|
|
|
|
});
|
2013-06-26 00:43:22 +08:00
|
|
|
});
|
|
|
|
|
2013-02-27 06:54:58 +08:00
|
|
|
describe("L.Polyline#toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D LineString object", function () {
|
2013-02-27 06:54:58 +08:00
|
|
|
var polyline = new L.Polyline([[10, 20], [2, 5]]);
|
2013-06-25 01:52:05 +08:00
|
|
|
expect(polyline.toGeoJSON().geometry).to.eql({
|
2013-02-27 06:54:58 +08:00
|
|
|
type: 'LineString',
|
|
|
|
coordinates: [[20, 10], [5, 2]]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D LineString object", function () {
|
|
|
|
var polyline = new L.Polyline([[10, 20, 30], [2, 5, 10]]);
|
|
|
|
expect(polyline.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'LineString',
|
|
|
|
coordinates: [[20, 10, 30], [5, 2, 10]]
|
|
|
|
});
|
|
|
|
});
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
|
2013-12-14 01:32:26 +08:00
|
|
|
describe("L.Polyline (multi) #toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D MultiLineString object", function () {
|
2013-12-14 01:32:26 +08:00
|
|
|
var multiPolyline = new L.Polyline([[[10, 20], [2, 5]], [[1, 2], [3, 4]]]);
|
2013-06-25 01:52:05 +08:00
|
|
|
expect(multiPolyline.toGeoJSON().geometry).to.eql({
|
2013-02-27 06:54:58 +08:00
|
|
|
type: 'MultiLineString',
|
|
|
|
coordinates: [
|
|
|
|
[[20, 10], [5, 2]],
|
|
|
|
[[2, 1], [4, 3]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D MultiLineString object", function () {
|
2013-12-14 01:32:26 +08:00
|
|
|
var multiPolyline = new L.Polyline([[[10, 20, 30], [2, 5, 10]], [[1, 2, 3], [4, 5, 6]]]);
|
2013-07-03 16:13:00 +08:00
|
|
|
expect(multiPolyline.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'MultiLineString',
|
|
|
|
coordinates: [
|
|
|
|
[[20, 10, 30], [5, 2, 10]],
|
|
|
|
[[2, 1, 3], [5, 4, 6]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("L.Polygon#toGeoJSON", function () {
|
2014-10-27 04:00:56 +08:00
|
|
|
it("returns a 2D Polygon object (no holes) from a flat LatLngs array", function () {
|
2013-02-27 06:54:58 +08:00
|
|
|
var polygon = new L.Polygon([[1, 2], [3, 4], [5, 6]]);
|
2013-06-25 01:52:05 +08:00
|
|
|
expect(polygon.toGeoJSON().geometry).to.eql({
|
2013-02-27 06:54:58 +08:00
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [[[2, 1], [4, 3], [6, 5], [2, 1]]]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-27 04:00:56 +08:00
|
|
|
it("returns a 3D Polygon object (no holes) from a flat LatLngs array", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
var polygon = new L.Polygon([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
|
|
|
|
expect(polygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [[[2, 1, 3], [5, 4, 6], [8, 7, 9], [2, 1, 3]]]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-10-27 04:00:56 +08:00
|
|
|
it("returns a 2D Polygon object from a simple GeoJSON like input", function () {
|
|
|
|
var multiPolygon = new L.Polygon([[[1, 2], [3, 4], [5, 6]]]);
|
|
|
|
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [
|
|
|
|
[[2, 1], [4, 3], [6, 5], [2, 1]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a 3D MultiPolygon object from a simple GeoJSON like input", function () {
|
|
|
|
var multiPolygon = new L.Polygon([[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]);
|
|
|
|
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [
|
|
|
|
[[2, 1, 3], [5, 4, 6], [8, 7, 9], [2, 1, 3]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D Polygon object (with holes)", function () {
|
2013-02-27 06:54:58 +08:00
|
|
|
var polygon = new L.Polygon([[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]);
|
2013-06-25 01:52:05 +08:00
|
|
|
expect(polygon.toGeoJSON().geometry).to.eql({
|
2013-02-27 06:54:58 +08:00
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [
|
|
|
|
[[2, 1], [4, 3], [6, 5], [2, 1]],
|
|
|
|
[[8, 7], [10, 9], [12, 11], [8, 7]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D Polygon object (with holes)", function () {
|
|
|
|
var polygon = new L.Polygon([[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[10, 11, 12], [13, 14, 15], [16, 17, 18]]]);
|
|
|
|
expect(polygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'Polygon',
|
|
|
|
coordinates: [
|
|
|
|
[[2, 1, 3], [5, 4, 6], [8, 7, 9], [2, 1, 3]],
|
|
|
|
[[11, 10, 12], [14, 13, 15], [17, 16, 18], [11, 10, 12]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2014-10-27 04:00:56 +08:00
|
|
|
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
|
2013-12-14 01:32:26 +08:00
|
|
|
describe("L.Polygon (multi) #toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D MultiPolygon object", function () {
|
2014-10-27 04:00:56 +08:00
|
|
|
var multiPolygon = new L.Polygon([[[[1, 2], [3, 4], [5, 6]]]]);
|
2013-06-25 01:52:05 +08:00
|
|
|
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
2013-02-27 06:54:58 +08:00
|
|
|
type: 'MultiPolygon',
|
|
|
|
coordinates: [
|
|
|
|
[[[2, 1], [4, 3], [6, 5], [2, 1]]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2013-07-03 16:13:00 +08:00
|
|
|
|
|
|
|
it("returns a 3D MultiPolygon object", function () {
|
2014-10-27 04:00:56 +08:00
|
|
|
var multiPolygon = new L.Polygon([[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]]]);
|
2013-07-03 16:13:00 +08:00
|
|
|
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'MultiPolygon',
|
|
|
|
coordinates: [
|
|
|
|
[[[2, 1, 3], [5, 4, 6], [8, 7, 9], [2, 1, 3]]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
2014-10-27 04:00:56 +08:00
|
|
|
|
|
|
|
it("returns a 2D MultiPolygon object with two polygons", function () {
|
|
|
|
var multiPolygon = new L.Polygon([[[[1, 2], [3, 4], [5, 6]]], [[[7, 8], [9, 10], [11, 12]]]]);
|
|
|
|
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'MultiPolygon',
|
|
|
|
coordinates: [
|
|
|
|
[[[2, 1], [4, 3], [6, 5], [2, 1]]],
|
|
|
|
[[[8, 7], [10, 9], [12, 11], [8, 7]]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a 2D MultiPolygon object with polygon having a hole", function () {
|
|
|
|
var multiPolygon = new L.Polygon([[[[1, 2], [3, 4], [5, 6]], [[7, 8], [9, 10], [11, 12]]]]);
|
|
|
|
expect(multiPolygon.toGeoJSON().geometry).to.eql({
|
|
|
|
type: 'MultiPolygon',
|
|
|
|
coordinates: [
|
|
|
|
[[[2, 1], [4, 3], [6, 5], [2, 1]], [[8, 7], [10, 9], [12, 11], [8, 7]]]
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe("L.LayerGroup#toGeoJSON", function () {
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 2D FeatureCollection object", function () {
|
2013-02-27 06:54:58 +08:00
|
|
|
var marker = new L.Marker([10, 20]),
|
|
|
|
polyline = new L.Polyline([[10, 20], [2, 5]]),
|
|
|
|
layerGroup = new L.LayerGroup([marker, polyline]);
|
2013-04-05 00:47:45 +08:00
|
|
|
expect(layerGroup.toGeoJSON()).to.eql({
|
2013-06-25 01:52:05 +08:00
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: [marker.toGeoJSON(), polyline.toGeoJSON()]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-03 16:13:00 +08:00
|
|
|
it("returns a 3D FeatureCollection object", function () {
|
|
|
|
var marker = new L.Marker([10, 20, 30]),
|
2015-09-25 18:55:37 +08:00
|
|
|
polyline = new L.Polyline([[10, 20, 30], [2, 5, 10]]),
|
|
|
|
layerGroup = new L.LayerGroup([marker, polyline]);
|
2013-07-03 16:13:00 +08:00
|
|
|
expect(layerGroup.toGeoJSON()).to.eql({
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: [marker.toGeoJSON(), polyline.toGeoJSON()]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-06-25 01:52:05 +08:00
|
|
|
it("ensures that every member is a Feature", function () {
|
|
|
|
var tileLayer = new L.TileLayer(),
|
|
|
|
layerGroup = new L.LayerGroup([tileLayer]);
|
|
|
|
|
|
|
|
tileLayer.toGeoJSON = function () {
|
|
|
|
return {
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10]
|
2013-11-08 05:54:33 +08:00
|
|
|
};
|
2013-06-25 01:52:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(layerGroup.toGeoJSON()).to.eql({
|
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: [{
|
|
|
|
type: 'Feature',
|
|
|
|
properties: {},
|
|
|
|
geometry: {
|
|
|
|
type: 'Point',
|
|
|
|
coordinates: [20, 10]
|
|
|
|
}
|
|
|
|
}]
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-28 17:43:04 +08:00
|
|
|
it('roundtrips GeometryCollection features', function () {
|
|
|
|
var json = {
|
|
|
|
"type": "FeatureCollection",
|
|
|
|
"features": [{
|
|
|
|
"type": "Feature",
|
|
|
|
"geometry": {
|
|
|
|
"type": "GeometryCollection",
|
|
|
|
"geometries": [{
|
|
|
|
"type": "LineString",
|
|
|
|
"coordinates": [[-122.4425587930444, 37.80666418607323], [-122.4428379594768, 37.80663578323093]]
|
|
|
|
}, {
|
|
|
|
"type": "LineString",
|
|
|
|
"coordinates": [
|
|
|
|
[-122.4425509770566, 37.80662588061205],
|
|
|
|
[-122.4428340530617, 37.8065999493009]
|
|
|
|
]
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"name": "SF Marina Harbor Master"
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2015-12-25 20:57:24 +08:00
|
|
|
expect(L.geoJSON(json).toGeoJSON()).to.eql(json);
|
2013-08-28 17:43:04 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('roundtrips MiltiPoint features', function () {
|
|
|
|
var json = {
|
|
|
|
"type": "FeatureCollection",
|
|
|
|
"features": [{
|
|
|
|
"type": "Feature",
|
|
|
|
"geometry": {
|
|
|
|
"type": "MultiPoint",
|
|
|
|
"coordinates": [[-122.4425587930444, 37.80666418607323], [-122.4428379594768, 37.80663578323093]]
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"name": "Test MultiPoints"
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2015-12-25 20:57:24 +08:00
|
|
|
expect(L.geoJSON(json).toGeoJSON()).to.eql(json);
|
2013-08-28 17:43:04 +08:00
|
|
|
});
|
|
|
|
|
2013-02-27 06:54:58 +08:00
|
|
|
it("omits layers which do not implement toGeoJSON", function () {
|
|
|
|
var tileLayer = new L.TileLayer(),
|
|
|
|
layerGroup = new L.LayerGroup([tileLayer]);
|
2013-04-05 00:47:45 +08:00
|
|
|
expect(layerGroup.toGeoJSON()).to.eql({
|
2013-06-25 01:52:05 +08:00
|
|
|
type: 'FeatureCollection',
|
|
|
|
features: []
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|
|
|
|
});
|
2017-03-02 20:21:56 +08:00
|
|
|
|
|
|
|
it('should return only one FeatureCollection for nested LayerGroups', function () {
|
|
|
|
var layerGroup = new L.LayerGroup([
|
|
|
|
new L.LayerGroup([new L.Marker([-41.3330287, 173.2008273])]),
|
|
|
|
new L.Marker([-41.273356, 173.287278])
|
|
|
|
]);
|
|
|
|
|
|
|
|
var geoJSON = layerGroup.toGeoJSON();
|
|
|
|
|
|
|
|
expect(geoJSON.features.length).to.eql(2);
|
|
|
|
expect(geoJSON.features[0].type).to.eql("Feature");
|
|
|
|
expect(geoJSON.features[1].type).to.eql("Feature");
|
|
|
|
});
|
2013-02-27 06:54:58 +08:00
|
|
|
});
|