So, the scenario is I have a situation where users can look up multiple tables worth of data, and want to view them in an aggregate fashion. Based on certain filters, I get a list of tables, then want them displayed on a map.
For the sake of everyone's sanity, I've put up a Fiddle with a working version:
https://jsfiddle.net/tigerhawkvok/q1nq89s1/5/
It uses real table names (with test data) and a real account, and you can see it not functional.
Here's the main function in question:
createRawCartoMap = (layers, callback, options, mapSelector = "#global-map-container") ->
###
# Create a raw CartoDB map
#
# See
# https://docs.cartodb.com/cartodb-platform/cartodb-js/getting-started/#creating-visualizations-at-runtime
#
# @param array layers -> an array of sublayer objs for CartoDB
###
unless options?
options = new Object()
params =
user_name: options.user_name ? cartoAccount
type: options.type ? "cartodb"
sublayers: layers
# 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: 5
## Leaflet Map Setup
leafletOptions =
center: [window.locationData?.lat ? 0, window.locationData?.lng ? 0]
zoom: zoom ? 5
unless geo.lMap?
lMap = new L.Map(mapSelector.slice(1), 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'
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', lTopoOptions).addTo lMap
BASE_MAP = geo.lMap
cartodb
.createLayer(BASE_MAP, params)
.addTo(BASE_MAP, 1)
.on "done", (layer) ->
# It really should already be up from the array of sublayers provided, but sure, we'll try again
for dataLayer in layers
layer.createSubLayer dataLayer
if typeof callback is "function"
callback()
false
.on "error", (errorString) ->
# Error handling
false
Both the fiddle and the code above may have some detritus from the full script it was pulled out of.
I'm seriously at a loss. Everything I've read and seen seems to indicate that it should work, but it doesn't.