Skip to content

Commit

Permalink
Configure proj4 options and transforms upon construction
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Mar 17, 2015
1 parent 8061b69 commit 2eec3dd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
10 changes: 5 additions & 5 deletions externs/olx.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ olx.OverlayOptions.prototype.autoPanMargin;
/**
* Object literal with config options for the projection.
* @typedef {{code: string,
* units: (ol.proj.Units|string),
* units: (ol.proj.Units|string|undefined),
* extent: (ol.Extent|undefined),
* axisOrientation: (string|undefined),
* global: (boolean|undefined),
Expand All @@ -430,8 +430,8 @@ olx.ProjectionOptions.prototype.code;


/**
* Units.
* @type {ol.proj.Units|string}
* Units. Required unless a proj4 projection is defined for `code`.
* @type {ol.proj.Units|string|undefined}
* @api stable
*/
olx.ProjectionOptions.prototype.units;
Expand Down Expand Up @@ -5046,9 +5046,9 @@ olx.source.TileArcGISRestOptions.prototype.attributions;
/**
* ArcGIS Rest parameters. This field is optional. Service defaults will be
* used for any fields not specified. `FORMAT` is `PNG32` by default. `F` is `IMAGE` by
* default. `TRANSPARENT` is `true` by default. `BBOX, `SIZE`, `BBOXSR`,
* default. `TRANSPARENT` is `true` by default. `BBOX, `SIZE`, `BBOXSR`,
* and `IMAGESR` will be set dynamically. Set `LAYERS` to
* override the default service layer visibility. See
* override the default service layer visibility. See
* {@link http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Map/02r3000000v7000000/}
* for further reference.
* @type {Object.<string,*>|undefined}
Expand Down
75 changes: 39 additions & 36 deletions src/ol/proj/proj.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ ol.proj.Projection = function(options) {
*/
this.defaultTileGrid_ = null;

if (ol.ENABLE_PROJ4JS && typeof proj4 == 'function') {
var code = options.code;
var def = proj4.defs(code);
if (goog.isDef(def)) {
if (goog.isDef(def.axis) && !goog.isDef(options.axisOrientation)) {
this.axisOrientation_ = def.axis;
}
if (!goog.isDef(options.units)) {
var units = def.units;
if (!goog.isDef(units)) {
if (goog.isDef(def.to_meter)) {
units = def.to_meter.toString();
ol.proj.METERS_PER_UNIT[units] = def.to_meter;
}
}
this.units_ = units;
}
ol.proj.addProjection(this);
var projections = ol.proj.projections_;
var currentCode, currentDef, currentProj, proj4Transform;
for (currentCode in projections) {
currentDef = proj4.defs(currentCode);
if (goog.isDef(currentDef)) {
currentProj = ol.proj.get(currentCode);
if (currentDef === def) {
ol.proj.addEquivalentProjections([currentProj, this]);
} else {
proj4Transform = proj4(currentCode, code);
ol.proj.addCoordinateTransforms(currentProj, this,
proj4Transform.forward, proj4Transform.inverse);
}
}
}
}
}

};


Expand Down Expand Up @@ -512,43 +548,10 @@ ol.proj.get = function(projectionLike) {
projection = projectionLike;
} else if (goog.isString(projectionLike)) {
var code = projectionLike;
var projections = ol.proj.projections_;
projection = projections[code];
projection = ol.proj.projections_[code];
if (ol.ENABLE_PROJ4JS && !goog.isDef(projection) &&
typeof proj4 == 'function') {
var def = proj4.defs(code);
if (goog.isDef(def)) {
var units = def.units;
if (!goog.isDef(units)) {
if (goog.isDef(def.to_meter)) {
units = def.to_meter.toString();
ol.proj.METERS_PER_UNIT[units] = def.to_meter;
}
}
projection = new ol.proj.Projection({
code: code,
units: units,
axisOrientation: def.axis
});
ol.proj.addProjection(projection);
var currentCode, currentDef, currentProj, proj4Transform;
for (currentCode in projections) {
currentDef = proj4.defs(currentCode);
if (goog.isDef(currentDef)) {
currentProj = ol.proj.get(currentCode);
if (currentDef === def) {
ol.proj.addEquivalentProjections([currentProj, projection]);
} else {
proj4Transform = proj4(currentCode, code);
ol.proj.addCoordinateTransforms(currentProj, projection,
proj4Transform.forward, proj4Transform.inverse);
}
}
}
} else {
goog.asserts.assert(goog.isDef(projection));
projection = null;
}
typeof proj4 == 'function' && goog.isDef(proj4.defs(code))) {
projection = new ol.proj.Projection({code: code});
}
} else {
projection = null;
Expand Down

0 comments on commit 2eec3dd

Please sign in to comment.