Widget:Test1: Difference between revisions
From International Robin Hood Bibliography
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
<noinclude><div class="no-img">This widget displays the navigation map on country and administrative division landing pages in the place-names section of IRHB. It takes no parameters.</div></noinclude><includeonly><div id="navMapNav"></div><script> | <noinclude><div class="no-img">This widget displays the navigation map on country and administrative division landing pages in the place-names section of IRHB. It takes no parameters.</div></noinclude><includeonly><div id="navMapNav"></div><script> | ||
//Utility | //Utility | ||
( function() { | ( function() { | ||
Line 245: | Line 236: | ||
var tooltip, features, zoom, tooltipOffset; | var tooltip, features, zoom, tooltipOffset; | ||
m.curMap = false; | m.curMap = false; | ||
m.makeResponsive = function(div, svg) { | |||
var container = d3.select(svg.node().parentNode); | |||
var w = parseInt(svg.style("width")); | |||
var h = parseInt(svg.style("height")); | |||
var aspect = w / h; | |||
svg.attr("viewBox", "0 0 " + w + " " + h) | |||
.attr("preserveAspectRatio", "xMinYMid") | |||
.call(resize); | |||
// to register multiple listeners for same event type, | |||
// you need to add namespace, i.e., 'click.foo' | |||
// necessary if you call invoke this function for multiple svgs | |||
// api docs: https://github.com/mbostock/d3/wiki/Selections#on | |||
d3.select(window).on("resize." + container.attr("id"), resize); | |||
// get width of container and resize svg to fit it | |||
function resize() { | |||
var targetWidth = parseInt(container.style("width")); | |||
svg.attr("width", targetWidth); | |||
svg.attr("height", Math.round(targetWidth / aspect)); | |||
} | |||
} | |||
Line 252: | Line 268: | ||
var projection = d3.geo.conicEqualArea().scale(5165.269352442655).center([-1.4602454263940616,52.55675714793008]).parallels([49.95898294542323,55.81107189358492]).rotate([1.4602454263940616]).translate([202.798519176517,306.70813464248357]); | var projection = d3.geo.conicEqualArea().scale(5165.269352442655).center([-1.4602454263940616,52.55675714793008]).parallels([49.95898294542323,55.81107189358492]).rotate([1.4602454263940616]).translate([202.798519176517,306.70813464248357]); | ||
var path = d3.geo.path().projection(projection); | var path = d3.geo.path().projection(projection); | ||
var | var div = "div#" + m.curMap; | ||
var svg = d3.select(div).append("svg").attr("width", width).attr("height", height); | |||
if (mp.childNodes.length > 1) { | if (mp.childNodes.length > 1) { | ||
mp.firstChild.nextSibling.style.display = "none"; | mp.firstChild.nextSibling.style.display = "none"; | ||
Line 258: | Line 275: | ||
features = svg.append("g").attr("class","features"); | features = svg.append("g").attr("class","features"); | ||
tooltip = d3.select("body").append("div").attr("class","ttip"); | tooltip = d3.select("body").append("div").attr("class","ttip"); | ||
m.makeResponsive(div, svg); | |||
d3.xml("/wiki/geo/england/country/England.svg",function(error,geodata) { | d3.xml("/wiki/geo/england/country/England.svg",function(error,geodata) { | ||
if (!error) { | if (!error) { | ||
features.selectAll("path").data(geodata.features).enter().append("path").attr("d",path).on("mouseover",showTooltip).on("mousemove",moveTooltip).on("mouseout",hideTooltip).on("click",clicked); | features.selectAll("path").data(geodata.features).enter().append("path").attr("d",path).on("mouseover",showTooltip).on("mousemove",moveTooltip).on("mouseout",hideTooltip).on("click",clicked); | ||
w.choro.choropleth(); | |||
if (mp.childNodes.length > 1) { | if (mp.childNodes.length > 1) { | ||
mp.removeChild(mp.childNodes[0]); | mp.removeChild(mp.childNodes[0]); |
Revision as of 16:27, 22 May 2019
This widget displays the navigation map on country and administrative division landing pages in the place-names section of IRHB. It takes no parameters.