Skip to content

Instantly share code, notes, and snippets.

@rgov
Last active August 9, 2019 20:14
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 rgov/ac38870ecee01d97513b6b8e9728b943 to your computer and use it in GitHub Desktop.
Save rgov/ac38870ecee01d97513b6b8e9728b943 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Map demo</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-draw@1.0.4/dist/leaflet.draw.css" />
<script src="https://unpkg.com/leaflet-draw@1.0.4/dist/leaflet.draw-src.js"></script>
<script src="https://unpkg.com/proj4@2.5.0/dist/proj4.js"></script>
<script src="https://unpkg.com/proj4leaflet@1.0.2/src/proj4leaflet.js"></script>
<script src="https://unpkg.com/leaflet-tilejson@1.0.0-rc4/index.js"></script>
</head>
<body>
<div id="map" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>
<script>
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib }),
map = new L.Map('map', { center: new L.LatLng(41.5265, -70.6731), zoom: 13 }),
drawnItems = L.featureGroup().addTo(map);
// We could the load the TileJSON from
// https://tileservice.charts.noaa.gov/tiles/50000_1/metadata.json
L.control.layers(
{
'osm': osm,
'google': L.tileLayer('//www.google.com/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', {
attribution: 'Google'
}),
'noaa': L.tileLayer("//tileservice.charts.noaa.gov/tiles/50000_1/{z}/{x}/{y}.png", {
attribution: 'NOAA'
}).addTo(map) /* default */
},
{ 'drawlayer': drawnItems },
{ position: 'topleft', collapsed: false }
).addTo(map);
map.addControl(new L.Control.Draw({
edit: {
featureGroup: drawnItems,
poly: {
allowIntersection: false
}
},
draw: {
polygon: {
allowIntersection: false,
showArea: true
}
}
}));
map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
drawnItems.addLayer(layer);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment