Jump to: navigation, search

Difference between revisions of "Widget:PnChoropleths"

m
m
Line 285: Line 285:
 
};
 
};
  
 +
}() );
 +
 +
 +
//Map
 +
( function() {
 +
 +
window.IRHB = window.IRHB || {};
 +
var w = window.IRHB;
 +
w.map = {};
 +
var m = w.map, d = w.data, get = w.get;
 +
var tooltip, features, zoom, tooltipOffset;
 +
m.curMap = false;
 +
 +
 +
function makeResponsive(svg) {
 +
var container = d3.select(svg.node().parentNode),
 +
w = parseInt(svg.style("width")),
 +
h = parseInt(svg.style("height")),
 +
aspect = w / h;
 +
svg.attr("viewBox", "0 0 " + w + " " + h)
 +
.attr("preserveAspectRatio", "xMinYMid")
 +
.call(resize);
 +
d3.select(window).on("resize." + container.attr("id"), resize);
 +
 +
function resize() {
 +
var targetWidth = parseInt(container.style("width"));
 +
svg.attr("width", targetWidth);
 +
svg.attr("height", Math.round(targetWidth / aspect));
 +
}
 +
}
 +
 +
 +
m.prepareMap = function() {
 +
var mp = get(m.curMap);
 +
var width = 496, height = 550;
 +
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 svg = d3.select("div#" + m.curMap).append("svg").attr("width", width).attr("height", height);
 +
if (mp.childNodes.length > 1) {
 +
mp.firstChild.nextSibling.style.display = "none";
 +
}
 +
features = svg.append("g").attr("class","features");
 +
tooltip = d3.select("body").append("div").attr("class","ttip");
 +
d3.json("/wiki/geo/england/country/England.json",function(error,geodata) {
 +
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);
 +
w.choro.choropleth();
 +
if (mp.childNodes.length > 1) {
 +
mp.removeChild(mp.childNodes[0]);
 +
}
 +
mp.firstChild.style.display = "block";
 +
makeResponsive(svg);
 +
} else {
 +
return console.log(error);
 +
}
 +
});
 +
tooltipOffset = {x: 5, y: -25};
 +
}
 +
 +
 +
m.initMap = function() {
 +
d.calcStats();
 +
};
 +
 +
 +
m.addSpinner = function (elem) {
 +
var svg = '<svg version="1.1" id="L9" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">';
 +
svg += '<path fill="#fff" d="M73,50c0-12.7-10.3-23-23-23S27,37.3,27,50 M30.9,50c0-10.5,8.5-19.1,19.1-19.1S69.1,39.5,69.1,50">';
 +
svg += '<animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="2s" from="0 50 50" to="360 50 50" repeatCount="indefinite"/>';
 +
svg += '</path></svg>';
 +
elem.innerHTML = svg;
 +
};
 +
 +
 +
 +
function clicked(d, i) {
 +
location.href = encodeURIComponent(d.properties.name) + " place-names";
 +
}
 +
 +
 +
function showTooltip(d) {
 +
moveTooltip();
 +
tooltip.style("display","block").text(d.properties.abbrev);
 +
}
 +
 +
 +
function moveTooltip() {
 +
tooltip.style("top",(d3.event.pageY+tooltipOffset.y)+"px").style("left",(d3.event.pageX+tooltipOffset.x)+"px");
 +
}
 +
 +
 +
function hideTooltip() {
 +
tooltip.style("display","none");
 +
}
 +
 
}() );
 
}() );
 
</script></includeonly>
 
</script></includeonly>

Revision as of 12:46, 2 June 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.