Simple Coordinate Reference System #210

Closed
tcoats opened this Issue Jul 25, 2011 · 9 comments

Comments

Projects
None yet
7 participants
@tcoats
Contributor

tcoats commented Jul 25, 2011

I'd like to use Leaflet to display images (similar to Zoomify). While it is currently possible to add an image overlay, it is displayed using accurate coordinates. Ideally a simple coordinate reference system could be used to define a 1:1 pixel LatLot reference.

In Summary:

  • 1:1 Coordinate Reference System

@ghost ghost assigned mourner Sep 9, 2011

@Majiir

This comment has been minimized.

Show comment
Hide comment
@Majiir

Majiir Nov 9, 2011

Contributor

I'd like this functionality as well. I looked into using image overlays, but my application is really better suited to using some sort of tile layer. My map is (potentially) infinite and non-repeating; think infinite flatland.

Contributor

Majiir commented Nov 9, 2011

I'd like this functionality as well. I looked into using image overlays, but my application is really better suited to using some sort of tile layer. My map is (potentially) infinite and non-repeating; think infinite flatland.

@robinvanemden

This comment has been minimized.

Show comment
Hide comment
@robinvanemden

robinvanemden Nov 30, 2011

Second that! Would be great to have a 1:1 pixel reference.

Second that! Would be great to have a 1:1 pixel reference.

@Majiir

This comment has been minimized.

Show comment
Hide comment
@Majiir

Majiir Jan 3, 2012

Contributor

It's actually possible to accomplish this without any modifications to the source. It requires a couple new classes, but it's nothing too difficult.

This creates new Projection and CRS classes for using unbound coordinates. For reasons I have yet to discover, LngLat coordinates do not map directly to Point coordinates, but there isn't any wrapping to cause trouble.

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

    unproject: function (point, unbounded) {
        return new L.LatLng(point.y, point.x, true);
    }
};

L.CRS.Direct = L.Util.extend({}, L.CRS, {
    code: 'Direct',

    projection: L.Projection.NoWrap,
    transformation: new L.Transformation(1, 0, 1, 0)
});

When creating our Map, we must reference the new CRS and also set worldCopyJump to false.

var map = new L.Map('map', {worldCopyJump: false, crs: L.CRS.Direct});

Finally, when creating a layer, we set continuousWorld to true.

var layer = new L.TileLayer(url, {continuousWorld: true});

Here is an example: link

It's not exactly clean, but it should suffice for most purposes.

Contributor

Majiir commented Jan 3, 2012

It's actually possible to accomplish this without any modifications to the source. It requires a couple new classes, but it's nothing too difficult.

This creates new Projection and CRS classes for using unbound coordinates. For reasons I have yet to discover, LngLat coordinates do not map directly to Point coordinates, but there isn't any wrapping to cause trouble.

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

    unproject: function (point, unbounded) {
        return new L.LatLng(point.y, point.x, true);
    }
};

L.CRS.Direct = L.Util.extend({}, L.CRS, {
    code: 'Direct',

    projection: L.Projection.NoWrap,
    transformation: new L.Transformation(1, 0, 1, 0)
});

When creating our Map, we must reference the new CRS and also set worldCopyJump to false.

var map = new L.Map('map', {worldCopyJump: false, crs: L.CRS.Direct});

Finally, when creating a layer, we set continuousWorld to true.

var layer = new L.TileLayer(url, {continuousWorld: true});

Here is an example: link

It's not exactly clean, but it should suffice for most purposes.

@mourner

This comment has been minimized.

Show comment
Hide comment
@mourner

mourner Jul 25, 2012

Member

Wanted to refactor projections code so it doesn't need to use the ugly worldCopyJump and continuousWorld options and instead delegates everything to CRS, using bounding box and wrap settings from it, but there are some open questions regarding this, so I'll postpone it to 0.5 so there are less chances of breaking anything.

Member

mourner commented Jul 25, 2012

Wanted to refactor projections code so it doesn't need to use the ugly worldCopyJump and continuousWorld options and instead delegates everything to CRS, using bounding box and wrap settings from it, but there are some open questions regarding this, so I'll postpone it to 0.5 so there are less chances of breaking anything.

@cfis

This comment has been minimized.

Show comment
Hide comment
@cfis

cfis Jul 25, 2012

A thought to consider while doing that. Remove the LatLng class. Instead just use Point. Also, all geometries should have an associated CRS. The way the geometry is interpreted is dependent on the CRS.

cfis commented Jul 25, 2012

A thought to consider while doing that. Remove the LatLng class. Instead just use Point. Also, all geometries should have an associated CRS. The way the geometry is interpreted is dependent on the CRS.

@rawsyntax

This comment has been minimized.

Show comment
Hide comment
@rawsyntax

rawsyntax Nov 11, 2012

@Majiir I had a look at your example and am using this for some indoor maps. The X coordinate lines up perfectly (top left 0), however the Y coordinate is off by some factor. Any idea how the scheme:'tms' option would affect this? My problem seems to be in _getWrapTileNum which is commented as not accurate for nonstandard projections

@Majiir I had a look at your example and am using this for some indoor maps. The X coordinate lines up perfectly (top left 0), however the Y coordinate is off by some factor. Any idea how the scheme:'tms' option would affect this? My problem seems to be in _getWrapTileNum which is commented as not accurate for nonstandard projections

@Majiir

This comment has been minimized.

Show comment
Hide comment
@Majiir

Majiir Nov 15, 2012

Contributor

@rawsyntax Unfortunately I can't be much help to you; I didn't understand my code much when I wrote it, and by now I understand it even less.

Is there a reason you need a specific scheme? If you're working with a flat coordinate system in Leaflet, it might be easier to do any kind of translation on the application end.

Contributor

Majiir commented Nov 15, 2012

@rawsyntax Unfortunately I can't be much help to you; I didn't understand my code much when I wrote it, and by now I understand it even less.

Is there a reason you need a specific scheme? If you're working with a flat coordinate system in Leaflet, it might be easier to do any kind of translation on the application end.

@mourner

This comment has been minimized.

Show comment
Hide comment
@mourner

mourner Dec 12, 2012

Member

The included CRS.Simple is now much more usable out of the box (it has different default scaling and transformation now), and LatLng clamping/wrapping and worldCopyJump are now disabled by default. See debug/map/simple-proj.html for an example.

So now I think it's safe to close the issue. The only thing left that bugs me is continuousWorld option that's still needed, but it will be handled separately later.

Member

mourner commented Dec 12, 2012

The included CRS.Simple is now much more usable out of the box (it has different default scaling and transformation now), and LatLng clamping/wrapping and worldCopyJump are now disabled by default. See debug/map/simple-proj.html for an example.

So now I think it's safe to close the issue. The only thing left that bugs me is continuousWorld option that's still needed, but it will be handled separately later.

@mourner mourner closed this Dec 12, 2012

@jordan314

This comment has been minimized.

Show comment
Hide comment
@jordan314

jordan314 Dec 12, 2012

I just wanted to add that CRS.Simple support is in the master branch not the hosted 0.4.5 branch. Also don't try and use the hosted CSS with the master branch JS. :)
Thanks Mourner!

I just wanted to add that CRS.Simple support is in the master branch not the hosted 0.4.5 branch. Also don't try and use the hosted CSS with the master branch JS. :)
Thanks Mourner!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment