adding features

This commit is contained in:
Mike Adair
2012-06-20 13:33:20 -04:00
parent d5f9f9e8a4
commit 4ea2fe3701
8 changed files with 332 additions and 2 deletions

View File

@@ -0,0 +1,79 @@
describe("ol.feature", function() {
it("should be easy to make a feature", function() {
var feat = ol.feature();
expect(feat).toBeA(ol.Feature);
});
it("should be easy to set feature attribute", function() {
var feat = ol.feature();
feat.set('foo', 'bar');
expect(feat).toBeA(ol.Feature);
expect(feat.get('foo')).toBe('bar');
});
it("calling set with one argument", function() {
var feat = ol.feature();
feat.set('foo');
expect(feat.get('foo')).toBe(undefined);
});
it("should be easy to set feature geometry", function() {
var feat = ol.feature();
var point = ol.geom.point([21, 4]);
feat.geometry(point);
var geom = feat.geometry();
expect(feat).toBeA(ol.Feature);
expect(geom.getX()).toBe(21);
expect(geom.getY()).toBe(4);
});
it("should be easy to create a feature from object literals", function() {
var feat = ol.feature({
attrs: {
foo: 'bar',
two: 'deux',
size: 3,
flag: true
},
geom: ol.geom.point([56, 22])
});
var geom = feat.geometry();
expect(feat).toBeA(ol.Feature);
expect(geom.getX()).toBe(56);
expect(geom.getY()).toBe(22);
expect(feat.get('foo')).toBe('bar');
expect(feat.get('two')).toBe('deux');
expect(feat.get('size')).toBe(3);
expect(feat.get('flag')).toBe(true);
});
/*
it("should be easy to create a feature from GeoJSON", function() {
var geoJson = {
type: "Feature",
geometry: {type: "Point", coordinates: [102.0, 0.5]},
properties: {prop0: "value0"}
};
var feat = ol.feature(geoJson);
var geom = feat.geometry();
expect(feat).toBeA(ol.Feature);
expect(geom.getX()).toBe(102.0);
expect(geom.getY()).toBe(0.5);
expect(feat.get('prop0')).toBe('value0');
});
*/
});

View File

@@ -137,6 +137,10 @@ describe("ol.map", function() {
expect(center.x().toFixed(3)).toBe("1113194.908");
expect(center.y().toFixed(3)).toBe("2273030.927");
//make sure the center doesn't change
expect(center.x().toFixed(3)).toBe("1113194.908");
expect(center.y().toFixed(3)).toBe("2273030.927");
});
it("provides feedback when you mess up", function() {

View File

@@ -0,0 +1,79 @@
describe("ol.Feature", function() {
it("should be easy to make a feature", function() {
var feat = new ol.Feature();
expect(feat).toBeA(ol.Feature);
});
it("should be easy to set feature attribute", function() {
var feat = new ol.Feature();
feat.setAttribute('foo', 'bar');
expect(feat).toBeA(ol.Feature);
expect(feat.getAttribute('foo')).toBe('bar');
});
it("calling set with one argument", function() {
var feat = new ol.Feature();
feat.setAttribute('foo');
expect(feat.getAttribute('foo')).toBe(undefined);
});
it("should be easy to set feature geometry", function() {
var feat = new ol.Feature();
var point = ol.geom.point([21, 4]);
feat.setGeometry(point);
var geom = feat.getGeometry();
expect(feat).toBeA(ol.Feature);
expect(geom).toBeA(ol.geom.Geometry);
expect(geom.getX()).toBe(21);
expect(geom.getY()).toBe(4);
});
it("should be able to set attributes from object literals", function() {
var feat = new ol.Feature();
feat.setAttributes({
foo: 'bar',
two: 'deux',
size: 3,
flag: true
});
expect(feat).toBeA(ol.Feature);
expect(feat.getAttribute('foo')).toBe('bar');
expect(feat.getAttribute('two')).toBe('deux');
expect(feat.getAttribute('size')).toBe(3);
expect(feat.getAttribute('flag')).toBe(true);
});
it("should be able to set attributes keeping existing ones", function() {
var feat = new ol.Feature();
feat.setAttributes({
foo: 'bar',
size: 3
});
expect(feat).toBeA(ol.Feature);
expect(feat.getAttribute('size')).toBe(3);
feat.setAttributes({
two: 'deux',
size: -99
});
expect(feat.getAttribute('two')).toBe('deux');
expect(feat.getAttribute('foo')).toBe('bar');
expect(feat.getAttribute('size')).toBe(-99);
});
});