-
-
Save ackuser/ea8082a25108f6dab4394edaed24d5ad to your computer and use it in GitHub Desktop.
Using Leaflet in TypeScript. Original code see http://leafletjs.com/examples/quick-start-example.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://leafletjs.com/examples/quick-start-example.html in TypeScript | |
/// <reference path="leaflet.d.ts" /> | |
var map = new L.Map("map"); | |
map.setView(new L.LatLng(51.505, -0.09), 13); | |
var layer =new L.TileLayer("http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png", { maxZoom: 18, attribution: "attribution test" }) | |
layer.addTo(map); | |
// add marker | |
var marker = new L.Marker(new L.LatLng(51.5, -0.09)); | |
marker.addTo(map).bindPopup("<b>Hello world!</b><br />I am a popup.").openPopup(); | |
// add circle | |
var circle = new L.Circle(new L.LatLng(51.508, -0.11), 500, { | |
color: 'red', | |
fillColor: '#f03', | |
fillOpacity: 0.5 | |
}).addTo(map).bindPopup("I am a circle."); | |
// add polygon | |
var latlongs : L.LatLng[]; | |
latlongs= [ | |
new L.LatLng(51.509, -0.08), | |
new L.LatLng(51.503, -0.06), | |
new L.LatLng(51.51, -0.047) | |
]; | |
var polygon = new L.Polygon(latlongs).addTo(map).bindPopup("I am a polygon."); | |
// popup on mapclick | |
var popup = new L.Popup(); | |
function onMapClick(e) { | |
popup | |
.setLatLng(e.latlng) | |
.setContent("You clicked the map at " + e.latlng.toString()) | |
.openOn(map); | |
} | |
map.on('click', onMapClick); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>TypeScript HTML App</title> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" /> | |
<script src="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js"></script> | |
</head> | |
<body> | |
<div id="map" style="width: 600px; height: 400px"></div> | |
<script src="map.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment