forked from CartoDB/carto.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenlayers.html
78 lines (69 loc) · 2.35 KB
/
openlayers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>OpenLayers 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="./css/OLstyle.css" type="text/css">
</head>
<body>
<div id="map"></div>
<!-- include cartodb.core.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.core.js"></script>
<script src="vendor/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer;
function init() {
// create openlayers map
layer = new OpenLayers.Layer.OSM("Simple OSM Map");
map = new OpenLayers.Map({
div: 'map',
layers: [layer],
center: [0, 0],
zoom: 1
});
// request cartodb layer
// most populated places rendered with red markers
cartodb.Tiles.getTiles({
type: 'cartodb',
user_name: 'examples',
sublayers: [{
sql: 'select * from ne_10m_populated_p_2',
cartocss: '#ne_10m_populated_p_2{ marker-fill: #F11810; marker-opacity: 0.9; marker-allow-overlap: true; marker-placement: point; marker-type: ellipse; marker-width: 7.5; marker-line-width: 2; marker-line-color: #000; marker-line-opacity: 0.2; }'
}]
}, function(tileTemplate) {
// generate urls for openlayers
var tilesUrl = []
for(var i = 0; i < 4; ++i) {
tilesUrl.push(
tileTemplate.tiles[0]
.replace('{s}', 'abcd'[i])
.replace('{z}','${z}')
.replace('{x}','${x}')
.replace('{y}','${y}')
);
}
// create the openlayers layer
var cartodbLayer = new OpenLayers.Layer.XYZ(
"CartoDB example",
tilesUrl, {
attribution: "CartoDB, populated places",
sphericalMercator: true,
isBaseLayer: false
});
// add to the map
map.addLayer(cartodbLayer);
});
}
init();
</script>
</body>
</html>