Skip to content

Instantly share code, notes, and snippets.

@bsudekum
Created November 6, 2013 17:07
Show Gist options
  • Save bsudekum/7340046 to your computer and use it in GitHub Desktop.
Save bsudekum/7340046 to your computer and use it in GitHub Desktop.
Switching from Google Maps to MapBox.js
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>Example Google Map</title>
<meta name='viewport' content='initial-scale=1.0, user-scalable=no'>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src='https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false'></script>
<script>
function initialize() {
var exampleLoc = new google.maps.LatLng(-25.363882,131.044922);
var map = new google.maps.Map(document.getElementById('map-canvas'),{
zoom: 4,
center: exampleLoc,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow({
content: 'Hello, world!'
});
var marker = new google.maps.Marker({
position: exampleLoc,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
var circle = new google.maps.Circle({
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 3,
fillColor: '#FF0000',
fillOpacity: 0.1,
map: map,
center: exampleLoc,
radius: 400000
});
var exampleKml = new google.maps.KmlLayer({
url: 'https://gist.github.com/rsudekum/531cb665aa8f7f3f0745/raw/d874f6ccea7d47105387f3ed7f7224eb44fb3c8e/demo.kml',
clickable: false
});
exampleKml.setMap(map);
google.maps.event.addListener(map, 'click', function(event) {
marker = new google.maps.Marker({
position: event.latLng, map: map
});
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id='map-canvas'></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>Example MapBox.js Map</title>
<script src='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.js'></script>
<script src='example.js'></script>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.css' rel='stylesheet' />
<!--[if lte IE 8]>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.4.0/mapbox.ie.css' rel='stylesheet'>
<![endif]-->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script type='text/javascript'>
var exampleLoc = new L.LatLng(-25.363882,131.044922);
var map = L.mapbox.map('map')
.setView(exampleLoc, 4);
var content = 'Hello, world!';
var marker = L.marker(exampleLoc)
.bindPopup(content)
.addTo(map)
.openPopup();
var circle = L.circle(exampleLoc, 400000,{
color:'#FF0000',
opactiy: 0.8,
weight: 3,
fillColor:'#FF0000',
fillOpacity: 0.1
}).addTo(map);
var exampleGeoJson = L.geoJson(features).addTo(map);
map.on('click',function(e){
L.marker(e.latlng).addTo(map)
});
L.control.layers({
'Map': L.mapbox.tileLayer('examples.map-9ijuk24y').addTo(map),
'Satellite': L.mapbox.tileLayer('bobbysud.map-l4i2m7nd')
}).addTo(map);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment