-
Notifications
You must be signed in to change notification settings - Fork 72
Projections and Transformations
Projections are used internally by Modest Maps providers to convert from Locations to Coordinates.
Internally, the rawProject
and rawUnproject
functions are the
pure mathematics of the operation (we use Wolfram Mathworld and Wikipedia
to find interesting projections). These are the only ones that
need overriding by subclasses. The project
and unproject
functions use these, and in turn are used by locationCoordinate
and coordinateLocation
which are then used by providers. You'll probably
just want to use the versions offered by Map
.
Modest Maps offers two projections out of the box: LinearProjection
and MercatorProjection
. The built-in providers all assume Mercator
is what you want, but this is easily overridden.
Transformations are used internally by Modest Maps projections to convert from one projection space to another, and apply any needed translations, rotations and scales to get everything lined up.
e.g. to transform from a Mercator projected Location in radians to a map Coordinate at zoom level 26, you could use the following Transformation:
var t = new MM.Transformation(1.068070779e7, 0, 3.355443185e7,
0, -1.068070890e7, 3.355443057e7);
These magic numbers can be derived from three control points using some simple linear algebra. Modest Maps provides helpers for these. For example, to derive a similar Transformation to the above, but for a Coordinate at zoom level 0, use:
var pi = Math.PI;
var t = MM.deriveTransformation(-pi, pi, 0, 0, pi, pi, 1, 0, -pi, -pi, 0, 1);
The Transformation
class then offers transform
and
untransform
methods that operate on Points
.