Map Layers - Named
HTML
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css">
<h1>
Layers Test
</h1>
<div id="global-map-container" class="map-container">
</div>
<div class="log-container">
<h2>
Logs:
</h2>
</div>
CSS
.map-container {
width: 90vw;
height: 60vh;
}
CoffeeScript
$(".log-container").append "<p>Loading script</p>"
window.geo = new Object()
cartoAccount = "mvz" # This is a working account.
# These params are calculated by another script to determine which tables are looked up
layers = new Array()
layer1 =
name: "adp_generic_heatmap-v15"
type: "namedmap"
params:
table_name: "t2627cbcbb4d7597f444903b2e7a5ce5c_6d6d454828c05e8ceea03c99cc5f5"
color: "#FF6600"
## Leflet Map Setup
leafletOptions =
center: [window.locationData?.lat ? 0, window.locationData?.lng ? 0]
zoom: 4
$(".log-container").append "<p>Defining function</p>"
createRawCartoMap = (layers, callback, options, mapSelector = "#global-data-map") ->
###
# Create a raw CartoDB map
#
# See
# https://docs.cartodb.com/cartodb-platform/cartodb-js/getting-started/#creating-visualizations-at-runtime
#
###
$(".log-container").append "<p>Starting raw map creation</p>"
unless options?
options = new Object()
unless layers.user_name?
params =
user_name: options.user_name ? cartoAccount
type: options.type ? "cartodb"
sublayers: layers
extra_params:
map_key: window.apiKey # For testing and not leaking
api_key: window.apiKey # For testing and not leaking
else
params = layers
$(".log-container").append "<p>Creating map <code>#{JSON.stringify(params)}</code></p>"
# The CartoDB layer options
mapOptions =
cartodb_logo: false
https: true
mobile_layout: true
gmaps_base_type: "hybrid"
center_lat: window.locationData?.lat ? center[0]
center_lon: window.locationData?.lng ? center[1]
zoom: 4
unless geo.lMap?
lMap = new L.Map("global-map-container", leafletOptions)
geo.lMap = lMap
lTopoOptions =
attribution: 'Tiles © Esri — Esri, DeLorme, NAVTEQ, TomTom, Intermap, iPC, USGS, FAO, NPS, NRCAN, GeoBase, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), and the GIS User Community'
...