A demonstration of custom modal infoboxes from d3.carto.map.
If you click on a site point (the pink circles) you'll see an infobox that reads something like "Lugdunum Convenarum in modern day France" whereas if you click on a country, you'll see an infobox that reads something like "The country of Spain has a short name".
How a modal handles the data in a datapoint for display is handled by defining a custom formatter for the modal, which requires that you create a new d3.carto.modal. The new modal is assigned to a d3.carto.layer using .modal() as shown in the example for the CSV Points and Feature Array layers.
Formatters are defined using the standard D3 accessor syntax. The default formatter, demonstrated in the basic modal example. Since you know your data better than d3.carto does, you can specify how to parse what attributes in as specific a manner as you want. The function should return a string of HTML suitable to be dropped into the modal div.
The key lines for defining the modal and formatter are:
csvModal = d3.carto.modal();
csvModal.formatter(
function(d) {return "<h1>" + d.label + " in modern day " + d.modern + "</h1>"}
)
and:
featureModal = d3.carto.modal();
featureModal.formatter(
function(d) {return "<p class='countryInfobox'>The country of " + d.properties.name + " has a short name</p>"}
)
Modified http://d3js.org/d3.v3.min.js to a secure url
Modified http://d3js.org/topojson.v1.min.js to a secure url
Modified http://d3js.org/d3.geo.projection.v0.min.js to a secure url
Modified http://d3js.org/colorbrewer.v1.min.js to a secure url
Updated missing url http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/tile.js to /emeeks/f3105fda25ff785dc5ed/example/tile.js
Updated missing url http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.quadtiles.js to /emeeks/f3105fda25ff785dc5ed/example/d3.quadtiles.js
Updated missing url http://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.geo.raster.js to /emeeks/f3105fda25ff785dc5ed/example/d3.geo.raster.js
Updated missing url https://rawgit.com/emeeks/d3-carto-map/master/d3.carto.map.js to https://cdn.jsdelivr.net/gh/emeeks/d3-carto-map/d3.carto.map.js
https://d3js.org/d3.v3.min.js
https://d3js.org/topojson.v1.min.js
https://d3js.org/d3.geo.projection.v0.min.js
https://d3js.org/colorbrewer.v1.min.js
https://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/tile.js
https://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.quadtiles.js
https://bl.ocks.org/emeeks/raw/f3105fda25ff785dc5ed/d3.geo.raster.js
https://rawgit.com/emeeks/d3-carto-map/master/d3.carto.map.js