GithubHelp home page GithubHelp logo

consbio / mbtileserver Goto Github PK

View Code? Open in Web Editor NEW
600.0 17.0 95.0 59.24 MB

Basic Go server for mbtiles

License: ISC License

Go 93.69% HTML 5.36% JavaScript 0.21% Dockerfile 0.73%
go vector-tiles mbtiles tilesets tilejson

mbtileserver's Introduction

mbtileserver

A simple Go-based server for map tiles stored in mbtiles format.

Build Status Coverage Status GoDoc Go Report Card

It currently provides support for png, jpg, webp, and pbf (vector tile) tilesets according to version 1.0 of the mbtiles specification. Tiles are served following the XYZ tile scheme, based on the Web Mercator coordinate reference system. UTF8 Grids are no longer supported.

In addition to tile-level access, it provides:

  • TileJSON 2.1.0 endpoint for each tileset, with full metadata from the mbtiles file.
  • a preview map for exploring each tileset.
  • a minimal ArcGIS tile map service API

We have been able to host a bunch of tilesets on an AWS t2.nano virtual machine without any issues.

Goals

  • Provide a web tile API for map tiles stored in mbtiles format
  • Be fast
  • Run on small resource cloud hosted machines (limited memory & CPU)
  • Be easy to install and operate

Supported Go versions

Requires Go >= 1.18+.

mbtileserver uses go modules and follows standard practices as of Go 1.18.

Installation

You can install this project with

go install github.com/consbio/mbtileserver@latest

This will create and install an executable called mbtileserver.

Usage

From within the repository root ($GOPATH/bin needs to be in your $PATH):

$  mbtileserver --help
Serve tiles from mbtiles files

Usage:
  mbtileserver [flags]

Flags:
      --basemap-style-url string   Basemap style URL for preview endpoint (can include authorization token parameter if required by host)
      --basemap-tiles-url string   Basemap raster tiles URL pattern for preview endpoint (can include authorization token parameter if required by host): https://some.host/{z}/{x}/{y}.png
  -c, --cert string                X.509 TLS certificate filename.  If present, will be used to enable SSL on the server.
  -d, --dir string                 Directory containing mbtiles files.  Can be a comma-delimited list of directories. (default "./tilesets")
      --disable-preview            Disable map preview for each tileset (enabled by default)
      --disable-svc-list           Disable services list endpoint (enabled by default)
      --disable-tilejson           Disable TileJSON endpoint for each tileset (enabled by default)
      --domain string              Domain name of this server.  NOTE: only used for AutoTLS.
      --dsn string                 Sentry DSN
      --enable-arcgis              Enable ArcGIS Mapserver endpoints
      --enable-fs-watch            Enable reloading of tilesets by watching filesystem
      --enable-reload-signal       Enable graceful reload using HUP signal to the server process
      --generate-ids               Automatically generate tileset IDs instead of using relative path
  -h, --help                       help for mbtileserver
      --host string                IP address to listen on. Default is all interfaces. (default "0.0.0.0")
  -k, --key string                 TLS private key
      --missing-image-tile-404     Return HTTP 404 error code when image tile is misssing instead of default behavior to return blank PNG
  -p, --port int                   Server port. Default is 443 if --cert or --tls options are used, otherwise 8000. (default -1)
  -r, --redirect                   Redirect HTTP to HTTPS
      --root-url string            Root URL of services endpoint (default "/services")
  -s, --secret-key string          Shared secret key used for HMAC request authentication
      --tiles-only                 Only enable tile endpoints (shortcut for --disable-svc-list --disable-tilejson --disable-preview)
  -t, --tls                        Auto TLS via Let's Encrypt
  -v, --verbose                    Verbose logging

So hosting tiles is as easy as putting your mbtiles files in the tilesets directory and starting the server. Woo hoo!

You can have multiple directories in your tilesets directory; these will be converted into appropriate URLs:

<tile_dir>/foo/bar/baz.mbtiles will be available at /services/foo/bar/baz.

If --generate-ids is provided, tileset IDs are automatically generated using a SHA1 hash of the path to each tileset. By default, tileset IDs are based on the relative path of each tileset to the base directory provided using --dir.

When you want to remove, modify, or add new tilesets, simply restart the server process or use one of the reloading processes below.

If a valid Sentry DSN is provided, warnings, errors, fatal errors, and panics will be reported to Sentry.

If redirect option is provided, the server also listens on port 80 and redirects to port 443.

If the --tls option is provided, the Let's Encrypt Terms of Service are accepted automatically on your behalf. Please review them here. Certificates are cached in a .certs folder created where you are executing mbtileserver. Please make sure this folder can be written by the mbtileserver process or you will get errors. Certificates are not requested until the first request is made to the server. We recommend that you initialize these after startup by making a request against https://<hostname>/services and watching the logs from the server to make sure that certificates were processed correctly. Common errors include Let's Encrypt not being able to access your server at the domain you provided. localhost or internal-only domains will not work.

If either --cert or --tls are provided, the default port is 443.

You can also use environment variables instead of flags, which may be more helpful when deploying in a docker image. Use the associated flag to determine usage. The following variables are available:

  • PORT (--port)
  • TILE_DIR (--dir)
  • GENERATE_IDS (--generate-ids)
  • ROOT_URL (--root-url)
  • DOMAIN (--domain)
  • TLS_CERT (--cert)
  • TLS_PRIVATE_KEY (--key)
  • HMAC_SECRET_KEY (--secret-key)
  • AUTO_TLS (--tls)
  • REDIRECT (--redirect)
  • DSN (--dsn)
  • VERBOSE (--verbose)

Example:

PORT=7777 TILE_DIR=./path/to/your/tiles VERBOSE=true mbtileserver

In a docker-compose.yml file it will look like:

mbtileserver:
  ...

  environment:
    PORT: 7777
    TILE_DIR: "./path/to/your/tiles"
    VERBOSE: true
  entrypoint: mbtileserver

  ...

Reloading

Reload using a signal

mbtileserver optionally supports graceful reload (without interrupting any in-progress requests). This functionality must be enabled with the --enable-reload-signal flag. When enabled, the server can be reloaded by sending it a HUP signal:

kill -HUP <pid>

Reloading the server will cause it to pick up changes to the tiles directory, adding new tilesets and removing any that are no longer present.

Reload using a filesystem watcher

mbtileserver optionally supports reload of individual tilesets by watching for filesystem changes. This functionality must be enabled with the --enable-fs-watch flag.

All directories specified by -d / --dir and any subdirectories that exist at the time the server is started will be watched for changes to the tilesets.

An existing tileset that is being updated will be locked while the file on disk is being updated. This will cause incoming requests to that tileset to stall for up to 30 seconds and will return as soon as the tileset is completely updated and unlocked. If it takes longer than 30 seconds for the tileset to be updated, HTTP 503 errors will be returned for that tileset until the tileset is completely updated and unlocked.

Under very high request volumes, requests that come in between when the file is first modified and when that modification is first detected (and tileset locked) may encounter errors.

WARNING: Do not remove the top-level watched directories while the server is running.

WARNING: Do not create or delete subdirectories within the watched directories while the server is running.

WARNING: do not generate tiles directly in the watched directories. Instead, create them in separate directories and copy them into the watched directories when complete.

Using with a reverse proxy

You can use a reverse proxy in front of mbtileserver to intercept incoming requests, provide TLS, etc.

We have used both Caddy and NGINX for our production setups in various projects, usually when we need to proxy to additional backend services.

To make sure that the correct request URL is passed to mbtileserver so that TileJSON and map preview endpoints work correctly, make sure to have your reverse proxy send the following headers:

Scheme (HTTP vs HTTPS): one of X-Forwarded-Proto, X-Forwarded-Protocol, X-Url-Scheme to set the scheme of the request. OR X-Forwarded-Ssl to automatically set the scheme to HTTPS.

Host: Set X-Forwarded-Host to the correct host for the request.

Caddy v2 Example:

For mbtileserver running on port 8000 locally, add the following to the block for your domain name:

<domain_name> {
  route /services* {
    reverse_proxy localhost:8000
  }
}

You may want to consider adding cache control headers within the route block depending on how often the contents of your tilesets change. For instance, to prevent clients from caching tiles longer than 1 hour:

  route /services* {
    header Cache-Control "public, max-age=3600, must-revalidate"
    localhost mbtileserver:8000
  }

NGINX Example:

For mbtileserver running on port 8000 locally, add the following to your server block:

server {
   <other config options>

    location /services {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_pass http://localhost:8000;
    }
}

Docker

Pull the latest image from Github Container Registry:

docker pull ghcr.io/consbio/mbtileserver:latest

To build the Docker image locally (named mbtileserver):

docker build -t mbtileserver -f Dockerfile .

To run the Docker container on port 8080 with your tilesets in <host tile dir>. Note that by default, mbtileserver runs on port 8000 in the container.

docker run --rm -p 8080:8000 -v <host tile dir>:/tilesets  consbio/mbtileserver

You can pass in additional command-line arguments to mbtileserver, for example, to use certificates and files in <host cert dir> so that you can access the server via HTTPS. The example below uses self-signed certificates generated using mkcert. This example uses automatic redirects, which causes mbtileserver to also listen on port 80 and automatically redirect to 443.

docker run  --rm -p 80:80 443:443 -v <host tile dir>:/tilesets -v <host cert dir>:/certs/ consbio/mbtileserver -c /certs/localhost.pem -k /certs/localhost-key.pem -p 443 --redirect

Alternately, use docker-compose to run:

docker-compose up -d

The default docker-compose.yml configures mbtileserver to connect to port 8080 on the host, and uses the ./mbtiles/testdata folder for tilesets. You can use your own docker-compose.override.yml or environment specific files to set these how you like.

To reload the server:

docker exec -it mbtileserver sh -c "kill -HUP 1"

Specifications

Creating Tiles

You can create mbtiles files using a variety of tools. We have created tiles for use with mbtileserver using:

The root name of each mbtiles file becomes the "tileset_id" as used below.

XYZ Tile API

The primary use of mbtileserver is as a host for XYZ tiles.

These are provided at: /services/<tileset_id>/tiles/{z}/{x}/{y}.<format>

where <format> is one of png, jpg, webp, pbf depending on the type of data in the tileset.

Missing tiles

Missing vector tiles are always returned as HTTP 204.

Missing image tiles are returned as blank PNGs with the same dimensions as the tileset to give seamless display of these tiles in interactive maps.

When serving image tiles that encode data (e.g., terrain) instead of purely for display, this can cause issues. In this case, you can use the --missing-image-tile-404 option. This behavior will be applied to all image tilesets.

TileJSON API

mbtileserver automatically creates a TileJSON endpoint for each service at /services/<tileset_id>. The TileJSON uses the same scheme and domain name as is used for the incoming request; the --domain setting does not affect auto-generated URLs.

This API provides most elements of the metadata table in the mbtiles file as well as others that are automatically inferred from tile data.

For example, http://localhost/services/states_outline

returns something like this:

{
  "bounds": [
    -179.23108,
    -14.601813,
    179.85968,
    71.441055
  ],
  "center": [
    0.314297,
    28.419622,
    1
  ],
  "credits": "US Census Bureau",
  "description": "States",
  "format": "png",
  "id": "states_outline",
  "legend": "[{\"elements\": [{\"label\": \"\", \"imageData\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAGFJREFUOI3tlDEOgEAIBClI5kF+w0fxwXvQdjZywcZEtDI31YaQgWrdPsYzAPFGJCmmEAhJGzCash0wSVE/HHnlKcDMfrPXYgmXcAl/JswK6lCrz89BdGVm1+qrH0bbWDgA3WwmgzD8ueEAAAAASUVORK5CYII=\"}], \"name\": \"tl_2015_us_state\"}]",
  "map": "http://localhost/services/states_outline/map",
  "maxzoom": 4,
  "minzoom": 0,
  "name": "states_outline",
  "scheme": "xyz",
  "tags": "states",
  "tilejson": "2.1.0",
  "tiles": [
    "http://localhost/services/states_outline/tiles/{z}/{x}/{y}.png"
  ],
  "type": "overlay",
  "version": "1.0.0"
}

Map preview

mbtileserver automatically creates a map preview page for each tileset at /services/<tileset_id>/map.

It uses MapLibre GL to render vector and image tiles.

No built-in basemap is included by default in the map preview. You can use one of the following options to include a basemap.

Basemap style URL

To include a MapLibre GL style URL use the --basemap-style-url option to provide a URL to that style:

--basemap-style-url "https://tiles.stadiamaps.com/styles/stamen_toner_lite.json?api_key=<your key>"

The URL can include query parameters as required by the host, such as ?access_token=<something>.

Basemap tiles URL

To include a basemap based on image tile URLs, use the --basemap-tiles-url option to provide a raster tile URL pattern:

--basemap https://some.host/{z}/{x}/{y}.png

The template parameters {z} (zoom), {x}, {y} are required.

The extension can be omitted or be any image format supported by MapLibre GL.

The URL can include query parameters as required by the host, such as ?access_token=<something>.

IMPORTANT: this does not support vector tiles.

ArcGIS API

This project currently provides a minimal ArcGIS tiled map service API for tiles stored in an mbtiles file.

This is enabled with the --enable-arcgis flag.

This should be sufficient for use with online platforms such as Data Basin. Because the ArcGIS API relies on a number of properties that are not commonly available within an mbtiles file, so certain aspects are stubbed out with minimal information.

This API is not intended for use with more full-featured ArcGIS applications such as ArcGIS Desktop.

Available endpoints:

  • Service info: http://localhost:8000/arcgis/rest/services/<tileset_id>/MapServer
  • Layer info: http://localhost:8000/arcgis/rest/services/<tileset_id>/MapServer/layers
  • Tiles: http://localhost:8000/arcgis/rest/services/<tileset_id>/MapServer/tile/0/0/0

Request authorization

Providing a secret key with -s/--secret-key or by setting the HMAC_SECRET_KEY environment variable will restrict access to all server endpoints and tile requests. Requests will only be served if they provide a cryptographic signature created using the same secret key. This allows, for example, an application server to provide authorized clients a short-lived token with which the clients can access tiles for a specific service.

Signatures expire 15 minutes from their creation date to prevent exposed or leaked signatures from being useful past a small time window.

Creating signatures

A signature is a URL-safe, base64 encoded HMAC hash using the SHA1 algorithm. The hash key is an SHA1 key created from a randomly generated salt, and the secret key string. The hash payload is a combination of the ISO-formatted date when the hash was created, and the authorized service id.

The following is an example signature, created in Go for the service id test, the date 2019-03-08T19:31:12.213831+00:00, the salt 0EvkK316T-sBLA, and the secret key YMIVXikJWAiiR3q-JMz1v2Mfmx3gTXJVNqme5kyaqrY

Create the SHA1 key:

serviceId := "test"
date := "2019-03-08T19:31:12.213831+00:00"
salt := "0EvkK316T-sBLA"
secretKey := "YMIVXikJWAiiR3q-JMz1v2Mfmx3gTXJVNqme5kyaqrY"

key := sha1.New()
key.Write([]byte(salt + secretKey))

Create the signature hash:

hash := hmac.New(sha1.New, key.Sum(nil))
message := fmt.Sprintf("%s:%s", date, serviceId)
hash.Write([]byte(message))

Finally, base64-encode the hash:

b64hash := base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
fmt.Println(b64hash) // Should output: 2y8vHb9xK6RSxN8EXMeAEUiYtZk

Making request

Authenticated requests must include the ISO-formatted date, and a salt-signature combination in the form of: <salt>:<signature>. These can be provided as query parameters:

?date=2019-03-08T19:31:12.213831%2B00:00&signature=0EvkK316T-sBLA:YMIVXikJWAiiR3q-JMz1v2Mfmx3gTXJVNqme5kyaqrY

Or they can be provided as request headers:

X-Signature-Date: 2019-03-08T19:31:12.213831+00:00
X-Signature: 0EvkK316T-sBLA:YMIVXikJWAiiR3q-JMz1v2Mfmx3gTXJVNqme5kyaqrY

Development

Dependencies are managed using go modules. Vendored dependencies are stored in vendor folder by using go mod vendor.

On Windows, it is necessary to install gcc in order to compile mattn/go-sqlite3. MinGW or TDM-GCC should work fine.

If you experience very slow builds each time, it may be that you need to first run

go build -a .

to make subsequent builds much faster.

Development of the templates and static assets likely requires using node and npm. Install these tools in the normal way.

From the handlers/templates/static folder, run

npm install

to pull in the static dependencies. These are referenced in the package.json file.

Then to build the minified version, run:

npm run build

Built static assets are saved to handlers/templates/static/dist and included via go:embed into the final executable.

Modifying the .go files or anything under handlers/templates always requires re-running go build ..

Changes

See CHANGELOG.

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Brendan Ward

๐Ÿ’ป ๐Ÿ“– ๐Ÿ› ๐Ÿ“ ๐Ÿ‘€ ๐Ÿค”

Fabian Wickborn

๐Ÿ’ป ๐Ÿ“– ๐Ÿ› ๐Ÿค”

Nik Molnar

๐Ÿ’ป ๐Ÿค” ๐Ÿ›

Nikolay Korotkiy

๐Ÿ’ป ๐Ÿ›

Robert Brown

๐Ÿ’ป

Mihail

๐Ÿ’ป

Marko Burjek

๐Ÿ’ป

Kristjan

๐Ÿ’ป

evbarnett

๐Ÿ›

walkaholic.me

๐Ÿ›

Brian Voelker

๐Ÿ›

Georg Leciejewski

๐Ÿ›

Christophe Benz

๐Ÿ›

Malcolm Meyer

๐Ÿ›

Josh Lee

๐Ÿ’ป

Martin Karlsen Jensen

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

mbtileserver's People

Contributors

brendan-ward avatar buma avatar cbenz avatar chrismytton avatar davidcalhoun avatar djbeadle avatar eltociear avatar fawick avatar jleedev avatar krizz avatar martin8412 avatar mika-go-13 avatar nikmolnar avatar retbrown avatar sikmir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mbtileserver's Issues

Add support for subfolders containing mbtiles tiles

There is a limit on the number of unique filenames that can be stored and easily used in a given folder.

For a folder structure like:

<tileroot>/a.mbtiles
<tileroot>/b/c.mbtiles

would be published as:

<domain>/a
<domain>/b/c

However, a folder name that is the same as a sibling mbtiles file name would not be allowed, e.g.,

<tileroot>/a.mbtiles
<tileroot>/a/b.mbtiles

Server crashes on startup if image type cannot be detected in an mbtiles file

Unable to create service set: could not open mbtiles file "/tmp/test.mbtiles": Could not detect tile format
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x43f7601]

goroutine 1 [running]:
github.com/consbio/mbtileserver/handlers.(*ServiceSet).Handler(0x0, 0x468d6d8, 0x1, 0xc4204121e0, 0xc4200be068)
	/Users/bcward/go/src/github.com/consbio/mbtileserver/handlers/handlers.go:405 +0x61
main.serve()
	/Users/bcward/go/src/github.com/consbio/mbtileserver/main.go:161 +0x55a
main.glob..func1(0x49203c0, 0xc420395400, 0x0, 0x4)
	/Users/bcward/go/src/github.com/consbio/mbtileserver/main.go:34 +0x20
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).execute(0x49203c0, 0xc4200c0100, 0x4, 0x4, 0x49203c0, 0xc4200c0100)
	/Users/bcward/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:651 +0x23d
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x49203c0, 0x400646c, 0xc42009c058, 0x0)
	/Users/bcward/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:726 +0x2d4
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).Execute(0x49203c0, 0x0, 0xbed3325b39422aa3)
	/Users/bcward/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:685 +0x2b
main.main()
	/Users/bcward/go/src/github.com/consbio/mbtileserver/main.go:66 +0x2d

Test file:
test.mbtiles.zip

We should not publish an invalid service, but we also shouldn't completely crash when this occurs.

Integrate tilemerge for creating static maps

https://github.com/brendan-ward/tilemerge

Use case is to make static maps from Leaflet or other interactive maps.

Possible REST API:
/services/<service_name>/merge/z/<x0>:<x1>/<y0>:<y1>.<ext>?xOff=<xOff>&yOff=<yOff>&mapWidth=<mapWidth>&mapHeight=<mapHeight>

where x0:x1, y0:y1 is a tile range, e.g., tiles x0,y0 to x1,y1.

xOff and yOff are offsets either within the image, or outside the image. mapWidth and mapHeight refer to the dimensions from the offset point.

How to handle wrapping the antimeridian is TBD.

Add ArcGIS API for identify

Using vector tiles or UTF8-grids in mbtiles file alongside image tiles.

Given a geographic location and info about map extent / width:

  1. determine zoom level
  2. find appropriate tile
  3. geometric operation (e.g., point in polygon) or lookup into UTF8-grid to find feature(s) at location
  4. format attribute data and return

Add CORS support

To use tiles in a page served on another server or port, we need CORS enabled.

404 not found

I want to first of all say that I am extremely happy that someone has put this together and want to say what a great job you have done with this.

Upon using this there is one thing that has come up which is if there is not a tile for something(which is completely normal) but console logs an error of 404 not found. Upon trying to see if i could get mapbox gl to suppress it I came to find out that its not so much a mapbox issue as it is the server returning 404. They recommended having the server send back 204, which is a successful request with no content.

Let me know your thoughts.

Thanks

Handle proxy

mbtileserver doesn't work correctly behind a proxy, e.g., Caddy.

It order to do this properly, we may need to allow setting the proxy hostname, port, and scheme.

Drop Leaflet, move everything to Mapbox GL

This is nothing against Leaflet, which remains as awesome as ever.

However, for easier maintenance and enhancements, it would be best to limit our map preview technology to a single type.

Corrupted mbtiles file causes segmentation violation and crashes the server

Here's the traceback of a sample error:

time="2018-03-28T20:33:10Z" level=error msg="Unable to create service set: could not open mbtiles file \"/root/tiles/ace_aqua_rept_ntv.mbtiles\": database disk image is malformed" 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fc8a1]

goroutine 1 [running]:
github.com/consbio/mbtileserver/handlers.(*ServiceSet).Handler(0x0, 0xa29650, 0x1, 0xc4203e8ca0, 0xc42000e1b8)
	/go/src/github.com/consbio/mbtileserver/handlers/handlers.go:409 +0x61
main.serve()
	/go/src/github.com/consbio/mbtileserver/main.go:161 +0x59f
main.glob..func1(0xea67e0, 0xc4203d7cb0, 0x0, 0x1)
	/go/src/github.com/consbio/mbtileserver/main.go:34 +0x20
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).execute(0xea67e0, 0xc42000c070, 0x1, 0x1, 0xea67e0, 0xc42000c070)
	/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:651 +0x23d
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xea67e0, 0x40c62c, 0xc420024118, 0x0)
	/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:726 +0x2d4
github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra.(*Command).Execute(0xea67e0, 0x0, 0xbea71cdb785791df)
	/go/src/github.com/consbio/mbtileserver/vendor/github.com/spf13/cobra/command.go:685 +0x2b
main.main()
	/go/src/github.com/consbio/mbtileserver/main.go:66 +0x2d

Map preview error

Steps to reproduce

$ # mb-util โž  https://github.com/mapbox/mbutil
$ mb-util ~/png-tiles ./mbtiles/testdata/test.mbtiles
$ docker-compose up -d
$ curl http://127.0.0.1:8080/services/test | jq
{
  "format": "png",
  "id": "test",
  "map": "http://127.0.0.1:8080/services/test/map",
  "maxzoom": 18,
  "minzoom": 0,
  "scheme": "xyz",
  "tilejson": "2.1.0",
  "tiles": [
    "http://127.0.0.1:8080/services/test/tiles/{z}/{x}/{y}.png"
  ]
}
$ curl http://127.0.0.1:8080/services/test/map
Internal Server Error
$ docker-compose logs mbtileserver
...
mbtileserver     | time="2019-11-14T22:57:50Z" level=error msg="could not parse template asset \"map\": html/template: cannot Parse after Execute"
mbtileserver     | time="2019-11-14T22:57:52Z" level=error msg="template: \"map\" is an incomplete or empty template"
mbtileserver     | time="2019-11-14T22:57:53Z" level=error msg="template: \"map\" is an incomplete or empty template"

Add feature identify / highlight on click

I often use the preview maps for inspecting data before consuming in projects.

It would be very helpful if I could click on a feature, and show info for that feature in a sidebar, popup, etc. This way I could inspect certain features, and verify that they have the right attributes present, and right attribute values.

Enable serving of static map-related assets

Related to #64

In order to better support self-hosted tilesets and styles, we need to support serving other static assets likely to be referenced from those styles, including:

  • fonts
  • sprites

Allow loading new tilesets without restarting server

Would be nice to add tilesets (and possibly remove / replace them) without restarting the server process.

Some options:

  1. Add a filesystem watcher and update the map of services on change
  2. Add an API endpoint (and associated auth, perhaps an API key) that we call on the running process to request update

Some challenges:

  • we are not using a concurrency safe map. (concurrent-map might work)

fun with logrus dependency lowercased name change

the logrus repo was renamed from github.com/Sirupsen/logrus to lowercased github.com/sirupsen/logrus so go build does not work for me anymore because logrus_sentry has changed it already .. what a hickup i can tell you.

After renaming the imports to lowercase in main.go and mbtileserver it compiles.

Is there any chance that you can tackle this issue?

Add support for legend

Should be able to provide rendering info via JSON or using HTML stored in the mbtiles file (like this ).

While the spec includes HTML to make it really easy to drop in place in HTML, it conflates data (the mapping of values to colors) with presentation / layout in a way that seems less than portable.

Docker image link seems to be broken / unpublished

Hi and thanks for this great project :)

There are 2 things that didn't work for me while following the README:

  1. The local installation output was blank (go get github.com/consbio/mbtileserver) and while trying to run mbtileserver I receive a command not found message
  2. The docker image seems to not be working at all. While trying to pull the docker image I receive this:

docker pull consbio/mbtileserver:latest
Error response from daemon: pull access denied for consbio/mbtileserver, repository does not exist or may require 'docker login'

Any help would be very appreciated.

Very slow startup when using large tilesets

Starting mbtileserver on a tileset that is >50 GB takes a couple minutes. Since we are using running a few basic queries to determine contents of the tileset, it should not take this long.

Use enums for determining types instead of strings

Right now we do lots of comparisons on string representation of format. We could do better using an enum and a higher level property.

We need to do this more than ideal because vector tiles require different handling if a few places than image tiles.

Key option is getting wrong text from CLI help

Usage:
  mbtileserver [flags]

Flags:
      --cachesize int   Size of cache in MB. (default 250)
  -c, --cert string     X.509 TLS certificate filename.  If present, will be used to enable SSL on the server.
  -d, --dir string      Directory containing mbtiles files. (default "./tilesets")
  -k, --key string      flag usage
  -p, --port int        Server port. (default 8000)

key option should not be 'flag usage'

Serve Mapbox-GL style files

is it possible to serve other files; i.e. like a standard http server?
In particular I am trying to use mapbox-gl.js which uses a .json file to store the style and also the mbtiles source location.
How can I serve the .json file from http://localhost?
Thanks.

And preview Leaflet map

Similar to what we did in clover, add a dynamically created Leaflet map using this tile service. Should be as simple as creating a template, injecting variables, and serving that on a known URL.

mbtileserver does not start on Windows

Following the instructions:

You can install this project with

go get github.com/consbio/mbtileserver

This will create and install an executable called mbtileserver.

However, the command does not install anything. Running it with -v only gives:

C:\>go get -v github.com/consbio/mbtileserver
github.com/consbio/mbtileserver (download)

Thank you for your help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.