Skip to content

Commit b3e1b24

Browse files
RelkfawDorian BenedettiFalke-Design
authored
Allow raw latlng array in latLngToCoords/latLngsToCoords (#7436)
* Add Array traitment into latLngToCoords/latLngsToCoords add array management into function latLngToCoords and coordsToLatLngs Add array management into GeoJSON.latLngToCoords andGeoJSON.latLngToCoords * Add tests * minify code * remove redundant code * revert change Co-authored-by: Dorian Benedetti <dorian.benedetti@etu.u-bordeaux.fr> Co-authored-by: Florian Bischof <design.falke@gmail.com>
1 parent 25546fc commit b3e1b24

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

spec/suites/layer/GeoJSONSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ describe("L.GeoJSON functions", function () {
752752
});
753753

754754
describe("#latLngToCoords", function () {
755+
it("accepts latlng array", function () {
756+
var coords = L.GeoJSON.latLngToCoords([2, 1, 3]);
757+
expect(coords).to.eql([1, 2, 3]);
758+
});
759+
755760
it("returns an array of coordinates and altitude", function () {
756761
var coords = L.GeoJSON.latLngToCoords(L.latLng(2, 1));
757762
var coordsWithAlt = L.GeoJSON.latLngToCoords(L.latLng(2, 1, 3));
@@ -772,6 +777,11 @@ describe("L.GeoJSON functions", function () {
772777
});
773778

774779
describe("#latLngsToCoords", function () {
780+
it("accepts multidimensional latlng array", function () {
781+
var coords = L.GeoJSON.latLngsToCoords([[2, 1, 3], [5, 4, 6]]);
782+
expect(coords).to.eql([[1, 2, 3], [4, 5, 6]]);
783+
});
784+
775785
it("returns a multidimensional array of coordinates", function () {
776786
var coords = L.GeoJSON.latLngsToCoords([L.latLng(2, 1), L.latLng(4, 3)]);
777787
var coordWithAlt = L.GeoJSON.latLngsToCoords([L.latLng(2, 1, 3), L.latLng(5, 4, 6)]);

src/layer/GeoJSON.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {Polyline} from './vector/Polyline';
88
import {Polygon} from './vector/Polygon';
99
import {LatLng} from '../geo/LatLng';
1010
import * as LineUtil from '../geometry/LineUtil';
11+
import {toLatLng} from '../geo/LatLng';
1112

1213

1314
/*
@@ -257,6 +258,7 @@ export function coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {
257258
// Reverse of [`coordsToLatLng`](#geojson-coordstolatlng)
258259
// Coordinates values are rounded with [`formatNum`](#util-formatnum) function.
259260
export function latLngToCoords(latlng, precision) {
261+
latlng = toLatLng(latlng);
260262
return latlng.alt !== undefined ?
261263
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :
262264
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];

0 commit comments

Comments
 (0)