map::slippy(n)
โจ map::slippy(n) โจ โ Mapping utilities
okay so bestie, this is the manual for map::slippy(n) from the Mapping utilities collection. It's part 1, and it's lowkey iconic. Let's get into it. ๐ซถ
๐ธ NAME ๐ธ
map::slippy โ Common code for slippy based map packages. That's the whole name vibe. ๐
โจ SYNOPSIS โจ
First, the package requirements and the full command list, no cap:
package require Tcl 8.6 9
package require map::slippy ?0.10?
::map slippy geo box 2point zoom geobox
::map slippy geo box center geobox
::map slippy geo box corners geobox
::map slippy geo box diameter geobox
::map slippy geo box dimensions geobox
::map slippy geo box fit geobox canvdim zmax ?zmin?
::map slippy geo box inside geobox geo
::map slippy geo box limit geobox
::map slippy geo box opposites geobox
::map slippy geo box perimeter geobox
::map slippy geo box valid geobox
::map slippy geo box valid-list geoboxes
::map slippy geo distance geo1 geo2
::map slippy geo distance* closed geo...
::map slippy geo distance-list closed geo-list
::map slippy geo limit geo
::map slippy geo bbox geo...
::map slippy geo bbox-list geo-list
::map slippy geo center geo...
::map slippy geo center-list geo-list
::map slippy geo diameter geo...
::map slippy geo diameter-list geo-list
::map slippy geo 2point zoom geo
::map slippy geo 2point* zoom geo...
::map slippy geo 2point-list zoom geo-list
::map slippy geo valid geo
::map slippy geo valid-list geos
::map slippy length level
::map slippy limit2 x
::map slippy limit3 x
::map slippy limit6 x
::map slippy point box 2geo zoom pointbox
::map slippy point box center pointbox
::map slippy point box corners pointbox
::map slippy point box diameter pointbox
::map slippy point box dimensions pointbox
::map slippy point box inside pointbox point
::map slippy point box opposites pointbox
::map slippy point box perimeter pointbox
::map slippy point distance point1 point2
::map slippy point distance* closed point...
::map slippy point distance-list closed point-list
::map slippy point bbox point...
::map slippy point bbox-list point-list
::map slippy point center point...
::map slippy point center-list point-list
::map slippy point diameter point...
::map slippy point diameter-list point-list
::map slippy point 2geo zoom point
::map slippy point 2geo* zoom point...
::map slippy point 2geo-list zoom point-list
::map slippy point simplify radial threshold point-list
::map slippy point simplify rdp point-list
::map slippy pretty-distance x
::map slippy tiles level
::map slippy tile size
::map slippy tile valid zoom row column levels ?msgvar?
::map slippy valid latitude x
::map slippy valid longitude x
๐ฆ DESCRIPTION ๐ฆ
This package provides a number of methods doing things needed by all types of slippy-based map packages. It's the friend that has your back for all your slippy map needs. ๐
โ ๏ธ BEWARE, Attention Version 0.9 is NOT backward compatible with version 0.7 and earlier. The entire API was heavily revised and changed. So if you're coming from 0.7, it's not me, it's the API. ๐ญ
๐ Note: For the representation of locations in the various coordinate systems used by the commands of this package please read section Coordinate systems. The command descriptions will not repeat them, and assume that they are understood already. iykyk.
๐ COORDINATE SYSTEMS ๐
The commands of this package operate in two distinct coordinate systems, geographical locations, and points. The former represents coordinates for locations on Earth, while the latter is for use on Tk canvas widgets. Two totally different vibes, bestie. ๐๐ฅ๏ธ
๐ GEOGRAPHIC ๐
Geographical locations (short: geo) are represented by a pair of Latitude and Longitude values, each of which is measured in degrees, as they are essentially angles. Yes, angles. Math is mathing. ๐
The Zero longitude is the Greenwich meridian, with positive values going east, and negative values going west, for a total range of +/- 180 degrees. Note that +180 and -180 longitude are the same meridian, opposite to Greenwich. So like, same same but different. ๐
The zero latitude is the Equator, with positive values going north and negative values going south. While the true range is +/- 90 degrees the projection used by the package requires us to cap the range at roughly +/- 85.05112877983284 degrees. This means that the North and South poles are not representable and not part of any map. Sorry polar bears, no map for you. ๐ปโโ๏ธ๐ญ
A geographical location is represented by a list containing two values, the latitude, and longitude of the location, in this order. Lat first, then long. Don't mix it up. ๐
A geographical bounding box is represented by a list containing four values, the minimal latitude and longitude of the box, and the maximal latitude and longitude of the box, in this order. Min lat, min long, max lat, max long. Got it. ๐ฆ
Geographical locations and boxes can be converted to points and their boxes by means of an additional parameter, the zoom level. This parameter indicates the size of the map in the canvas the coordinates are to be projected into. Zoom zoom. ๐
๐ POINTS ๐
Points (short: point) are represented by a pair of x and y values, each of which is measured in pixels. They reference a location in a Tk canvas widget. As a map can be shown at different degrees of magnification, the exact pixel coordinates for a geographical location depend on this zoom level. Pixels go brrr. ๐ฅ๏ธโจ
For the following explanation to make sense it should be noted that a map shown in a Tk canvas widget is split into equal-sized quadratic tiles. Yes, squares. ๐ฆ
Point coordinates are tile coordinates scaled by the size of these tiles. This package uses tiles of size 256, which is the standard size used by many online servers providing map tiles of some kind or other. 256, the magic number. ๐ข
A point is represented by a list containing the x- and y-coordinates of the location, in this order. x first, y second. Don't @ me. ๐
A point bounding box is represented by a list containing four values, the minimal x and y of the box, and the maximal x and y of the box, in this order. Min x, min y, max x, max y. ๐ฆ
Point locations and boxes can be converted to geographical locations and their boxes by means of an additional parameter, the zoom level. This parameter indicates the size of the map in the canvas the coordinates are projected from. ๐
Tile coordinates appear only in one place of the API, in the signature of command map slippy tile valid. Everything else uses Point coordinates. So like, tile coords are the special guest star. ๐
Using tile coordinates in the following however makes the structure of the map at the various zoom levels (magnification factors) easier to explain.
Generally the integer part of the tile coordinates represent the row and column number of a tile of the map, whereas the fractional parts signal how far inside that tile the location in question is, with pure integer coordinates (no fractional part) representing the upper left corner of a tile.
The zero point of the map is at the upper left corner, regardless of zoom level, with larger coordinates going right (east) and down (south), and smaller coordinates going left (west) and up (north). Again regardless of zoom level. So up-left is zero, down-right is more. ๐งญ
Negative coordinates are not allowed. Periodt. ๐ซ
At zoom level 0 the entire map is represented by a single tile, putting the geographic zero at 1/2, 1/2 in terms of tile coordinates, and the range of tile coordinates as [0...1]. One tile to rule them all. ๐
When going from zoom level N to the next deeper (magnified) level (N+1) each tile of level N is split into its four quadrants, which then are the tiles of level N+1. Quadrants, quadrants, quadrants. ๐ฒ๐ณ
This means that at zoom level N the map is sliced (horizontally and vertically) into 2^N rows and columns, for a total of 4^N tiles, with the tile coordinates ranging from 0 to 2^N+1. Math! ๐ค
๐ ๏ธ API ๐ ๏ธ
Now the commands, bestie. Each one is a little gift. ๐
::map slippy geo box 2point zoom geobox
The command converts the geographical box geobox to a point box in the canvas, for the specified zoom level, and returns that box. Glow-up from geo to point. โจ
::map slippy geo box center geobox
The command returns the center of the geographical box geobox. Dead center, like your aesthetic. ๐ฏ
::map slippy geo box corners geobox
This command returns a list containing the four corner locations implied by the geographical box geobox. The four points are top-left, bottom-left, top-right, and bottom-right, in that order. Four corners, four vibes. ๐ฒ
::map slippy geo box diameter geobox
The command returns the diameter of the geographical box geobox, in meters. Meters, bestie. ๐
::map slippy geo box dimensions geobox
The command returns the dimensions of the geographical box geobox, width and height, in this order. Width first, height second. Don't @ me. ๐
::map slippy geo box fit geobox canvdim zmax ?zmin?
This command calculates the zoom level such that the geobox will fit into a viewport given by canvdim (a 2-element list containing the width and height of said viewport) and returns it. Fit check! ๐ธ
The zoom level will be made to fit within the range zmin...zmax. When zmin is not specified it will default to 0. Default is zero, no cap. 0๏ธโฃ
::map slippy geo box inside geobox geo
The command tests if the geographical location geo is contained in the geographical box geobox or not. It returns true if so, and false else. In or out? True or false? ๐
::map slippy geo box limit geobox
This command limits the geographical box to at most 6 decimals and returns the result. Six decimals, that's the limit. โ
For geographical coordinates 6 decimals is roughly equivalent to a grid of 11.1 cm. 11.1 cm, that's precise. ๐
::map slippy geo box opposites geobox
This command returns a list containing the two principal corner locations implied by the geographical box geobox. The two points are top-left, and bottom-right, in that order. Opposites attract. ๐งฒ
::map slippy geo box perimeter geobox
The command returns the perimeter of the geographical box geobox, in meters. Walk the perimeter. ๐ถโโ๏ธ
::map slippy geo box valid geobox
This commands tests if the specified geographical box contains only valid latitudes and longitudes. It returns true if the box is valid, and false else. Valid check. โ
::map slippy geo box valid-list geoboxes
This commands tests if the list of geographical boxes contains only valid latitudes and longitudes. It returns true if all the boxes are valid, and false else. All of them? Valid list energy. ๐
::map slippy geo distance geo1 geo2
This command computes the great-circle distance between the two geographical locations in meters and returns that value. Great-circle, like the shortest path on a sphere. ๐
The code is based on https://wiki.tcl-lang.org/page/geodesy take on the haversine formula [https://en.wikipedia.org/wiki/Haversine_formula]. Haversine formula, iconic. ๐
::map slippy geo distance* closed geo...
An extension of map slippy geo distance this command computes the cumulative distance along the path specified by the ordered set of geographical locations in meters, and returns it. Cumulative distance, so it adds it all up. ๐
Okay so real quick, finishing the thought from the last one โ if the path is marked as closed (i.e. a polygon/loop) the result contains the distance between last and first element of the path as well, making the result the length of the perimeter of the area described by the locations. ๐ฆ
::map slippy geo distance-list closed geo-listโ literally the same energy asmap slippy geo distance*, except it takes the path you're measuring as one single list of geographical locations instead of a whole varying number of arguments. Same math, tidier hands. ๐::map slippy geo limit geoโ this one caps your geographical location at at most 6 decimals and hands back the result. And for geographical coordinates, 6 decimals is roughly equivalent to a grid of 11.1 cm. That's the vibe. ๐::map slippy geo bbox geo...and::map slippy geo bbox-list geo-listโ these two compute the bounding box for the set of geographical locations you give them and return a geographical box. When no geographical locations are specified the box is"0 0 0 0". And the locations come in as either a varying number of arguments, or as a single list โ dealer's choice bestie. โจ::map slippy geo center geo...and::map slippy geo center-list geo-listโ these two compute the center of the bounding box for the specified set of geographical locations. When no geographical locations are specified the center is"0 0". Again, locations are either a varying number of arguments, or a single list. ๐ฏ::map slippy geo diameter geo...and::map slippy geo diameter-list geo-listโ these two compute the diameter for the specified set of geographical locations, in meters. The diameter is the maximum of the pair-wise distances between all locations. When less than two geographical locations are specified the diameter is"0". And yup โ varying number of arguments, or a single list. ๐::map slippy geo 2point zoom geoโ converts the geographical location geo into a point in the canvas for the zoom level you specify, and returns that point. ๐บ๏ธ::map slippy geo 2point* zoom geo...and::map slippy geo 2point-list zoom geo-listโ these two are extensions ofmap slippy geo 2pointthat take a whole series of geographical locations (as either a varying number of arguments or a single list), convert them all to points per the specified zoom level, and return a list of the results. Glow up. ๐::map slippy geo valid geoโ tests if the specified geographical location contains only valid latitudes and longitudes. Returnstrueif the location is valid, andfalseelse. โ::map slippy geo valid-list geosโ same test, but for a whole list of geographical locations. Returnstrueif all the locations are valid, andfalseelse. ๐ซถ::map slippy length levelโ returns the width/height of a slippy-based map at the specified zoom level, in pixels. In essence, this is the result of:
expr { [tiles $level] * [tile size] }
::map slippy limit2 x,::map slippy limit3 x, and::map slippy limit6 xโ these cap the value at at most 2, 3, or 6 decimals respectively, and return the result. And for geographical coordinates, 6 decimals is roughly equivalent to a grid of11.1 cm. ๐::map slippy point box 2geo zoom pointboxโ converts the point box pointbox into a geographical box in the canvas, per the specified zoom level, and returns that box. ๐ฆ::map slippy point box center pointboxโ returns the center of the pointbox. Simple. Iconic. ๐::map slippy point box corners pointboxโ returns a list of the four corner locations implied by the point box pointbox. The four points are top-left, bottom-left, top-right, and bottom-right, in that order. Don't shuffle them bestie, order matters. ๐ธ::map slippy point box diameter pointboxโ returns the diameter of the pointbox, in pixels. ๐::map slippy point box dimensions pointboxโ returns the dimensions of the pointbox โ width and height, in this order. ๐ฆ::map slippy point box inside pointbox pointโ tests if the point is contained in the pointbox or not. Returnstrueif so, andfalseelse. ๐::map slippy point box opposites pointboxโ returns a list of the two principal corner locations implied by the point box pointbox. The two points are top-left, and bottom-right, in that order. ๐::map slippy point box perimeter pointboxโ returns the perimeter of the pointbox, in pixels. Walk it around the block. ๐ถโโ๏ธ::map slippy point distance point1 point2โ computes the euclidean distance between the two points in pixels and returns that value. ๐งฎ::map slippy point distance* closed point...โ an extension ofmap slippy point distance, it computes the cumulative distance along the path specified by the ordered set of points, and returns it. And if the path is marked as closed (i.e. a polygon/loop) the result contains the distance between last and first element of the path as well, making the result the length of the perimeter of the area described by the locations. Round and round we go. ๐::map slippy point distance-list closed point-listโ as a variant ofmap slippy point distance*, this one takes the path you're measuring as a single list of points instead of a varying number of arguments. โจ::map slippy point bbox point...and::map slippy point bbox-list point-listโ these two compute the bounding box for the specified set of points and return a point box. When no points are specified the box is"0 0 0 0". And the locations are given as either a varying number of arguments, or as a single list. ๐::map slippy point center point...and::map slippy point center-list point-listโ these two compute the center of the bounding box for the specified set of points. When no points are specified the center is"0 0". Same deal โ varying number of arguments, or a single list. ๐ฏ::map slippy point diameter point...and::map slippy point diameter-list point-listโ these two compute the diameter for the specified set of points, in pixels. The diameter is the maximum of the pair-wise distances between all locations. When less than two points are specified the diameter is"0". And yup, varying arguments or a single list. ๐::map slippy point 2geo zoom pointโ converts the point in the canvas, for the specified zoom level, into a geographical location, and returns that location. ๐บ๏ธ::map slippy point 2geo* zoom point...and::map slippy point 2geo-list zoom point-listโ these two are extensions ofmap slippy point 2geothat take a series of points as either a varying number of arguments or a single list, convert them all to geographical locations per the specified zoom level, and return a list of the results. ๐::map slippy point simplify radial threshold point-listโ takes a path of points (as a single list), simplifies it using the Radial Distance algorithm, and returns the simplified path as a list of points. In essence the algorithm keeps only the first of adjacent points nearer to that first point than the threshold, and drops the others. Declutter, but make it geometry. ๐งน::map slippy point simplify rdp point-listโ takes a patch of points (as a single list), simplifies it using the non-parametric Ramer-Douglas-Peucker algorithm, and returns the simplified path as a list of points. Fancy name, clean results. โจ::map slippy pretty-distance xโ formats the distance x (in meters) for display and returns the resulting string (including the chosen unit). Sub-kilometer distances are limited to 2 decimals, i.e. centimeters, whereas Kilometers are limited to 3 decimals, i.e. meters. It's giving presentable. ๐::map slippy tiles levelโ returns the width/height of a slippy-based map at the specified zoom level, in tiles. ๐งฑ::map slippy tile sizeโ returns the width/height of a tile in a slippy-based map, in pixels. One lil square, measured. ๐ฆ::map slippy tile valid zoom row column levels ?msgvar?โ checks if the tile described by zoom, row, and column is valid for a slippy-based map having that many zoom levels, or not. The result is a boolean value โtrueif the tile is valid, andfalseotherwise. In the latter case a message is left in the variable named by msgvar, should it be specified. ๐::map slippy valid latitude xโ tests if the argument x is a valid latitude value, and returns the boolean result of that test. I.e.trueif the value is valid, andfalseelse. ๐::map slippy valid longitude xโ tests if the argument x is a valid longitude value, and returns the boolean result of that test. I.e.trueif the value is valid, andfalseelse. ๐
๐ REFERENCES ๐
[1]http://wiki.openstreetmap.org/wiki/Main_Pageโ the source of truth, go read it bestie ๐
๐ KEYWORDS ๐
geodesy, geography, latitute, location, longitude, map, slippy, zoom
And that's a wrap on map::slippy(n), brought to you by tcllib, version 0.10 โ courtesy of the tcllib crew, no cap. Go map something gorgeous. ๐โจ๐ธ
๐ฆ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 ยท TCL
- fedora 44: tcllib 2.0-4.fc44 ยท TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms