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

L.Proj.GeoJSON #32

Merged
merged 6 commits into from
Aug 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,32 @@ L.Proj.TileLayer.TMS(tileUrl, crs, options)
* ```tileUrl``` is the URL template to use for tiles (see [L.TileLayer](http://leafletjs.com/reference.html#tilelayer))
* ```crs``` is the L.Proj.CRS.TMS ICRS object used for this layer
* ```options``` are the options for this layer, see [L.TileLayer](http://leafletjs.com/reference.html#tilelayer)

###L.Proj.GeoJSON

Extends [L.GeoJSON](http://leafletjs.com/reference.html#geojson) to add CRS support. Unlike the TileLayer extension, the CRS
is derived from the `name` property of a `crs` defined directly on the GeoJSON object per [the spec](http://www.geojson.org/geojson-spec.html#named-crs). Linked CRSs are not supported.

**Note:** The relevant Proj4js definition should be defined directly through `Proj4js.defs` before loading the GeoJSON object. If it is not, Proj4js will attempt to load it asynchronously but it will not be ready in time to reproject the features.

Also, note that future versions of the GeoJSON spec may not include explicit CRS support. See https://github.com/GeoJSONWG/draft-geojson/pull/6 for more information.

####Usage Example
```javascript
Proj4js.defs["EPSG:26915"] = "+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";
var geojson = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [481650, 4980105]
},
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::26915"
}
}
};
var map = L.map('map');
L.Proj.geoJson(geojson).addTo(map);
```
18 changes: 18 additions & 0 deletions examples/geojson-crs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="../../lib/leaflet/leaflet.css" />
<!--[if lt IE 9]>
<link rel="stylesheet" href="lib/leaflet/leaflet.ie.css"/>
<![endif]-->
</head>
<body>
<div id="map"></div>
<script src="../../lib/leaflet/leaflet-src.js"></script>
<script src="../../lib/proj4js-compressed.js"></script>
<script src="../../src/proj4leaflet.js"></script>
<script src="script.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions examples/geojson-crs/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var map = L.map('map').setView([44.97,-93.24], 11);

// MapQuest OSM Tiles

// Attribution (https://gist.github.com/mourner/1804938)
var osmAttr = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>';
var mqTilesAttr = 'Tiles &copy; <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png" />';

L.tileLayer(
'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png',
{
subdomains: '1234',
attribution: osmAttr + ', ' + mqTilesAttr
}
).addTo(map);

// GeoJSON layer (UTM15)
Proj4js.defs["EPSG:26915"] = "+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";
var geojson = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [481650, 4980105],
},
"properties": {
"name": "University of Minnesota"
},
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::26915"
}
}
};

L.Proj.geoJson(geojson, {
'pointToLayer': function(feature, latlng) {
return L.marker(latlng).bindPopup(feature.properties.name);
}
}).addTo(map);
10 changes: 10 additions & 0 deletions examples/geojson-crs/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
html, body {
height: 100%;
padding: 0;
margin: 0;
}

#map {
width: 100%;
height: 100%;
}
Binary file added lib/leaflet/images/layers-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/leaflet/images/layers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/leaflet/images/marker-icon-2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/leaflet/images/marker-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/leaflet/images/marker-shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading