Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Indoor Maps - See Issue #675 #676

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/geo/crs/CRS.Cartesian.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* CRS.Cartesian is used for infinite coordinate systems that are not related to the Earth. Examples
* include indoor maps, gaming maps, etc. We assume 0,0 is in the bottom right corner.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean bottom left here? From code it seems that only latitude is inverted, but longitude is still from left to right.

*/

L.CRS.Cartesian = L.Class.extend({
includes: L.CRS,

initialize: function(bounds, options)
{
L.Util.setOptions(this, options);
this.unbounded = true;
this._bounds = bounds;

var boundsWidth = bounds.max.x - bounds.min.x;
var boundsHeight = bounds.max.y - bounds.min.y;

var xOffset = options.falseEasting || 0;
var xOffsetPercentage = 0 + xOffset / (boundsWidth * 1.0)

var yOffset = options.falseNorthing || 0;
var yOffsetPercentage = 1 - yOffset / (boundsHeight * 1.0)

this.projection = L.Projection.Identity;
this.transformation = new L.Transformation(1.0/boundsWidth, xOffsetPercentage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain the falseEasting/Northing and offsetPercentage stuff? I don't quite understand why the transformation coefficients are percentage values (while they should shifts basically, so are expected to be of a pixel value)

-1.0/boundsHeight, yOffsetPercentage);
}
});
6 changes: 4 additions & 2 deletions src/geo/crs/CRS.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@

L.CRS = {
unbounded : false,

latLngToPoint: function (latlng, zoom) { // (LatLng, Number) -> Point
var projectedPoint = this.projection.project(latlng),
scale = this.scale(zoom);

return this.transformation._transform(projectedPoint, scale);
},

pointToLatLng: function (point, zoom, unbounded) { // (Point, Number[, Boolean]) -> LatLng
pointToLatLng: function (point, zoom) { // (Point, Number[, Boolean]) -> LatLng
var scale = this.scale(zoom),
untransformedPoint = this.transformation.untransform(point, scale);

return this.projection.unproject(untransformedPoint, unbounded);
return this.projection.unproject(untransformedPoint, this.unbounded);
//TODO get rid of 'unbounded' everywhere
},

Expand Down
10 changes: 10 additions & 0 deletions src/geo/projection/Projection.Identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

L.Projection.Identity = {
project: function(latlng) {
return new L.Point(latlng.lng, latlng.lat);
},

unproject: function(point, unbounded) {
return new L.LatLng(point.y, point.x, unbounded);
}
};
15 changes: 7 additions & 8 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ L.Map = L.Class.extend({

// public methods for getting map state

getCenter: function (unbounded) { // (Boolean) -> LatLng
getCenter: function () { // (Boolean) -> LatLng
var viewHalf = this.getSize().divideBy(2),
centerPoint = this._getTopLeftPoint().add(viewHalf);

return this.unproject(centerPoint, this._zoom, unbounded);
return this.unproject(centerPoint, this._zoom);
},

getZoom: function () {
Expand All @@ -243,10 +243,10 @@ L.Map = L.Class.extend({

getBounds: function () {
var bounds = this.getPixelBounds(),
sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true),
ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true);
sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom),
ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom);

return new L.LatLngBounds(sw, ne);
return new L.LatLngBounds(sw, ne, this.options.crs.unbounded);
},

getMinZoom: function () {
Expand Down Expand Up @@ -371,10 +371,9 @@ L.Map = L.Class.extend({
return this.options.crs.latLngToPoint(latlng, zoom);
},

unproject: function (point, zoom, unbounded) { // (Point[, Number, Boolean]) -> LatLng
// TODO remove unbounded, making it true all the time?
unproject: function (point, zoom) { // (Point[, Number, Boolean]) -> LatLng
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
return this.options.crs.pointToLatLng(point, zoom, unbounded);
return this.options.crs.pointToLatLng(point, zoom);
},


Expand Down
2 changes: 1 addition & 1 deletion src/map/anim/Map.PanAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
// difference between the new and current centers in pixels
var offset = this._getNewTopLeftPoint(center).subtract(this._getTopLeftPoint());

center = new L.LatLng(center.lat, center.lng);
center = new L.LatLng(center.lat, center.lng, this.options.crs.unbounded);

var done = (zoomChanged ?
this._zoomToIfCenterInView && this._zoomToIfCenterInView(center, zoom, offset) :
Expand Down