Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Array traitment into latLngToCoords/latLngsToCoords #7436

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add Array traitment into latLngToCoords/latLngsToCoords
add array management into function latLngToCoords and coordsToLatLngs

Add array management into GeoJSON.latLngToCoords andGeoJSON.latLngToCoords
  • Loading branch information
Dorian Benedetti committed Jan 28, 2021
commit 9fbabe09343e12a293479c70812e421bd0512267
15 changes: 9 additions & 6 deletions src/layer/GeoJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Polyline} from './vector/Polyline';
import {Polygon} from './vector/Polygon';
import {LatLng} from '../geo/LatLng';
import * as LineUtil from '../geometry/LineUtil';
import {toLatLng} from '../geo/LatLng';


/*
Expand Down Expand Up @@ -257,21 +258,23 @@ export function coordsToLatLngs(coords, levelsDeep, _coordsToLatLng) {
// Reverse of [`coordsToLatLng`](#geojson-coordstolatlng)
export function latLngToCoords(latlng, precision) {
precision = typeof precision === 'number' ? precision : 6;
return latlng.alt !== undefined ?
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision), Util.formatNum(latlng.alt, precision)] :
[Util.formatNum(latlng.lng, precision), Util.formatNum(latlng.lat, precision)];
var Truelatlng = toLatLng(latlng);
return Truelatlng.alt !== undefined ?
[Util.formatNum(Truelatlng.lng, precision), Util.formatNum(Truelatlng.lat, precision), Util.formatNum(Truelatlng.alt, precision)] :
[Util.formatNum(Truelatlng.lng, precision), Util.formatNum(Truelatlng.lat, precision)];
}

// @function latLngsToCoords(latlngs: Array, levelsDeep?: Number, closed?: Boolean): Array
// Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs)
// `closed` determines whether the first point should be appended to the end of the array to close the feature, only used when `levelsDeep` is 0. False by default.
export function latLngsToCoords(latlngs, levelsDeep, closed, precision) {
var coords = [];

for (var i = 0, len = latlngs.length; i < len; i++) {
var latlng;
if (!levelsDeep) { latlng = toLatLng(latlngs[i]); } else { latlng = latlngs[i]; }
coords.push(levelsDeep ?
latLngsToCoords(latlngs[i], levelsDeep - 1, closed, precision) :
latLngToCoords(latlngs[i], precision));
latLngsToCoords(latlng, levelsDeep - 1, closed, precision) :
latLngToCoords(latlng, precision));
}

if (!levelsDeep && closed) {
Expand Down