Skip to content

Instantly share code, notes, and snippets.

@ustroetz
Created September 13, 2015 08:54
Show Gist options
  • Select an option

  • Save ustroetz/2e680c389913b123abd3 to your computer and use it in GitHub Desktop.

Select an option

Save ustroetz/2e680c389913b123abd3 to your computer and use it in GitHub Desktop.
CartoDB.js + Mapbox.js
<!DOCTYPE html>
<html>
<head>
<title>Leaflet example | CartoDB.js</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
<style>
html,
body,
#map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.css' rel='stylesheet' />
</head>
<body>
<div id="map"></div>
<!-- include cartodb.js library -->
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.js'></script>
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.uncompressed.js"></script>
<script>
function main() {
L.mapbox.accessToken = 'pk.eyJ1IjoiYWxscnlkZXIiLCJhIjoidWs5cUFfRSJ9.t8kxvO3nIhCaAl07-4lkNw';
var map = L.mapbox.map('map', 'mapbox.light', {
center: [52.106505,10.986328],
zoom: 2
});
cartodb.createLayer(map, 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json').addTo(map)
}
window.onload = main;
</script>
</body>
</html>
@iriberri
Copy link
Copy Markdown

The CartoDB layer is not being shown correctly because there's a conflict with Leaflet. Both CartoDB.js and Mapbox.js include it, so when you add these libraries you will have to use their version without Leaflet in one of them.

The no-leaflet URL for mapbox.js is: https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.standalone.js

The CartoDB one is: http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb_noleaflet.js

Then, you could use:

    <script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script>
    <script src='https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.standalone.js'></script>

@ustroetz
Copy link
Copy Markdown
Author

👍 thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment