本文へ移動

Chizu地図

SVGの地図を描き、地域を表示範囲に収め、番号付きの注記や地理クイズを英語と日本語の名前で作れます。

「地図」は、土地や場所を図で表したものです。 名前について(英語)

目次

リファレンス

表示範囲・形・クイズの道具

import { … } from "@johnmorrisdotca/chizu";

最小化と gzip 圧縮をしたサイズは 18.4 kB(読み込むものをすべて含み、esbuild で計測)

リファレンスの説明と例は英語です。見出しと目次は日本語です。

Chizu 地図: the engine round a map. Framing and zoom, insets, a world that wraps round, the outlines as points, quiz distractors, the callout placer, pasted place names, and the city scale (localMap: a place's own GeoJSON and pictures in a local projection), over plain ChizuMap data. Pure functions: each returns new values and never changes what it was given. No data, no drawing, no page: the maps are @johnmorrisdotca/chizu/world, /countries/<code> and /divisions/<code>; the drawing is /draw, the pan-and-zoom map in a page is /mount, and the names of every country are /names.

エクスポート

名前種類概要
applyInsetTransform関数The same move, applied to a point: a centroid, so a handle follows its region.
Bounds型The box round a shape: left, top, right, bottom.
boxCentre関数Where a box is looking, which is what a zoom step keeps hold of.
boxIsWholeMap関数True when the box shows the whole map rather than a zoomed-in window.
boxToViewBox関数A window as an SVG viewBox attribute.
CALLOUT_INSET定数How far in from the frame's edge the outermost circle's centre sits, in radii.
CALLOUT_RADIUS_RATIO定数The share of the window's width a circle's radius is, unless asked otherwise.
CALLOUT_ROOMY定数The sea a circle would like around it, in radii, and what having less costs it - so that open water wins over a bay with barely the room, without a bay being refused when it is the only water a region has.
calloutFaults関数The two faults a printed sheet is held to, counted over its placed leaders: pairs that cross, and pairs closer than a radius - or than they start, where two regions start closer than that - counting a line through another number's circle as close too.
calloutGrid関数The same places, with the grid they were found on.
CalloutKeepOut型The lengths of frame kept clear at the bottom-right corner, in the map's units: up the right edge before the corner and along the bottom edge after it, which is where the credit line is drawn.
CalloutLand型One drawn region, as the outlines it is actually drawn with.
CalloutObstacle型A box, which is what a leader is kept off and what the credit's corner is.
CalloutPlace型One place a circle could sit, and where it sits on the search grid.
CalloutRequest型The region codes, framing window, radius, numbering and layout options for a callout sheet.
calloutSpaces関数Every place in the frame where a circle fits clear of the land and of the credit's corner, on a grid fine enough to find the water beside a coast.
CalloutSpot型One numbered circle placed in open water, and the leader line that joins it to its region.
CHIZU_FEATURE_GROUPS定数The six groups, in the order they are drawn: seas under the land, then landforms, lakes, rivers, peaks and capitals on it.
CHIZU_FEATURE_KINDS定数The kinds in each group.
CHIZU_STRINGS定数Native English and Japanese map controls, descriptions and physical-feature labels.
ChizuCountry型One country in the table of every country: its names, and which of the maps has it.
ChizuFeature型One named physical feature on a map's canvas: a sea, a lake, a river, a landform or a peak.
ChizuFeatureChoice型What to show of a layer: water (seas, lakes and rivers), all, a group (marine, landforms, lakes, rivers, peaks, capitals) or a single kind (strait, reservoir, capital).
ChizuFeatureGroup型The six groups the features come in, in the order they are drawn: from Natural Earth's physical files, marine (oceans, seas, bays, straits), under the land, landforms (deserts, ranges, plains), drawn only when chosen, lakes, rivers and peaks; and from kuni 国, capitals (a country's capital, its regions' seats).
ChizuFeatureKind型What a named physical feature is: a kind of sea (ocean, sea, gulf, bay, strait, channel, sound, fjord, inlet, lagoon, reef), of lake (lake, reservoir), a river, a landform (desert, range, plateau, plain, peninsula, cape, basin, delta, valley, wetland, tundra, isthmus, depression, lowland, gorge, foothills), a peak, or a country's capital or a region's seat.
ChizuFeatureLayer型The named features of one map, drawn on that map's canvas: what loadFeatures(mapId) gives, and what drawChizu and mountChizu take as featureLayer.
ChizuGeoJson型GeoJSON as the engine reads it: a Feature, a FeatureCollection, or a bare geometry, in the loose shape JSON.parse and an imported .json file give (type is any string, and is checked as the data is read).
ChizuGroup型A named group of places: a continent, a UN M49 subregion, or any set of codes a page names (the countries of the EU, Japan's Kanto region).
ChizuInset型A region the map draws in a box of its own, instead of where its projection put it (Alaska, Hawaii, Okinawa).
ChizuLanguage型THE WORDS chizu says itself, in English and Japanese: what a screen reader hears of a drawing, and the labels on a mounted map's buttons.
chizuLanguageOf関数A language this package has words for, from a tag such as ja-JP or en: Japanese for any ja, English otherwise.
ChizuLocalCanvas型What a local map is made of: where, how big in metres, and how many metres a unit of its canvas is.
ChizuLocalMap型A map of a small place: a ChizuMap (so every function of the engine takes it) whose canvas is a city or a venue in a local projection, whose regions are the polygons of the data, and which also holds the lines, points, pictures and credits that drawLocal draws.
ChizuLocalMarker型A picture placed on a local map: where it is on the canvas, how many canvas units a unit of the picture is, and the turn that puts its top towards its bearing (the bearing less the map's grid convergence, localConvergence).
ChizuLocalMarkerInput型A picture to put on a local map, given as the caller has it.
ChizuLocalOptions型What a local map is made of.
ChizuLocalShape型One shape of a local map, in the canvas's units: an area (a closed outline, filled), a line (an open one) or a point.
ChizuMap型A map: a canvas and its regions.
ChizuPlace型The part of a region the engine reads, so a map of your own regions needs no more than these.
ChizuProjection型How a map's canvas was made from the earth, enough to put a longitude and latitude on it (projectPoint): Miller's cylindrical projection round a centre longitude (the world), a Lambert azimuthal equal-area projection round a centre (one country on its own), or, for a city or a single venue (localMap), a transverse Mercator on the WGS 84 ellipsoid round a centre (radius is its rectifying radius, in metres), a unit of the canvas being metresPerUnit metres.
ChizuRegion型One place on a map: a country on the world, a province or state on a country.
chizuSay関数A line of the board's words with its {name} values filled in.
circleMeetsRing関数Whether a circle of this radius at this point touches the land inside a ring.
distanceToRing関数How far a point is from a ring's outline, ignoring which side of it the point is on.
DISTRACTOR_SCORES定数What makes one place on a map a convincing wrong answer for another.
DistractorOptions型The wrong-answer count, optional seeded random source and candidate restriction.
distractorScore関数How tempting candidate is as a wrong answer for target, from 0 up to 200: 100 for a land neighbour, 60 for the same group, and up to 40 for being close, measured against diagonal, the corner-to-corner length of the map (each map is drawn on a canvas of its own, so a distance only means something relative to it).
featureChosen関数Whether a feature is among the choices.
featureKindName関数What a kind of feature is called, in a language: Sea and 海, Mountain range and 山脈.
featureKindOf関数What a feature is called as a kind, on the map it is drawn on: featureKindName, except that a kind may have a word of its own in one country, written kind.<kind>.<COUNTRY> in CHIZU_STRINGS and read from the country in a seat's code (seat-JP-47).
featureMap関数A layer as a map of its own: the same canvas, the features as its regions.
featuresShown関数The features of a layer that are among the choices, in the layer's order (seas first, peaks last).
findFeatures関数The features a few typed letters may mean, best first: a name (English or Japanese) or reading that is the words typed, then one that begins with them, then one with a word that does, then one that holds them anywhere; within each, the higher ranked first.
findQuestion関数Makes the question: the target, count of the most tempting wrong answers for it (pickDistractors), and all of them put in a random order.
FindQuestion型A "which one is this?" question: the place asked about, the choices (it among its look-alikes) and where it is in them.
focusBox関数The window that frames these regions, or the whole map when none are given.
focusRegionFit関数What choosing one place computes: zoom in to fit it, whatever zoom the reader was already at.
groundDistance関数How far, in metres, two places are from each other, along the ground: the local projection centred half way between them, so within a hair of the ellipsoid up to 400 km.
groupBox関数The window that shows a group whole, shaped to the frame it is drawn in (aspect, how much wider than tall), with a little room round it.
groupMap関数The map cut down to a group: the same canvas, only the regions whose codes are given (in the map's order), only their boxes, and neighbours only among themselves.
groupTones関数Tones that fade every region outside a group (faint unless another tone is named) and leave the group's own as they are, or give them inside's tones: for a map of a continent drawn on the world, with its neighbours as a pale coast round it.
HANDLE_CLEARANCE定数How far apart two handle centres must be, in radii.
HANDLE_LAYOUTS定数How a map places its numbered handles: on each region, or in the space around it.
HANDLE_RADIUS_RATIO定数A handle's radius as a share of the framed width, so it holds up at any zoom.
HANDLE_SLOTS定数Positions a handle will try, in order, measured in radii from the centroid.
HandleBounds型A box the handles should stay inside, so none is cropped at the frame edge.
HandleLayout型The native ordering, candidate positions and constraints used to place numbered callouts.
handleRadius関数A handle's radius in the map's own units, for a window this wide and a share of the usual size.
HandleSpot型A numbered region’s label position, native land anchor and leader geometry.
insetFor関数The inset a region is drawn in, or null when it is drawn where it is.
insetHoldsWhole関数Whether a box holds its region whole, rather than only some of its pieces (outlyingBelow, within).
insetsFor関数Every box a region is drawn in, in the map's order: none for most, one for Alaska, three for Okinawa (its main islands, the Sakishima Islands and the Daito Islands, each in a box of its own) and three for Tokyo's far islands.
insetTransform関数What to do to a region's own geometry to seat it in its box: shrink it to fit if it is too big, centre it in the frame, and leave it at its own size unless the box says it may be magnified.
InsetTransform型What to do to a region's own geometry to seat it in its box: a scale, and a move.
insetTransformAttribute関数The SVG transform attribute the move is written as.
isMapZoom関数Whether a number is one of the zoom steps.
landAnchor関数A point on the region's own land, for a leader to end at.
layoutCallouts関数Numbered circles in the open space around and between the regions of a map, each with a leader line to its region.
localCanvasFromBox関数The local canvas that shows the ground a window on a world or country map shows, so a page can hand over from the map to the city at the moment it has zoomed past what the map knows, with nothing jumping: at its own 1× the local map covers the same ground as the window did.
localConvergence関数The angle, in degrees, between true north and the canvas's up at a place: how much a thing that points at a true bearing is turned on a local map.
localMap関数A local map: the ground of a city or a venue, from caller-given GeoJSON and pictures, in a projection made for a small piece of the earth.
mainlandBounds関数The box around a region as anyone would picture it: its largest outline, and whatever else is close enough to belong in the same glance.
MAP_ZOOM_LEVELS定数How far in the map is drawn, as steps rather than a free zoom.
MapBox型A window on a map, in the map's own units: what an SVG viewBox says.
mapBoxFromLocal関数The window on a world or country map that a local map covers, the way back from the city: the smallest window that holds the ground of the local window (all of the canvas unless box is given).
mapBoxMetres関数How many metres of ground a window on a world or country map shows, across and down: the number to compare with a city's size when deciding that a map has been zoomed past what Natural Earth can say and a local map should take over.
mapDiagonal関数The corner-to-corner length of a map's canvas, which proximity is measured against.
MapOutline型A map's outlines, drawn where they are drawn: a region in a box carried into it, outlying islands in a box carried into theirs, everything else where the projection put it.
mapOutlines関数The outlines of every region of a map, in the map's order, with a point on each one's land.
MapPiece型How one region is drawn: usually in one piece, where it is.
mapRegionPieces関数The region’s separate drawn pieces, including the geometry moved into its inset boxes.
MapRing型One closed outline: a region's mainland, or one of its islands.
mapWrapsAround関数Whether this map's east and west edges are the same edge.
MapZoom型One of the native whole-number zoom steps from 1 to 10.
MatchOptions型A set of regions made from a list of place names somebody pasted.
nameOf関数What a region is called in a language: the English name, or in Japanese the everyday short name where there is one (アメリカ), else the full Japanese name, else the English.
nearestWrappedBox関数The copy of a window nearest another one.
orderByPosition関数The choices in the order they run across the map, west to east.
parseMapRings関数The rings of one region's path, in the order it draws them, each with its own box.
PastedPlaces型Matched native places in paste order and the original text items that were not found.
pickDistractors関数The wrong answers to "which one is this?": the codes of count places, drawn from the most tempting ones for the target, never the target itself.
placeCallouts関数Places every circle in the open space around the map.
placeHandles関数Places every handle clear of the ones before it.
placesFromText関数The regions a paste names.
pointInRing関数Whether a point is inside a ring, by the crossing rule.
POLISH_CIRCLE_CLEAR_RADII定数How far a leader keeps from the middle of another number's circle, in radii: past the ring, with air.
POLISH_CLOSE_RADII定数How close two leaders may come, in radii.
projectPoint関数Where a longitude and latitude (in degrees) fall on the map's canvas, as [x, y]; null for a map whose canvas cannot be reversed from here.
Random型A number in [0, 1), like Math.random, from a stream a seed fixes.
regionBox関数A window tight on one region, for drawing it on its own.
regionCentre関数The middle of a region, for zooming to whatever somebody just chose: where it is drawn, not where it is.
regionGroups関数The groups a map's regions fall in, by their group, in the order the map first names them: the continents on the world, the eight regions on Japan's prefectures, the four Census regions on the United States'.
Scorable型The parts of a place this scoring reads, so a map of your own places needs no more than these.
seaAround関数How much water is around a point before this ring's land, never looking further than reach - a place far from every coast only has to be known to be far, and walking six thousand points to find out how far is the bill this runs up on every draw.
seededRandom関数A stream of numbers in [0, 1) fixed by a seed.
segmentCrossesBox関数Whether a straight leader from a to b passes through this box.
segmentMeetsRing関数Whether a straight line from one point to another passes over the land inside a ring.
segmentsCross関数Whether two leaders cross.
segmentsGap関数How close two leaders come, where they do not cross: the nearest any point of one gets to the other.
shapeGlyphBox関数A square window on one region's own outline, for drawing it as an icon: every shape gets the same box and fills it, so a small region is as legible in a list as a large one.
shiftedOutlines関数Copies of the outlines translated horizontally by the supplied map-unit offset.
shuffled関数A copy of the list in a random order (Fisher–Yates, from the end); the list given is left alone.
splitPastedPlaces関数A paste split into its lines, on the separators a pasted list actually uses.
stepMapZoom関数One step in or out, clamped: the ends stay put rather than wrapping.
unprojectPoint関数The longitude and latitude (in degrees) of a point on the map's canvas, as [lon, lat]; null where projectPoint is.
VERSION定数The package's version, which a test holds equal to package.json's.
wholeMapBox関数The whole canvas as a window.
wrapAcross関数A coordinate brought back onto the canvas, for a pan that has gone round.
wrapIntoBox関数The copy of a point that this window shows, or null when it shows none.
wrapOffsets関数The copies of the canvas this window sees, as x offsets in map units: [0] while the window is wholly on the canvas, which is most of the time.
zoomBox関数The window a zoom step and a centre make.
zoomToFit関数The zoom step and centre that show all of these regions at once: for opening a region from its heading, which wants it filling the view and not the whole map with a few regions lit somewhere in it.

ソースを見るGitHub で編集@johnmorrisdotca/chizu 1.5.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。