Skip to content

Commit cb95a78

Browse files
committed
Feature collection from array
1 parent 8d69310 commit cb95a78

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main/java/org/geoscript/js/feature/FeatureCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ public SimpleFeature next() throws NoSuchElementException {
323323
if (hasNext()) {
324324
++current;
325325
Object obj = array.get(current, array);
326-
if (obj instanceof SimpleFeature) {
327-
feature = (SimpleFeature) obj;
326+
if (obj instanceof Feature) {
327+
feature = (SimpleFeature) ((Feature) obj).unwrap();
328328
} else if (obj instanceof NativeObject) {
329329
NativeObject config = (NativeObject) obj;
330330
feature = (SimpleFeature) new Feature(config.getParentScope(), config).unwrap();

src/test/resources/org/geoscript/js/tests/geoscript/feature/test_collection.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,26 @@ exports["test: close (custom)"] = function() {
199199

200200
}
201201

202+
exports["test: constructor (array)"] = function() {
203+
var Point = GEOM.Point;
204+
205+
var features = [
206+
new Feature({properties: {loc: new Point([1, 2])}}),
207+
new Feature({properties: {loc: new Point([3, 4])}})
208+
];
209+
var collection = new FeatureCollection({features: features});
210+
ASSERT.strictEqual(collection.size, 2);
211+
212+
var got = [];
213+
for (var feature in collection) {
214+
got.push(feature);
215+
}
216+
ASSERT.strictEqual(got.length, 2);
217+
ASSERT.ok(got[0].geometry.equals(new Point([1, 2])));
218+
ASSERT.deepEqual(got[1].get("loc").coordinates, [3, 4]);
219+
220+
};
221+
202222

203223
if (require.main == module.id) {
204224
system.exit(require("test").run(exports));

0 commit comments

Comments
 (0)