- for (var i = 0; i < results.elements.length; i++) {
- var element = results.elements[i],
- geometry = featureGeometry(element, features);
+ if (merge) {
+ elements = results.elements.reduce(function (hash, element) {
+ var key = element.type + element.id;
+ if ("geometry" in element) {
+ delete element.bounds;
+ }
+ hash[key] = $.extend({}, hash[key], element);
+ return hash;
+ }, {});
+
+ elements = Object.keys(elements).map(function (key) {
+ return elements[key];
+ });
+ } else {
+ elements = results.elements;
+ }
+
+ if (compare) {
+ elements = elements.sort(compare);
+ }
+
+ for (var i = 0; i < elements.length; i++) {
+ var element = elements[i];