@sil/data 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sil-data.cjs +73 -0
- package/dist/sil-data.cjs.map +1 -1
- package/dist/sil-data.js +73 -0
- package/dist/sil-data.js.map +1 -1
- package/dist/types/__tests__/countryMaps.test.d.ts +1 -0
- package/dist/types/data/countryMaps.d.ts +104 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/types/index.d.ts +29 -0
- package/package.json +1 -1
package/dist/sil-data.js
CHANGED
|
@@ -4929,7 +4929,77 @@ function _renderPaths(country, fill, stroke, strokeWidth, label) {
|
|
|
4929
4929
|
return `<path${attrs} d="${d}" fill="${fill}" stroke="${stroke}" stroke-width="${strokeWidth}">${i === 0 ? title : ""}</path>`;
|
|
4930
4930
|
}).join("");
|
|
4931
4931
|
}
|
|
4932
|
+
const WORLD_MAP_WIDTH = 2e3;
|
|
4933
|
+
const WORLD_MAP_HEIGHT = 857;
|
|
4934
|
+
const COUNTRY_MAP_DEFAULTS = {
|
|
4935
|
+
fill: "#d0d0d0",
|
|
4936
|
+
stroke: "#ffffff",
|
|
4937
|
+
strokeWidth: 0.5,
|
|
4938
|
+
width: "100%",
|
|
4939
|
+
height: "auto",
|
|
4940
|
+
className: "",
|
|
4941
|
+
showCities: true,
|
|
4942
|
+
cityColor: "#555555",
|
|
4943
|
+
capitalColor: "#cc2222",
|
|
4944
|
+
cityRadius: 3,
|
|
4945
|
+
capitalRadius: 5,
|
|
4946
|
+
padding: 5
|
|
4947
|
+
};
|
|
4948
|
+
function latLonToMapPoint(lat, lon) {
|
|
4949
|
+
return {
|
|
4950
|
+
x: (lon + 180) * (WORLD_MAP_WIDTH / 360),
|
|
4951
|
+
y: (90 - lat) * (WORLD_MAP_HEIGHT / 180)
|
|
4952
|
+
};
|
|
4953
|
+
}
|
|
4954
|
+
function getCountrySubdivisionMapUrl(alpha3) {
|
|
4955
|
+
const code = alpha3.toUpperCase();
|
|
4956
|
+
return `https://upload.wikimedia.org/wikipedia/commons/thumb/maps/${code}.svg/800px-${code}.svg.png`;
|
|
4957
|
+
}
|
|
4958
|
+
function getCountrySvg(alpha2, options = {}) {
|
|
4959
|
+
const opts = { ...COUNTRY_MAP_DEFAULTS, ...options };
|
|
4960
|
+
const code = alpha2.toUpperCase();
|
|
4961
|
+
const countryData = getCountryMapData(code);
|
|
4962
|
+
if (!countryData || countryData.paths.length === 0) return null;
|
|
4963
|
+
const geo = getCountryGeography(code);
|
|
4964
|
+
if (!geo) return null;
|
|
4965
|
+
const { x: x1, y: y1 } = latLonToMapPoint(geo.bounds.north, geo.bounds.west);
|
|
4966
|
+
const { x: x2, y: y2 } = latLonToMapPoint(geo.bounds.south, geo.bounds.east);
|
|
4967
|
+
const minX = Math.min(x1, x2) - opts.padding;
|
|
4968
|
+
const minY = Math.min(y1, y2) - opts.padding;
|
|
4969
|
+
const boxW = Math.abs(x2 - x1) + opts.padding * 2;
|
|
4970
|
+
const boxH = Math.abs(y2 - y1) + opts.padding * 2;
|
|
4971
|
+
const viewBox = `${minX.toFixed(1)} ${minY.toFixed(1)} ${boxW.toFixed(1)} ${boxH.toFixed(1)}`;
|
|
4972
|
+
const pathsHtml = countryData.paths.map((d, i) => {
|
|
4973
|
+
const attrs = i === 0 ? ` id="${code}" data-code="${code}" data-name="${countryData.name}"` : ` data-code="${code}"`;
|
|
4974
|
+
return `<path${attrs} d="${d}" fill="${opts.fill}" stroke="${opts.stroke}" stroke-width="${opts.strokeWidth}"/>`;
|
|
4975
|
+
}).join("\n ");
|
|
4976
|
+
let cityMarkersHtml = "";
|
|
4977
|
+
if (opts.showCities) {
|
|
4978
|
+
const citiesForCountry = getCitiesByCountry(code);
|
|
4979
|
+
cityMarkersHtml = citiesForCountry.map((city) => {
|
|
4980
|
+
const { x, y } = latLonToMapPoint(city.lat, city.lon);
|
|
4981
|
+
const isCapital = city.capital === true;
|
|
4982
|
+
const r = isCapital ? opts.capitalRadius : opts.cityRadius;
|
|
4983
|
+
const color = isCapital ? opts.capitalColor : opts.cityColor;
|
|
4984
|
+
const capitalAttr = isCapital ? ' data-capital="true"' : "";
|
|
4985
|
+
return `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${r}" fill="${color}" data-city="${city.name}"${capitalAttr}><title>${city.name}${isCapital ? " (capital)" : ""}</title></circle>`;
|
|
4986
|
+
}).join("\n ");
|
|
4987
|
+
}
|
|
4988
|
+
const svgClass = opts.className ? ` class="${opts.className}"` : "";
|
|
4989
|
+
const body = cityMarkersHtml ? ` ${pathsHtml}
|
|
4990
|
+
${cityMarkersHtml}` : ` ${pathsHtml}`;
|
|
4991
|
+
return `<svg
|
|
4992
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4993
|
+
viewBox="${viewBox}"
|
|
4994
|
+
width="${opts.width}"
|
|
4995
|
+
height="${opts.height}"${svgClass}
|
|
4996
|
+
role="img"
|
|
4997
|
+
aria-label="${countryData.name} map">
|
|
4998
|
+
${body}
|
|
4999
|
+
</svg>`;
|
|
5000
|
+
}
|
|
4932
5001
|
export {
|
|
5002
|
+
COUNTRY_MAP_DEFAULTS,
|
|
4933
5003
|
WORLD_MAP_DEFAULTS,
|
|
4934
5004
|
WORLD_MAP_VIEWBOX,
|
|
4935
5005
|
bearing,
|
|
@@ -4955,6 +5025,8 @@ export {
|
|
|
4955
5025
|
getCountryGeography,
|
|
4956
5026
|
getCountryMapData,
|
|
4957
5027
|
getCountryMapSvgUrl,
|
|
5028
|
+
getCountrySubdivisionMapUrl,
|
|
5029
|
+
getCountrySvg,
|
|
4958
5030
|
getCurrencyByCode,
|
|
4959
5031
|
getCurrencyByCountry,
|
|
4960
5032
|
getDirectionBetweenCountries,
|
|
@@ -4975,6 +5047,7 @@ export {
|
|
|
4975
5047
|
getWorldMapSvg,
|
|
4976
5048
|
haversineDistance,
|
|
4977
5049
|
highlightCountries,
|
|
5050
|
+
latLonToMapPoint,
|
|
4978
5051
|
phoneCountryCodes,
|
|
4979
5052
|
searchCities,
|
|
4980
5053
|
searchWorldMapCountries,
|