Commit Graph

35 Commits

Author SHA1 Message Date
Kian-Meng Ang
4b32ae072b
Fix typos (#1225)
Found via `typos --hidden --format brief`
2024-03-03 02:54:01 -05:00
Yuri Astrakhan
0b4e3f95cf
write! perf optimization - use write_str (#1182) 2024-02-07 18:01:24 +00:00
Yuri Astrakhan
3dc54d7f9e
Implement tile caching (#1105)
Add a top level config parameter -- the size of cache memory (in MB) to
use for caching tiles and PMT directories, defaulting to 512, and 0 to
disable. This also removes the `pmtiles.dir_cache_size_mb` parameter (it
will be ignored, but will give a warning)

```
cache_size_mb: 512
```

The new cache will contain all tiles as provided by the source. So if
PostgreSQL returns a non-compressed tile, the cache will contain the
uncompressed variant, and will be compressed for each response. This
will be fixed in the later releases.

Note that fonts and sprites are not cached at this time, and are still a
TODO.
2023-12-30 22:48:23 -05:00
Yuri Astrakhan
4bf206bd7f doc links 2023-12-25 01:49:39 -05:00
Yuri Astrakhan
2def6288f1
PMTiles cache, refactor file configs, modularize (#1094)
* Make it possible to have configuration specific to the file-based
config sections: pmtiles, mbtiles, and sprites.
* Implement PMTiles directory cache shared between all pmtiles (both
http and local), with configurable max cache size (in MB), or 0 to
disable. Defaults to 32MB (?)
* PMTiles now share web client instance, which optimizes connection
reuse in case multiple pmtiles reside on the same host
* Major refactoring to allow modular reuse, enabling the following build
features:
    * **postgres** - enable PostgreSQL/PostGIS tile sources
    * **pmtiles** - enable PMTile tile sources
    * **mbtiles** - enable MBTile tile sources
    * **fonts** - enable font sources
    * **sprites** - enable sprite sources
* Use justfile in the CI

Fixes #1093
2023-12-25 05:52:04 +00:00
Yuri Astrakhan
24819bdb45
Multiple mbtiles and martin-cp fixes (#1083)
* BREAKING: `martin-cp` will now set `format=pbf` instead of `mvt`. This
is what QGIS and possibly others expect, and this is what tools like
tilelive generates.
* `martin-cp` sets `minzoom` and `maxzoom` metadata values based on the
zoom parameters
* Add `mbtiles meta-update` command to refresh zoom levels based on the
present tiles.

Partially addresses items in #1081
2023-12-18 23:19:36 -05:00
Yuri Astrakhan
fc15e0da5e Preparing release, version bump 2023-12-18 20:24:43 -05:00
Lucas
f21119d548
Fix bbox_to_xyz (#1070)
Figure out and fix the bug with `tile-grid` crate or remove the crate
and implement it ourself.

---------

Co-authored-by: Yuri Astrakhan <yuriastrakhan@gmail.com>
2023-12-18 00:02:49 -05:00
Yuri Astrakhan
bb802c5688
Feature: mbtiles copy --bbox ... to copy tiles within a bbox only (#1060)
Allow users to copy tiles between mbtiles files that are only within a
bounding box. Multiple `--bbox` params are allowed.
2023-12-15 23:13:57 -05:00
Yuri Astrakhan
886358e93f
Fix bbox to xyz roundtrip computation (#1059)
Add `tile-grid` as a dependency to use its webmercator tile math.

---------

Co-authored-by: sharkAndshark <zhangyijunmetro@hotmail.com>
2023-12-15 06:11:31 +00:00
Yuri Astrakhan
b97f1ccdbe Move utils to v0.2, MAX_ZOOM 2023-12-09 10:19:49 -05:00
Yuri Astrakhan
280dbe162f
Move math utils to martin-tile-utils (#1056)
Mathematics should be consolidated in the utils crate. Eventually, I
hope we will move it to [tile-grid](https://crates.io/crates/tile-grid)
or [utiles](https://crates.io/crates/utiles) crates and consolidate our
efforts there.

Also, modify earth circumference by a few centimeters (to match various
other implementations): from `.7` to `.685_578_5`. This modified a few
unit tests.
2023-12-09 04:38:15 +00:00
Yuri Astrakhan
999179029b Prepare for release 2023-11-20 01:51:08 -05:00
Lucas
a3b2bfd705
Minor cleanup (#1008)
- Add separators to long literal.
- Use first() instead of get(0)
- Move some SQL-making code to their own functions
- Minor mathematics and rounding cleanup

---------

Co-authored-by: Yuri Astrakhan <YuriAstrakhan@gmail.com>
2023-11-17 18:55:05 +00:00
Yuri Astrakhan
d8e386fb0c
Use Rust's 1.74 cargo lint section (#1006)
https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html
2023-11-17 08:29:25 +08:00
Yuri Astrakhan
73b56e8a90
Include readme as docs for all crates (#981)
This adds documentation in the https://docs.rs site.
2023-10-31 14:04:10 -04:00
Yuri Astrakhan
bfbe52d032 Add crate categories 2023-10-30 18:52:47 -04:00
Yuri Astrakhan
f1241e264c fix CI status badges 2023-10-28 16:29:38 -04:00
Yuri Astrakhan
0cf57a6a6a bump versions 2023-10-01 23:29:56 -04:00
Yuri Astrakhan
cd584faa30
mbtiles: remove tls features, CI streamlining (#908) 2023-09-29 20:40:32 -04:00
Yuri Astrakhan
4664d5ad8a update lock, minor toml sort cleanup 2023-07-05 20:56:23 -04:00
Yuri Astrakhan
a419d77fca Bump versions for release 2023-06-04 15:04:42 -04:00
Yuri Astrakhan
73af185737 readme for all packages 2023-06-04 00:56:20 -04:00
Yuri Astrakhan
36eab5f6bb bump martin-tile-utils version to v0.1.1 2023-06-03 23:26:44 -04:00
Yuri Astrakhan
2cdd373044
Refactor mbtiles lib, mbtiles tool tests & CI (#702)
* Broke up martin-mbtiles into multiple files
* Made all mbtiles functions take a `SqliteExecutor` -- this way they
can be used with any SQLX connection structs - either a pool connection
or an individual non-pooled connection.
* Simplified mbtiles bin a bit - I realized there is really no need to
pretty print the output for the single value retrieval. Easier to just
dump it to console as is.
* Bump martin-mbtiles to v0.2.0
* Minor fixes in tools docs, cargo.toml, and justfile
* MBTiles tool Integration tests and release publishing

Major thanks to the
[stackoverflow](https://stackoverflow.com/questions/76394665/how-to-pass-sqlx-connection-a-mut-trait-as-a-fn-parameter-in-rust/76395111)
quick reply by @cafce25 on how to use generic sql executor!
2023-06-04 00:54:50 +02:00
Yuri Astrakhan
18770664e1
Consolidate all crate dependencies (#694)
This moves all dependency version management to one location
2023-06-01 09:05:06 -04:00
Yuri Astrakhan
0ffd712927 bump versions, update lock 2023-03-25 14:41:52 -04:00
Yuri Astrakhan
9cd71476db
Prepare for sub-crate publish, detection bug fix (#615)
* tile format detection would crash on a rare edge case
* add some formatting and info about utils and mbtiles crates
2023-03-25 18:37:42 +00:00
Yuri Astrakhan
3fcad46500
fix (re-)compression of images (#579)
Compression middleware turned out to be hard to use for image cases - it
simply looks at the content-encoding, and if not set, tries to compress
if accepted by the client.

Instead, now individual routes are configured with either that
middleware, or for tiles, I decompress and optionally recompress if
applicable.

Now encoding is tracked separately from the tile content, making it
cleaner too. Plus lots of tests for mbtiles & pmtiles.

Fixes #577
2023-02-20 10:44:22 -05:00
Yuri Astrakhan
9e5ed2fc02
Add .mbtiles support (#549)
Adds a new [.mbtiles](https://github.com/mapbox/mbtiles-spec/blob/master/1.3/spec.md)
backend, without the grid support. Uses extensive tile content
detection, i.e. if the content is gzipped, png, jpeg, gif, webp.

From CLI, can be as easy as adding a path to a directory that contains a
.mbtiles file (works just like pmtiles support)

```bash
# All *.mbtiles files in this dir will be published.
# The filename will be used as the source ID
martin ./tests/fixtures
```

From configuration file, the path can be specified in a number of ways
(same as pmtiles)

```yaml
mbtiles:
  paths:
    # scan this whole dir, matching all *.mbtiles files
    - /dir-path
    # specific mbtiles file will be published as mbtiles2 source
    - /path/to/mbtiles2.mbtiles
  sources:
      # named source matching source name to a single file
      pm-src1: /tmp/mbtiles.mbtiles
      # named source, where the filename is explicitly set. This way we will be able to add more options later
      pm-src2:
        path: /tmp/mbtiles.mbtiles
```

Fixes #494
2023-01-09 00:10:23 -05:00
Yuri Astrakhan
e58773f7b0
Refactorings, content-type/enc, cli parsing, tests, minor fixes (#548)
* introduce a new Connections object to track all positional strings
passed as the CLI arguments
* each tile provider can now indicate if it can take a positional CLI
arg, and if the value can be shared between multiple providers, i.e. if
its a directory that could contain files for multiple providers
* make xyz use better types - u8 for zoom, u32 for x&y. Postgres casts
those to INT2 and INT8
* minor bug in pre-push git hook to abort in case of a testingerror
* added GIF detection/type
* combine MVT and compression concepts into one enum more explicitly. It
is not ideal (technically they are separate concerns), but it keeps it a
bit simpler for now for multiple providers.
* set content encoding and content type on HTTP responses if known, and
also include them in the `/catalog` response (json)
* raise an error if the user attempts to merge non-concatenatable tiles
from multiple sources. We may want to implement it in the future, e.g.
combine multiple semi-transparent PNGs. Or even combine GIF & PNG & JPEG
* do not set content-type on empty responses (http 204)
* add tilejson outputs to testing
2023-01-08 16:31:58 +02:00
Yuri Astrakhan
64ad07ce36
Fix legacy DB, add CI tests (#547)
* fixed SQL to work on older PG versions
* re-enable CI to test expected `test.sh` output against the one stored
in the `tests/expected`
* add postgres in docker tests on linux - one for the oldest supported
DB, and another using the more recent version
* minor justfile cleanup
* ensure config files are sorted alphabetically
2023-01-01 05:03:21 +00:00
Yuri Astrakhan
555a1fccdd
Improve Coverage tooling (#535)
* added manual coverage justfile command
* a lot of small refactorings of config and argument parsing
* feature: support jsonb query param for functions
* cleaned up public/private access
* make all tests populate with a predefined values to avoid issues with
random data
2022-12-27 06:56:27 +00:00
Yuri Astrakhan
cb99b835e9
Enable clippy pedantic, fix lints (#525)
Pedantic lints often offer some good insight into the code. It is
usually easier to sprinkle a few "allow"-s around, than to miss some
important life hack offered by clippy.

Also, make use a different martin port when running integration tests
locally (make sure `git push` works even if martin is running).
2022-12-18 21:24:06 -05:00
Yuri Astrakhan
66b7fdc4ea
Multi-source support, new path structure (#456)
Partial implementation of the #430

* New endpoint structure:
  * `GET /` -- a placeholder for the future home page
* `GET /catalog` -- get a list of available sources, as a list of json
blobs.
* `[{id, name, description, attribution, vector_layer}, ...]` (some
fields might be missing)
* `GET /<id>` -- get tilejson for the given source, or a combination of
sources. No `.json` extension
  * `GET /<id>/<z>/<x>/<y>` -- get a tile. No format extension.
  * `GET /health` -- healthcheck
* Introduce a new tile format support crate (using code from the
maplibre/mbtileserve project)
* Removed the `/rpc/...` routes - all source IDs are accessed in the
same way
* Can print auto-generated configuration or save it to a file
* Refactored to support multiple sources from multiple backends, with a
proper naming conflict resolution

TODO:
* benchmarks need to be rewritten - they were relying on some internal
structures that are no longer there. This might be done as a separate PR
due to a very different internal architecture - might need to rethink
benchmarking approaches.
2022-11-26 04:46:40 -05:00