Consistent GeoJSON casing

I've made the choice to:
- switch API and method to upper case version (GeoJSON, geoJSON, toGeoJSON)
- keep internal variable all lower case (geojson), because we usually do not
  uppercase variables

Fix #2444
This commit is contained in:
Yohan Boniface 2015-12-25 13:57:24 +01:00
parent 3fd2d5cb75
commit 5e6ef5ce12
2 changed files with 17 additions and 15 deletions

View File

@ -1,14 +1,14 @@
describe("L.GeoJSON", function () { describe("L.GeoJSON", function () {
describe("addData", function () { describe("addData", function () {
var geoJSON = { var geojson = {
type: 'Feature', type: 'Feature',
properties: {}, properties: {},
geometry: { geometry: {
type: 'Point', type: 'Point',
coordinates: [20, 10, 5] coordinates: [20, 10, 5]
} }
}, geoJSONEmpty = { }, geojsonEmpty = {
type: 'Feature', type: 'Feature',
properties: {}, properties: {},
geometry: null geometry: null
@ -16,19 +16,19 @@ describe("L.GeoJSON", function () {
it("sets feature property on member layers", function () { it("sets feature property on member layers", function () {
var layer = new L.GeoJSON(); var layer = new L.GeoJSON();
layer.addData(geoJSON); layer.addData(geojson);
expect(layer.getLayers()[0].feature).to.eql(geoJSON); expect(layer.getLayers()[0].feature).to.eql(geojson);
}); });
it("normalizes a geometry to a Feature", function () { it("normalizes a geometry to a Feature", function () {
var layer = new L.GeoJSON(); var layer = new L.GeoJSON();
layer.addData(geoJSON.geometry); layer.addData(geojson.geometry);
expect(layer.getLayers()[0].feature).to.eql(geoJSON); expect(layer.getLayers()[0].feature).to.eql(geojson);
}); });
it("accepts geojson with null geometry", function () { it("accepts geojson with null geometry", function () {
var layer = new L.GeoJSON(); var layer = new L.GeoJSON();
layer.addData(geoJSONEmpty); layer.addData(geojsonEmpty);
expect(layer.getLayers().length).to.eql(0); expect(layer.getLayers().length).to.eql(0);
}); });
}); });
@ -43,7 +43,7 @@ describe("L.GeoJSON", function () {
coordinates:[[-2.35, 51.38], [-2.38, 51.38]] coordinates:[[-2.35, 51.38], [-2.38, 51.38]]
} }
}; };
var geojson = L.geoJson(feature, {weight: 7, color: 'chocolate'}); var geojson = L.geoJSON(feature, {weight: 7, color: 'chocolate'});
geojson.setStyle({weight: 22, color: 'coral'}); geojson.setStyle({weight: 22, color: 'coral'});
var layer = geojson.getLayers()[0]; var layer = geojson.getLayers()[0];
expect(layer.options.weight).to.be(22); expect(layer.options.weight).to.be(22);
@ -327,7 +327,7 @@ describe("L.LayerGroup#toGeoJSON", function () {
}] }]
}; };
expect(L.geoJson(json).toGeoJSON()).to.eql(json); expect(L.geoJSON(json).toGeoJSON()).to.eql(json);
}); });
it('roundtrips MiltiPoint features', function () { it('roundtrips MiltiPoint features', function () {
@ -345,7 +345,7 @@ describe("L.LayerGroup#toGeoJSON", function () {
}] }]
}; };
expect(L.geoJson(json).toGeoJSON()).to.eql(json); expect(L.geoJSON(json).toGeoJSON()).to.eql(json);
}); });
it("omits layers which do not implement toGeoJSON", function () { it("omits layers which do not implement toGeoJSON", function () {

View File

@ -173,15 +173,15 @@ L.extend(L.GeoJSON, {
L.GeoJSON.asFeature(newGeometry); L.GeoJSON.asFeature(newGeometry);
}, },
asFeature: function (geoJSON) { asFeature: function (geojson) {
if (geoJSON.type === 'Feature') { if (geojson.type === 'Feature') {
return geoJSON; return geojson;
} }
return { return {
type: 'Feature', type: 'Feature',
properties: {}, properties: {},
geometry: geoJSON geometry: geojson
}; };
} }
}); });
@ -273,6 +273,8 @@ L.LayerGroup.include({
} }
}); });
L.geoJson = function (geojson, options) { L.geoJSON = function (geojson, options) {
return new L.GeoJSON(geojson, options); return new L.GeoJSON(geojson, options);
}; };
// Backward compatibility.
L.geoJson = L.geoJSON;