Skip to content

Instantly share code, notes, and snippets.

@henningjensen
Created December 9, 2015 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henningjensen/3a6501206be4e7c765bd to your computer and use it in GitHub Desktop.
Save henningjensen/3a6501206be4e7c765bd to your computer and use it in GitHub Desktop.
Kartverket - Leaflet with UTM33 projection - add markers and features.
<div id="map" width="500" height="500"></div>
<script type="text/javascript">
(function () {
L.Icon.Default.imagePath = '/Content/img/leaflet/';
var crs = L.CRS.proj4js('EPSG:32633', '+proj=utm +zone=33+ellps=WGS84 +datum=WGS84 +units=m +no_defs', new L.Transformation(1, 2500000, -1, 9045984));
crs.scale = function (zoom) {
return 1 / (21674.7100160867 / Math.pow(2, zoom));
};
var map = L.map('map', { crs: crs, continuousWorld: true }).setView([64.5, 10], 5);
var southWest = L.latLng(@Model.StateBoundingBox.South, @Model.StateBoundingBox.West),
northEast = L.latLng(@Model.StateBoundingBox.North, @Model.StateBoundingBox.East),
bounds = L.latLngBounds(southWest, northEast);
map.fitBounds(bounds);
/*
var baseLayer1 = new L.TileLayer.WMS("http://openwms.statkart.no/skwms1/wms.europa", {
layers: 'Europa_WMS',
format: 'image/png',
attribution: "Kartverket",
crs: crs
}).addTo(map);
*/
var baseLayer2 = new L.TileLayer.WMS("http://wms.geonorge.no/skwms1/wms.topo2", {
layers: 'topo2_WMS',
format: 'image/png',
attribution: "Kartverket",
version: '1.3.0'
}).addTo(map);
var coverageLayer = new L.TileLayer.WMS("http://openwms.statkart.no/skwms1/wms.gp_dek_oversikt?datasett=korallrev", {
layers: 'datasett_dekning',
format: 'image/png',
attribution: "Kartverket",
transparent: true,
opacity: 0.7
}).addTo(map);
/*
var countyNames = new L.TileLayer.WMS("http://wms.geonorge.no/skwms1/wms.abas?", {
layers: 'Kommunenavn',
format: 'image/png',
transparent: true,
attribution: "Kartverket",
}).addTo(map);
*/
/*
var geojson = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-29956, 6730321]
},
"crs": {
"type": "name",
"properties": {
"name": "EPSG:32633"
}
}
};
L.Proj.geoJson(geojson).addTo(map);
*/
var point = new L.Point(-29956, 6730321);
L.marker(crs.projection.unproject(point), {bounceOnAdd: true}).addTo(map);
}());
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment