Add the ability to easily set the tile layer's gcs.
Along with the addition of proj4 affine transforms, this allows multiple
tile layers to have different (and adjustable) transforms.
MODIFY
src/featureLayer.js
src/featureLayer.js
@@ -136,6 +136,38 @@ var featureLayer = function (arg) {
}
};
+ /**
+ * Get or set the gcs for all features. For features, the default is usually
+ * the map's ingcs.
+ *
+ * @param {string?} [val] If `undefined`, return the current gcs. If
+ * `null`, use the map's interface gcs. Otherwise, set a new value for
+ * the gcs. When getting the current gcs, if not all features have the
+ * same gcs, `undefined` will be returned.
+ * @returns {string|this} A string used by {@link geo.transform}. If the
+ * map interface gcs is in use, that value will be returned. If the gcs
+ * is set, return the current class instance.
+ */
+ this.gcsFeatures = function (val) {
+ if (val === undefined) {
+ var gcs, mixed;
+ this.features().forEach((feature) => {
+ if (gcs === undefined) {
+ gcs = feature.gcs();
+ } else if (feature.gcs() !== gcs) {
+ mixed = true;
+ }
+ });
+ return mixed ? undefined : gcs;
+ }
+ m_this.features().forEach((feature) => {
+ if (feature.gcs() !== val) {
+ feature.gcs(val);
+ }
+ });
+ return m_this;
+ };
+
/**
* Initialize.
*

MODIFY
src/tileLayer.js
src/tileLayer.js
@@ -683,6 +683,32 @@ var tileLayer = function (arg) {
return tiles;
};
+ /**
+ * Get or set the layer gcs. This defaults to the map's gcs.
+ *
+ * @param {string} [arg] If `undefined`, return the current gcs. Otherwise,
+ * a new value for the gcs. If `null`, use the map's gcs.
+ * @returns {string|this} A string used by {@link geo.transform}.
+ */
+ this.gcs = function (arg) {
+ if (arg === undefined) {
+ return m_this._options.gcs || m_this.map().gcs();
+ }
+ var previous = m_this.gcs();
+ if (arg === null) {
+ delete m_this._options.gcs;
+ } else {
+ m_this._options.gcs = arg;
+ }
+ if (m_this.gcs() !== previous) {
+ m_this.clear();
+ m_this.gcsFeatures(m_this.gcs());
+ m_this.modified();
+ m_this._update();
+ }
+ return m_this;
+ };
+
/**
* Prefetches tiles up to a given zoom level around a given bounding box.
*

MODIFY
tests/cases/featureLayer.js
tests/cases/featureLayer.js
@@ -118,6 +118,15 @@ describe('geo.featureLayer', function () {
expect(layer.features().length).toBe(2);
expect(layer.features()).toEqual([feat2, feat1]);
});
+ it('gcsFeatures', function () {
+ expect(layer.gcsFeatures()).toBe(layer.map().ingcs());
+ layer.features()[0].gcs('+proj=longlat');
+ expect(layer.gcsFeatures()).toBe(undefined);
+ expect(layer.gcsFeatures('+proj=longlat')).toBe(layer);
+ expect(layer.gcsFeatures()).toBe('+proj=longlat');
+ expect(layer.gcsFeatures(null)).toBe(layer);
+ expect(layer.gcsFeatures()).toBe(layer.map().ingcs());
+ });
it('visible', function () {
expect(layer.visible()).toBe(true);
expect(feat1.visible()).toBe(true);

MODIFY
tests/cases/tileLayer.js
tests/cases/tileLayer.js
@@ -58,6 +58,7 @@ describe('geo.tileLayer', function () {
size: get_set('size'),
scale: get_set('scale'),
zoom: get_set('zoom'),
+ rotation: get_set('rotation'),
center: get_set('center'),
origin: get_set('origin'),
unitsPerPixel: function (zoom) {
@@ -714,6 +715,16 @@ describe('geo.tileLayer', function () {
left: 90, top: -66.51, right: 180, bottom: -85.05})).toBe(true);
});
});
+ it('gcs', function () {
+ var l = geo.tileLayer({map: map(), url: function () { return '/testdata/white.jpg'; }, canvas: $('<div/>')});
+ // replace _getTiles so we don't have to actually compute things.
+ l._getTiles = function () {};
+ expect(l.gcs()).toBe(l.map().gcs());
+ expect(l.gcs('+proj=longlat')).toBe(l);
+ expect(l.gcs()).toBe('+proj=longlat');
+ expect(l.gcs(null)).toBe(l);
+ expect(l.gcs()).toBe(l.map().gcs());
+ });
describe('tileCropFromBounds and tilesMaxBounds', function () {
var w = 5602, h = 4148,
mapOpts = {

Add the ability to easily set the tile layer's gcs.

Along with the addition of proj4 affine transforms, this allows multiple
tile layers to have different (and adjustable) transforms.