mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Convert lodah-es and d3 to named imports for osm
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import _ from 'lodash';
|
||||
import _compact from 'lodash-es/compact';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _filter from 'lodash-es/filter';
|
||||
import _find from 'lodash-es/find';
|
||||
import _map from 'lodash-es/map';
|
||||
import _values from 'lodash-es/values';
|
||||
|
||||
import { osmEntity } from './entity';
|
||||
import { geoExtent } from '../geo';
|
||||
|
||||
@@ -16,7 +22,7 @@ osmEntity.changeset = osmChangeset;
|
||||
|
||||
osmChangeset.prototype = Object.create(osmEntity.prototype);
|
||||
|
||||
_.extend(osmChangeset.prototype, {
|
||||
_extend(osmChangeset.prototype, {
|
||||
|
||||
type: 'changeset',
|
||||
|
||||
@@ -35,7 +41,7 @@ _.extend(osmChangeset.prototype, {
|
||||
return {
|
||||
osm: {
|
||||
changeset: {
|
||||
tag: _.map(this.tags, function(value, key) {
|
||||
tag: _map(this.tags, function(value, key) {
|
||||
return { '@k': key, '@v': value };
|
||||
}),
|
||||
'@version': 0.6,
|
||||
@@ -71,7 +77,7 @@ _.extend(osmChangeset.prototype, {
|
||||
|
||||
// find a referenced relation in the current changeset
|
||||
function resolve(item) {
|
||||
return _.find(relations, function(relation) {
|
||||
return _find(relations, function(relation) {
|
||||
return item.keyAttributes.type === 'relation'
|
||||
&& item.keyAttributes.ref === relation['@id'];
|
||||
});
|
||||
@@ -79,7 +85,7 @@ _.extend(osmChangeset.prototype, {
|
||||
|
||||
// a new item is an item that has not been already processed
|
||||
function isNew(item) {
|
||||
return !sorted[ item['@id'] ] && !_.find(processing, function(proc) {
|
||||
return !sorted[ item['@id'] ] && !_find(processing, function(proc) {
|
||||
return proc['@id'] === item['@id'];
|
||||
});
|
||||
}
|
||||
@@ -100,7 +106,7 @@ _.extend(osmChangeset.prototype, {
|
||||
|
||||
while (processing.length > 0) {
|
||||
var next = processing[0],
|
||||
deps = _.filter(_.compact(next.member.map(resolve)), isNew);
|
||||
deps = _filter(_compact(next.member.map(resolve)), isNew);
|
||||
if (deps.length === 0) {
|
||||
sorted[next['@id']] = next;
|
||||
processing.shift();
|
||||
@@ -110,7 +116,7 @@ _.extend(osmChangeset.prototype, {
|
||||
}
|
||||
}
|
||||
|
||||
changes.relation = _.values(sorted);
|
||||
changes.relation = _values(sorted);
|
||||
return changes;
|
||||
}
|
||||
|
||||
@@ -124,7 +130,7 @@ _.extend(osmChangeset.prototype, {
|
||||
'@generator': 'iD',
|
||||
'create': sort(nest(changes.created.map(rep), ['node', 'way', 'relation'])),
|
||||
'modify': nest(changes.modified.map(rep), ['node', 'way', 'relation']),
|
||||
'delete': _.extend(nest(changes.deleted.map(rep), ['relation', 'way', 'node']), { '@if-unused': true })
|
||||
'delete': _extend(nest(changes.deleted.map(rep), ['relation', 'way', 'node']), { '@if-unused': true })
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
import _clone from 'lodash-es/clone';
|
||||
import _keys from 'lodash-es/keys';
|
||||
import _toPairs from 'lodash-es/toPairs';
|
||||
import _union from 'lodash-es/union';
|
||||
import _without from 'lodash-es/without';
|
||||
|
||||
import { debug } from '../index';
|
||||
import { osmIsInterestingTag } from './tags';
|
||||
import { dataDeprecated } from '../../data/index';
|
||||
@@ -117,7 +122,7 @@ osmEntity.prototype = {
|
||||
|
||||
|
||||
mergeTags: function(tags) {
|
||||
var merged = _.clone(this.tags), changed = false;
|
||||
var merged = _clone(this.tags), changed = false;
|
||||
for (var k in tags) {
|
||||
var t1 = merged[k],
|
||||
t2 = tags[k];
|
||||
@@ -126,7 +131,7 @@ osmEntity.prototype = {
|
||||
merged[k] = t2;
|
||||
} else if (t1 !== t2) {
|
||||
changed = true;
|
||||
merged[k] = _.union(t1.split(/;\s*/), t2.split(/;\s*/)).join(';');
|
||||
merged[k] = _union(t1.split(/;\s*/), t2.split(/;\s*/)).join(';');
|
||||
}
|
||||
}
|
||||
return changed ? this.update({tags: merged}) : this;
|
||||
@@ -139,13 +144,13 @@ osmEntity.prototype = {
|
||||
|
||||
|
||||
isUsed: function(resolver) {
|
||||
return _.without(Object.keys(this.tags), 'area').length > 0 ||
|
||||
return _without(Object.keys(this.tags), 'area').length > 0 ||
|
||||
resolver.parentRelations(this).length > 0;
|
||||
},
|
||||
|
||||
|
||||
hasInterestingTags: function() {
|
||||
return _.keys(this.tags).some(osmIsInterestingTag);
|
||||
return _keys(this.tags).some(osmIsInterestingTag);
|
||||
},
|
||||
|
||||
|
||||
@@ -158,11 +163,11 @@ osmEntity.prototype = {
|
||||
},
|
||||
|
||||
deprecatedTags: function() {
|
||||
var tags = _.toPairs(this.tags);
|
||||
var tags = _toPairs(this.tags);
|
||||
var deprecated = {};
|
||||
|
||||
dataDeprecated.forEach(function(d) {
|
||||
var match = _.toPairs(d.old)[0];
|
||||
var match = _toPairs(d.old)[0];
|
||||
tags.forEach(function(t) {
|
||||
if (t[0] === match[0] &&
|
||||
(t[1] === match[1] || match[1] === '*')) {
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import _ from 'lodash';
|
||||
import _each from 'lodash-es/each';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _find from 'lodash-es/find';
|
||||
import _indexOf from 'lodash-es/indexOf';
|
||||
import _keys from 'lodash-es/keys';
|
||||
import _values from 'lodash-es/values';
|
||||
|
||||
import { geoAngle } from '../geo/index';
|
||||
import { osmWay } from './way';
|
||||
|
||||
@@ -6,7 +12,7 @@ import { osmWay } from './way';
|
||||
export function osmTurn(turn) {
|
||||
if (!(this instanceof osmTurn))
|
||||
return new osmTurn(turn);
|
||||
_.extend(this, turn);
|
||||
_extend(this, turn);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +55,7 @@ export function osmIntersection(graph, vertexId) {
|
||||
indexA = 1;
|
||||
indexB = way.nodes.length - 2;
|
||||
} else {
|
||||
splitIndex = _.indexOf(way.nodes, vertex.id, 1); // split at vertexid
|
||||
splitIndex = _indexOf(way.nodes, vertex.id, 1); // split at vertexid
|
||||
wayA = osmWay({id: way.id + '-a', tags: way.tags, nodes: way.nodes.slice(0, splitIndex + 1)});
|
||||
wayB = osmWay({id: way.id + '-b', tags: way.tags, nodes: way.nodes.slice(splitIndex)});
|
||||
indexA = splitIndex - 1;
|
||||
@@ -70,13 +76,13 @@ export function osmIntersection(graph, vertexId) {
|
||||
|
||||
var intersection = {
|
||||
highways: highways,
|
||||
ways: _.values(highways),
|
||||
ways: _values(highways),
|
||||
graph: graph
|
||||
};
|
||||
|
||||
|
||||
intersection.adjacentNodeId = function(fromWayId) {
|
||||
return _.find(_.keys(highways), function(k) {
|
||||
return _find(_keys(highways), function(k) {
|
||||
return highways[k].id === fromWayId;
|
||||
});
|
||||
};
|
||||
@@ -125,7 +131,7 @@ export function osmIntersection(graph, vertexId) {
|
||||
via = { node: vertex.id },
|
||||
turns = [];
|
||||
|
||||
_.each(highways, function(end, adjacentNodeId) {
|
||||
_each(highways, function(end, adjacentNodeId) {
|
||||
if (end === start)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import _isNumber from 'lodash-es/isNumber';
|
||||
import _isString from 'lodash-es/isString';
|
||||
import _isNaN from 'lodash-es/isNaN';
|
||||
|
||||
|
||||
export function osmLanes(entity) {
|
||||
@@ -120,8 +122,8 @@ function getLaneCount(tags, isOneWay) {
|
||||
|
||||
function parseMaxspeed(tags) {
|
||||
var maxspeed = tags.maxspeed;
|
||||
if (_.isNumber(maxspeed)) return maxspeed;
|
||||
if (_.isString(maxspeed)) {
|
||||
if (_isNumber(maxspeed)) return maxspeed;
|
||||
if (_isString(maxspeed)) {
|
||||
maxspeed = maxspeed.match(/^([0-9][\.0-9]+?)(?:[ ]?(?:km\/h|kmh|kph|mph|knots))?$/g);
|
||||
if (!maxspeed) return;
|
||||
return parseInt(maxspeed, 10);
|
||||
@@ -144,17 +146,17 @@ function parseLaneDirections(tags, isOneWay, laneCount) {
|
||||
bothways = 0;
|
||||
backward = 0;
|
||||
}
|
||||
else if (_.isNaN(forward) && _.isNaN(backward)) {
|
||||
else if (_isNaN(forward) && _isNaN(backward)) {
|
||||
backward = Math.floor((laneCount - bothways) / 2);
|
||||
forward = laneCount - bothways - backward;
|
||||
}
|
||||
else if (_.isNaN(forward)) {
|
||||
else if (_isNaN(forward)) {
|
||||
if (backward > laneCount - bothways) {
|
||||
backward = laneCount - bothways;
|
||||
}
|
||||
forward = laneCount - bothways - backward;
|
||||
}
|
||||
else if (_.isNaN(backward)) {
|
||||
else if (_isNaN(backward)) {
|
||||
if (forward > laneCount - bothways) {
|
||||
forward = laneCount - bothways;
|
||||
}
|
||||
@@ -195,7 +197,7 @@ function parseMaxspeedLanes(tag, maxspeed) {
|
||||
if (s === 'none') return s;
|
||||
var m = parseInt(s, 10);
|
||||
if (s === '' || m === maxspeed) return null;
|
||||
return _.isNaN(m) ? 'unknown': m;
|
||||
return _isNaN(m) ? 'unknown': m;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import _ from 'lodash';
|
||||
import { actionReverse } from '../actions/reverse';
|
||||
import { osmIsInterestingTag } from './tags';
|
||||
|
||||
@@ -104,28 +103,28 @@ export function osmJoinWays(array, graph) {
|
||||
current.nodes = nodes = resolve(member).slice();
|
||||
joined.push(current);
|
||||
|
||||
while (array.length && _.first(nodes) !== _.last(nodes)) {
|
||||
first = _.first(nodes);
|
||||
last = _.last(nodes);
|
||||
while (array.length && nodes[0] !== nodes[nodes.length - 1]) {
|
||||
first = nodes[0];
|
||||
last = nodes[nodes.length - 1];
|
||||
|
||||
for (i = 0; i < array.length; i++) {
|
||||
member = array[i];
|
||||
what = resolve(member);
|
||||
|
||||
if (last === _.first(what)) {
|
||||
if (last === what[0]) {
|
||||
how = nodes.push;
|
||||
what = what.slice(1);
|
||||
break;
|
||||
} else if (last === _.last(what)) {
|
||||
} else if (last === what[what.length - 1]) {
|
||||
how = nodes.push;
|
||||
what = what.slice(0, -1).reverse();
|
||||
member = reverse(member);
|
||||
break;
|
||||
} else if (first === _.last(what)) {
|
||||
} else if (first === what[what.length - 1]) {
|
||||
how = nodes.unshift;
|
||||
what = what.slice(0, -1);
|
||||
break;
|
||||
} else if (first === _.first(what)) {
|
||||
} else if (first === what[0]) {
|
||||
how = nodes.unshift;
|
||||
what = what.slice(1).reverse();
|
||||
member = reverse(member);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import _ from 'lodash';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _map from 'lodash-es/map';
|
||||
import _some from 'lodash-es/some';
|
||||
|
||||
import { osmEntity } from './entity';
|
||||
import { geoExtent } from '../geo/index';
|
||||
import { geoExtent } from '../geo';
|
||||
|
||||
|
||||
export function osmNode() {
|
||||
if (!(this instanceof osmNode)) {
|
||||
@@ -14,7 +18,7 @@ osmEntity.node = osmNode;
|
||||
|
||||
osmNode.prototype = Object.create(osmEntity.prototype);
|
||||
|
||||
_.extend(osmNode.prototype, {
|
||||
_extend(osmNode.prototype, {
|
||||
|
||||
type: 'node',
|
||||
|
||||
@@ -65,7 +69,7 @@ _.extend(osmNode.prototype, {
|
||||
}
|
||||
|
||||
// vertex is connected to multiple parent lines
|
||||
if (parents.length > 1 && _.some(parents, isLine)) {
|
||||
if (parents.length > 1 && _some(parents, isLine)) {
|
||||
return true;
|
||||
|
||||
} else if (parents.length === 1) {
|
||||
@@ -121,7 +125,7 @@ _.extend(osmNode.prototype, {
|
||||
'@lon': this.loc[0],
|
||||
'@lat': this.loc[1],
|
||||
'@version': (this.version || 0),
|
||||
tag: _.map(this.tags, function(v, k) {
|
||||
tag: _map(this.tags, function(v, k) {
|
||||
return { keyAttributes: { k: k, v: v } };
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import * as d3 from 'd3';
|
||||
import _ from 'lodash';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _map from 'lodash-es/map';
|
||||
import _reject from 'lodash-es/reject';
|
||||
|
||||
import { geoArea as d3_geoArea } from 'd3-geo';
|
||||
|
||||
import { osmEntity } from './entity';
|
||||
import { osmJoinWays } from './multipolygon';
|
||||
import {
|
||||
geoExtent,
|
||||
geoPolygonContainsPolygon,
|
||||
geoPolygonIntersectsPolygon
|
||||
} from '../geo/index';
|
||||
} from '../geo';
|
||||
|
||||
|
||||
export function osmRelation() {
|
||||
@@ -32,7 +36,7 @@ osmRelation.creationOrder = function(a, b) {
|
||||
};
|
||||
|
||||
|
||||
_.extend(osmRelation.prototype, {
|
||||
_extend(osmRelation.prototype, {
|
||||
type: 'relation',
|
||||
members: [],
|
||||
|
||||
@@ -44,7 +48,7 @@ _.extend(osmRelation.prototype, {
|
||||
var copy = osmEntity.prototype.copy.call(this, resolver, copies);
|
||||
|
||||
var members = this.members.map(function(member) {
|
||||
return _.extend({}, member, { id: resolver.entity(member.id).copy(resolver, copies).id });
|
||||
return _extend({}, member, { id: resolver.entity(member.id).copy(resolver, copies).id });
|
||||
});
|
||||
|
||||
copy = copy.update({members: members});
|
||||
@@ -89,7 +93,7 @@ _.extend(osmRelation.prototype, {
|
||||
indexedMembers: function() {
|
||||
var result = new Array(this.members.length);
|
||||
for (var i = 0; i < this.members.length; i++) {
|
||||
result[i] = _.extend({}, this.members[i], {index: i});
|
||||
result[i] = _extend({}, this.members[i], {index: i});
|
||||
}
|
||||
return result;
|
||||
},
|
||||
@@ -100,7 +104,7 @@ _.extend(osmRelation.prototype, {
|
||||
memberByRole: function(role) {
|
||||
for (var i = 0; i < this.members.length; i++) {
|
||||
if (this.members[i].role === role) {
|
||||
return _.extend({}, this.members[i], {index: i});
|
||||
return _extend({}, this.members[i], {index: i});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -111,7 +115,7 @@ _.extend(osmRelation.prototype, {
|
||||
memberById: function(id) {
|
||||
for (var i = 0; i < this.members.length; i++) {
|
||||
if (this.members[i].id === id) {
|
||||
return _.extend({}, this.members[i], {index: i});
|
||||
return _extend({}, this.members[i], {index: i});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -122,7 +126,7 @@ _.extend(osmRelation.prototype, {
|
||||
memberByIdAndRole: function(id, role) {
|
||||
for (var i = 0; i < this.members.length; i++) {
|
||||
if (this.members[i].id === id && this.members[i].role === role) {
|
||||
return _.extend({}, this.members[i], {index: i});
|
||||
return _extend({}, this.members[i], {index: i});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -137,7 +141,7 @@ _.extend(osmRelation.prototype, {
|
||||
|
||||
updateMember: function(member, index) {
|
||||
var members = this.members.slice();
|
||||
members.splice(index, 1, _.extend({}, members[index], member));
|
||||
members.splice(index, 1, _extend({}, members[index], member));
|
||||
return this.update({members: members});
|
||||
},
|
||||
|
||||
@@ -150,7 +154,7 @@ _.extend(osmRelation.prototype, {
|
||||
|
||||
|
||||
removeMembersWithID: function(id) {
|
||||
var members = _.reject(this.members, function(m) { return m.id === id; });
|
||||
var members = _reject(this.members, function(m) { return m.id === id; });
|
||||
return this.update({members: members});
|
||||
},
|
||||
|
||||
@@ -183,7 +187,7 @@ _.extend(osmRelation.prototype, {
|
||||
relation: {
|
||||
'@id': this.osmId(),
|
||||
'@version': this.version || 0,
|
||||
member: _.map(this.members, function(member) {
|
||||
member: _map(this.members, function(member) {
|
||||
return {
|
||||
keyAttributes: {
|
||||
type: member.type,
|
||||
@@ -192,7 +196,7 @@ _.extend(osmRelation.prototype, {
|
||||
}
|
||||
};
|
||||
}),
|
||||
tag: _.map(this.tags, function(v, k) {
|
||||
tag: _map(this.tags, function(v, k) {
|
||||
return { keyAttributes: { k: k, v: v } };
|
||||
})
|
||||
}
|
||||
@@ -214,7 +218,7 @@ _.extend(osmRelation.prototype, {
|
||||
type: 'FeatureCollection',
|
||||
properties: this.tags,
|
||||
features: this.members.map(function (member) {
|
||||
return _.extend({role: member.role}, resolver.entity(member.id).asGeoJSON(resolver));
|
||||
return _extend({role: member.role}, resolver.entity(member.id).asGeoJSON(resolver));
|
||||
})
|
||||
};
|
||||
}
|
||||
@@ -224,7 +228,7 @@ _.extend(osmRelation.prototype, {
|
||||
|
||||
area: function(resolver) {
|
||||
return resolver.transient(this, 'area', function() {
|
||||
return d3.geoArea(this.asGeoJSON(resolver));
|
||||
return d3_geoArea(this.asGeoJSON(resolver));
|
||||
});
|
||||
},
|
||||
|
||||
@@ -266,13 +270,13 @@ _.extend(osmRelation.prototype, {
|
||||
outers = osmJoinWays(outers, resolver);
|
||||
inners = osmJoinWays(inners, resolver);
|
||||
|
||||
outers = outers.map(function(outer) { return _.map(outer.nodes, 'loc'); });
|
||||
inners = inners.map(function(inner) { return _.map(inner.nodes, 'loc'); });
|
||||
outers = outers.map(function(outer) { return _map(outer.nodes, 'loc'); });
|
||||
inners = inners.map(function(inner) { return _map(inner.nodes, 'loc'); });
|
||||
|
||||
var result = outers.map(function(o) {
|
||||
// Heuristic for detecting counterclockwise winding order. Assumes
|
||||
// that OpenStreetMap polygons are not hemisphere-spanning.
|
||||
return [d3.geoArea({ type: 'Polygon', coordinates: [o] }) > 2 * Math.PI ? o.reverse() : o];
|
||||
return [d3_geoArea({ type: 'Polygon', coordinates: [o] }) > 2 * Math.PI ? o.reverse() : o];
|
||||
});
|
||||
|
||||
function findOuter(inner) {
|
||||
@@ -294,7 +298,7 @@ _.extend(osmRelation.prototype, {
|
||||
for (var i = 0; i < inners.length; i++) {
|
||||
var inner = inners[i];
|
||||
|
||||
if (d3.geoArea({ type: 'Polygon', coordinates: [inner] }) < 2 * Math.PI) {
|
||||
if (d3_geoArea({ type: 'Polygon', coordinates: [inner] }) < 2 * Math.PI) {
|
||||
inner = inner.reverse();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import * as d3 from 'd3';
|
||||
import _ from 'lodash';
|
||||
import { geoExtent, geoCross } from '../geo/index';
|
||||
import _extend from 'lodash-es/extend';
|
||||
import _map from 'lodash-es/map';
|
||||
import _uniq from 'lodash-es/uniq';
|
||||
|
||||
import { geoArea as d3_geoArea } from 'd3-geo';
|
||||
|
||||
import { geoExtent, geoCross } from '../geo';
|
||||
import { osmEntity } from './entity';
|
||||
import { osmLanes } from './lanes';
|
||||
import { osmOneWayTags } from './tags';
|
||||
@@ -21,7 +25,7 @@ osmEntity.way = osmWay;
|
||||
osmWay.prototype = Object.create(osmEntity.prototype);
|
||||
|
||||
|
||||
_.extend(osmWay.prototype, {
|
||||
_extend(osmWay.prototype, {
|
||||
type: 'way',
|
||||
nodes: [],
|
||||
|
||||
@@ -129,8 +133,8 @@ _.extend(osmWay.prototype, {
|
||||
isConvex: function(resolver) {
|
||||
if (!this.isClosed() || this.isDegenerate()) return null;
|
||||
|
||||
var nodes = _.uniq(resolver.childNodes(this)),
|
||||
coords = _.map(nodes, 'loc'),
|
||||
var nodes = _uniq(resolver.childNodes(this)),
|
||||
coords = _map(nodes, 'loc'),
|
||||
curr = 0, prev = 0;
|
||||
|
||||
for (var i = 0; i < coords.length; i++) {
|
||||
@@ -186,7 +190,7 @@ _.extend(osmWay.prototype, {
|
||||
|
||||
|
||||
isDegenerate: function() {
|
||||
return _.uniq(this.nodes).length < (this.isArea() ? 3 : 2);
|
||||
return _uniq(this.nodes).length < (this.isArea() ? 3 : 2);
|
||||
},
|
||||
|
||||
|
||||
@@ -383,10 +387,10 @@ _.extend(osmWay.prototype, {
|
||||
way: {
|
||||
'@id': this.osmId(),
|
||||
'@version': this.version || 0,
|
||||
nd: _.map(this.nodes, function(id) {
|
||||
nd: _map(this.nodes, function(id) {
|
||||
return { keyAttributes: { ref: osmEntity.id.toOSM(id) } };
|
||||
}),
|
||||
tag: _.map(this.tags, function(v, k) {
|
||||
tag: _map(this.tags, function(v, k) {
|
||||
return { keyAttributes: { k: k, v: v } };
|
||||
})
|
||||
}
|
||||
@@ -400,7 +404,7 @@ _.extend(osmWay.prototype, {
|
||||
|
||||
asGeoJSON: function(resolver) {
|
||||
return resolver.transient(this, 'GeoJSON', function() {
|
||||
var coordinates = _.map(resolver.childNodes(this), 'loc');
|
||||
var coordinates = _map(resolver.childNodes(this), 'loc');
|
||||
if (this.isArea() && this.isClosed()) {
|
||||
return {
|
||||
type: 'Polygon',
|
||||
@@ -422,20 +426,20 @@ _.extend(osmWay.prototype, {
|
||||
|
||||
var json = {
|
||||
type: 'Polygon',
|
||||
coordinates: [_.map(nodes, 'loc')]
|
||||
coordinates: [_map(nodes, 'loc')]
|
||||
};
|
||||
|
||||
if (!this.isClosed() && nodes.length) {
|
||||
json.coordinates[0].push(nodes[0].loc);
|
||||
}
|
||||
|
||||
var area = d3.geoArea(json);
|
||||
var area = d3_geoArea(json);
|
||||
|
||||
// Heuristic for detecting counterclockwise winding order. Assumes
|
||||
// that OpenStreetMap polygons are not hemisphere-spanning.
|
||||
if (area > 2 * Math.PI) {
|
||||
json.coordinates[0] = json.coordinates[0].reverse();
|
||||
area = d3.geoArea(json);
|
||||
area = d3_geoArea(json);
|
||||
}
|
||||
|
||||
return isNaN(area) ? 0 : area;
|
||||
|
||||
Reference in New Issue
Block a user