Coder Social home page Coder Social logo

flopp / go-staticmaps Goto Github PK

View Code? Open in Web Editor NEW
337.0 10.0 72.0 1.44 MB

A go (golang) library and command line tool to render static map images using OpenStreetMap tiles.

License: MIT License

Go 98.77% Makefile 1.23%
map maps geo gis openstreetmap tiles tilemap go-staticmaps

go-staticmaps's Introduction

PkgGoDev Go Report Card golang/static License MIT

go-staticmaps

A go (golang) library and command line tool to render static map images using OpenStreetMap tiles.

What?

go-staticmaps is a golang library that allows you to create nice static map images from OpenStreetMap tiles, along with markers of different size and color, as well as paths and colored areas.

For a Python version with a similar interface, take a look at py-staticmaps.

go-staticmaps comes with a command line tool called create-static-map for use in shell scripts, etc.

Static map of the Berlin Marathon

How?

Installation

Installing go-staticmaps is as easy as

go get -u github.com/flopp/go-staticmaps

For the command line tool, use

go get -u github.com/flopp/go-staticmaps/create-static-map

Of course, your local Go installation must be setup up properly.

Library Usage

Create a 400x300 pixel map with a red marker:

package main

import (
  "image/color"

  sm "github.com/flopp/go-staticmaps"
  "github.com/fogleman/gg"
  "github.com/golang/geo/s2"
)

func main() {
  ctx := sm.NewContext()
  ctx.SetSize(400, 300)
  ctx.AddObject(
    sm.NewMarker(
      s2.LatLngFromDegrees(52.514536, 13.350151),
      color.RGBA{0xff, 0, 0, 0xff},
      16.0,
    ),
  )

  img, err := ctx.Render()
  if err != nil {
    panic(err)
  }

  if err := gg.SavePNG("my-map.png", img); err != nil {
    panic(err)
  }
}

See PkgGoDev for a complete documentation and the source code of the command line tool for an example how to use the package.

Command Line Usage

Usage:
  create-static-map [OPTIONS]

Creates a static map

Application Options:
      --width=PIXELS              Width of the generated static map image (default: 512)
      --height=PIXELS             Height of the generated static map image (default: 512)
  -o, --output=FILENAME           Output file name (default: map.png)
  -t, --type=MAPTYPE              Select the map type; list possible map types with '--type list'
  -c, --center=LATLNG             Center coordinates (lat,lng) of the static map
  -z, --zoom=ZOOMLEVEL            Zoom factor
  -b, --bbox=nwLATLNG|seLATLNG    Bounding box of the static map
      --background=COLOR          Background color (default: transparent)
  -u, --useragent=USERAGENT       Overwrite the default HTTP user agent string
  -m, --marker=MARKER             Add a marker to the static map
  -i, --imagemarker=MARKER        Add an image marker to the static map
  -p, --path=PATH                 Add a path to the static map
  -a, --area=AREA                 Add an area to the static map
  -C, --circle=CIRCLE             Add a circle to the static map

Help Options:
  -h, --help                      Show this help message

General

The command line interface tries to resemble Google's Static Maps API. If neither --bbox, --center, nor --zoom are given, the map extent is determined from the specified markers, paths and areas.

--background lets you specify a color used for map areas that are not covered by map tiles (areas north of 85°/south of -85°).

Markers

The --marker option defines one or more map markers of the same style. Use multiple --marker options to add markers of different styles.

--marker MARKER_STYLES|LATLNG|LATLNG|...

LATLNG is a comma separated pair of latitude and longitude, e.g. 52.5153,13.3564.

MARKER_STYLES consists of a set of style descriptors separated by the pipe character |:

  • color:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: red)
  • size:SIZE - where SIZE is one of mid, small, tiny, or some number > 0 (default: mid)
  • label:LABEL - where LABEL is an alpha numeric character, i.e. A-Z, a-z, 0-9; (default: no label)
  • labelcolor:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: black or white, depending on the marker color)

Using the --imagemarker option, you can use custom images as markers:

--imagemarker image:IMAGEFILE|offsetx:OFFSETX|offsety:OFFSETY|LATLNG|LATLNG|...

IMAGEFILE is the file name of a PNG or JPEG file,

OFFSETX and OFFSETY are the pixel offsets of the reference point from the top-left corner of the image.

Paths

The --path option defines a path on the map. Use multiple --path options to add multiple paths to the map.

--path PATH_STYLES|LATLNG|LATLNG|...

or

--path PATH_STYLES|gpx:my_gpx_file.gpx

PATH_STYLES consists of a set of style descriptors separated by the pipe character |:

  • color:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: red)
  • weight:WEIGHT - where WEIGHT is the line width in pixels (defaut: 5)

Areas

The --area option defines a closed area on the map. Use multiple --area options to add multiple areas to the map.

--area AREA_STYLES|LATLNG|LATLNG|...

AREA_STYLES consists of a set of style descriptors separated by the pipe character |:

  • color:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: red)
  • weight:WEIGHT - where WEIGHT is the line width in pixels (defaut: 5)
  • fill:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: none)

Circles

The --circles option defines one or more circles of the same style. Use multiple --circle options to add circles of different styles.

--circle CIRCLE_STYLES|LATLNG|LATLNG|...

LATLNG is a comma separated pair of latitude and longitude, e.g. 52.5153,13.3564.

CIRCLE_STYLES consists of a set of style descriptors separated by the pipe character |:

  • color:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: red)
  • fill:COLOR - where COLOR is either of the form 0xRRGGBB, 0xRRGGBBAA, or one of black, blue, brown, green, orange, purple, red, yellow, white (default: no fill color)
  • radius:RADIUS - where RADIUS is te circle radius in meters (default: 100.0)
  • weight:WEIGHT - where WEIGHT is the line width in pixels (defaut: 5)

Examples

Basic Maps

Centered at "N 52.514536 E 13.350151" with zoom level 10:

$ create-static-map --width 600 --height 400 -o map1.png -c "52.514536,13.350151" -z 10

Example 1

A map with a marker at "N 52.514536 E 13.350151" with zoom level 14 (no need to specify the map's center - it is automatically computed from the marker(s)):

$ create-static-map --width 600 --height 400 -o map2.png -z 14 -m "52.514536,13.350151"

Example 2

A map with two markers (red and green). If there are more than two markers in the map, a good zoom level can be determined automatically:

$ create-static-map --width 600 --height 400 -o map3.png -m "color:red|52.514536,13.350151" -m "color:green|52.516285,13.377746"

Example 3

Create a map of the Berlin Marathon

create-static-map --width 800 --height 600 \
  --marker "color:green|52.5153,13.3564" \
  --marker "color:red|52.5160,13.3711" \
  --output "berlin-marathon.png" \
  --path "color:blue|weight:2|gpx:berlin-marathon.gpx"

Static map of the Berlin Marathon

Create a map of the US capitals

create-static-map --width 800 --height 400 \
  --output "us-capitals.png" \
  --marker "color:blue|size:tiny|32.3754,-86.2996|58.3637,-134.5721|33.4483,-112.0738|34.7244,-92.2789|\
    38.5737,-121.4871|39.7551,-104.9881|41.7665,-72.6732|39.1615,-75.5136|30.4382,-84.2806|33.7545,-84.3897|\
    21.2920,-157.8219|43.6021,-116.2125|39.8018,-89.6533|39.7670,-86.1563|41.5888,-93.6203|39.0474,-95.6815|\
    38.1894,-84.8715|30.4493,-91.1882|44.3294,-69.7323|38.9693,-76.5197|42.3589,-71.0568|42.7336,-84.5466|\
    44.9446,-93.1027|32.3122,-90.1780|38.5698,-92.1941|46.5911,-112.0205|40.8136,-96.7026|39.1501,-119.7519|\
    43.2314,-71.5597|40.2202,-74.7642|35.6816,-105.9381|42.6517,-73.7551|35.7797,-78.6434|46.8084,-100.7694|\
    39.9622,-83.0007|35.4931,-97.4591|44.9370,-123.0272|40.2740,-76.8849|41.8270,-71.4087|34.0007,-81.0353|\
    44.3776,-100.3177|36.1589,-86.7821|30.2687,-97.7452|40.7716,-111.8882|44.2627,-72.5716|37.5408,-77.4339|\
    47.0449,-122.9016|38.3533,-81.6354|43.0632,-89.4007|41.1389,-104.8165"

Static map of the US capitals

Create a map of Australia

...where the Northern Territory is highlighted and the capital Canberra is marked.

create-static-map --width 800 --height 600 \
  --center="-26.284973,134.303764" \
  --output "australia.png" \
  --marker "color:blue|-35.305200,149.121574" \
  --area "color:0x00FF00|fill:0x00FF007F|weight:2|-25.994024,129.013847|-25.994024,137.989677|-16.537670,138.011649|\
    -14.834820,135.385917|-12.293236,137.033866|-11.174554,130.398124|-12.925791,130.167411|-14.866678,129.002860"

Static map of Australia

Acknowledgements

Besides the go standard library, go-staticmaps uses

Contributors

  • Kooper: fixed library usage examples
  • felix: added more tile servers
  • wiless: suggested to add user definable marker label colors
  • noki: suggested to add a user definable bounding box
  • digitocero: reported and fixed type mismatch error
  • bcicen: reported and fixed syntax error in examples
  • pshevtsov: fixed drawing of empty attribution strings
  • Luzifer: added overwritable user agent strings to comply with the OSM tile usage policy
  • Jason Fox: added RenderWithBounds function
  • Alexander A. Kapralov: initial circles implementation
  • tsukumaru: added NewArea and NewPath functions

License

Copyright 2016, 2017 Florian Pigorsch & Contributors. All rights reserved.

Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

go-staticmaps's People

Contributors

andrerenaud avatar anonymous5726221 avatar azzaouit avatar bcicen avatar billglover avatar digitocero avatar esperlu avatar felix avatar flopp avatar jasonpfox avatar leczb avatar luzifer avatar manoj-py avatar pushinginertia avatar renovate[bot] avatar rubiojr avatar shanghuiyang avatar tsukumaru 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

go-staticmaps's Issues

Color of the Marker Label

Thanks for the handy library.

Is there a way to change the color of the label of the Markers added ? The current color property changes the color of the marker though.

Bounding Box Feature

Hi!

I just had a look at your static maps implementation. I really like it but I think it should be possible to set/limit the map using a bounding box in addition to all the other wonderful ways you implemented.

My usecase for this would be to show a whole country on the map and than highlight a city or an area within the country.

Any plans to implement this?

Best regards
Tobias

MapObject margins

Another interesting case since you added an ability to add custom objects to the map: sometimes map object can be not symmetrical.
For example I want to add a custom marker like this:

image

And of course if the marker is placed on the left edge of the map it will be cropped. Also in my case determineCenter method works incorrectly as it doesn't take into account text block.

Right now we have a method ExtraMarginPixels in MapObject interface. As I understand it just adds the same margin to top/bottom and right/left margin to the entire output picture. But would be good to have more smart function.

And again, thank you a lot for this project!

Map is not properly centered latitude-wise

go run create-static-map/create-static-map.go --marker "0,0|color:red" --marker "75,0|color:blue"

This centers the map at at latitude=(0 + 75)/2, which is vertically off:

map

404 for the stamen-terrain TileProvider

FYI :
Just playing around with different tiles sources and just came across a 404 for the stamen-terrain tiles.

Another question: is there a parameter to "dim" a given tile (alpha channel? transprency?)

Cheers

Jean-Luc

How to extend?

I want to have an ability to add custom markers. For example I would like to override draw method. What is the best way to do it?

Add generic 'TileProvider' struct

with

  • name
  • attribution
  • tile size
  • list of shards
  • url pattern (parameters: shard, zoom, x, y)

Add functions to MapCreator and TileFetcher to set TileProvider

Custom marker size, cannot parse size string: 30

Thank you for this great project!

I tried to use custom marker size it says 'cannot parse size', not sure what I'm doing wrong here. Here is my command...

create-static-map --width 800 --height 300 --marker "size:'30'|label:1|labelcolor:white|color:blue|8.89698,77.36292666666667" ......

Nicer markers

something mor "pin like" instead of the boring circles

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-go v5
  • actions/checkout v4
  • actions/setup-go v5
gomod
go.mod
  • go 1.22
  • github.com/flopp/go-coordsparser v0.0.0-20240403152942-4891dc40d0a7@4891dc40d0a7
  • github.com/fogleman/gg v1.3.0
  • github.com/golang/geo v0.0.0-20230421003525-6adc56603217@6adc56603217
  • github.com/jessevdk/go-flags v1.5.0
  • github.com/mazznoer/csscolorparser v0.1.3
  • github.com/tkrajina/gpxgo v1.4.0
  • golang.org/x/image v0.15.0

  • Check this box to trigger a request for Renovate to run again on this repository

Determine center/zoom from specified objects

Determine center/zoom (if not specified) from objects (markers, paths) added to the MapCreator.

i.e.

  • if center is not specified: center = center of the bounding box of all objects
  • if zoom is not specified: find largest zoom level such that bounding box of all objects fits into static map

Map Center

Since #49 and #50 are closed the library became very flexible. But I want to suggest one more improvement if you don't mind:)

Example:

package main

import (
	"github.com/flopp/go-staticmaps"
	"github.com/fogleman/gg"
	"github.com/golang/geo/s2"
)

type Square struct {
	sm.MapObject
	Position s2.LatLng
	size     float64
}

func NewSquare(pos s2.LatLng, size float64) *Square {
	s := new(Square)
	s.Position = pos
	s.size = size
	return s
}

func (s *Square) ExtraMarginPixels() (float64, float64, float64, float64) {
	return s.size, s.size / 2.0, 0.0, s.size / 2.0
}

func (s *Square) Bounds() s2.Rect {
	r := s2.EmptyRect()
	r = r.AddPoint(s.Position)
	return r
}

func (s *Square) Draw(gc *gg.Context, trans *sm.Transformer) {
	if !sm.CanDisplay(s.Position) {
		return
	}

	x, y := trans.LatLngToXY(s.Position)
	gc.ClearPath()
	gc.SetLineWidth(1)

	gc.DrawRectangle(x-s.size, y-s.size/2.0, s.size, s.size)
	gc.SetHexColor("#ff0000")
	gc.Fill()

	gc.SetHexColor("#00ff00")
	gc.DrawCircle(x, y, 5)
	gc.Fill()
}

func main() {
	ctx := sm.NewContext()
	ctx.SetSize(700, 500)
	ctx.AddObject(NewSquare(s2.LatLngFromDegrees(52.51450, 13.35012), 50))

	img, err := ctx.Render()
	if err != nil {
		panic(err)
	}

	if err := gg.SavePNG("out.png", img); err != nil {
		panic(err)
	}
}

Output:
image

Green circle show us exactly geo coordinates specified in the main function (it's here just for showing specified coordinates, let's omit it in margins calculation).
As you see the centre of the image in terms of geo-coordinates is correct:
image

But in terms of drawn content it's not aligned:
image

Would be cool to have an ability to centre the image in terms of drawn content. How about this?

Add attribution text

... to the bottom of the generated static map image. Use a text corresponding to the guidelines of the employed tile service.

Allow configurable tile cache directory location and file mode

It's currently not possible to set the cache directory when instantiating a staticmaps context to point at a user-specified path, because it defaults to a directory under the executing user's home directory via the appdirs library.

There are use cases where we might want to store the tile cache in a static directory defined by the user of the library:

  • A multinode service might save to a cache on an NFS mount.
  • Running this within a docker container would require using a directory mounted into the container if the cache should persist across docker instances.
  • Since tiles are continuously updated on the mapping service, we might want to write a job that periodically removes cached tiles older than a certain age and it might be preferable to configure this directory outside the library.

The directory permissions are also created as 777, which allows any user on the host to write to anywhere within the cache. It would also be helpful to specify the file mask as an argument when instantiating the cache for the user of the library to determine.

Suggest addition of a TileCache interface that provides the path and permissions to TileFetcher. This could be instantiated by default with the current behaviour but would allow

type TileCache interface {
    // Root path to store cached tiles in with no trailing slash.
    Path() string
    // Permission to set when creating missing cache directories.
    Perm() os.FileMode
}

Cannot use newline in attribution

Hi,

Thank you for making this library. Would it be possible that you could add a way to make newlines in the attribution work? I have a problem where my attributions aren't small enough to fit on one line, and would greatly appreciate the ability to add more than one line to the attribution section. When I try to add \n to my attribution, a ? character appears, instead of a newline.

Thanks,
Lance

Network error when downloading tile produces map with missing tile

If the fetch of a tile fails due to a network error, the Context.renderLayer function ignores the error and renders the map with a beige square where the tile would have been placed.

This function currently logs that the tile couldn't be downloaded, but this doesn't work for unattended jobs that generate static maps and the map has to be generated correctly.

Suggest adding a return err as described in this code fragment. The caller can then make the choice to retry if it's due to a transient network error.

func (m *Context) renderLayer(gc *gg.Context, zoom int, trans *transformer, tileSize int, provider *TileProvider) error {
...
	if tileImg, err := t.Fetch(zoom, x, y); err == nil {
		gc.DrawImage(tileImg, xx*tileSize, yy*tileSize)
	} else {
		log.Printf("Error downloading tile file: %s", err)
		return err
	}

go get command fails

go get -u github.com/flopp/go-staticmaps/create-static-map

fails with these errors:

/usr/local/opt/go/bin/src/github.com/flopp/go-staticmaps/create-static-map/create-static-map.go:76: cannot assign *s2.Rect to bbox (type s2.Rect) in multiple assignment
/usr/local/opt/go/bin/src/github.com/flopp/go-staticmaps/create-static-map/create-static-map.go:81: invalid indirect of bbox (type s2.Rect)

Already created a fix, wll send

403 forbiden

I try to run the CLI and receive 403 error, I suppose I need to do something to configure my access to openstreemap.org?

 ~ create-static-map --width 600 --height 400 -o map1.png -c "52.514536,13.350151" -z 10
2017/04/18 18:38:46 Error downloading tile file: GET http://b.tile.openstreetmap.org/10/548/335.png: 403 Forbidden
2017/04/18 18:38:46 Error downloading tile file: GET http://c.tile.openstreetmap.org/10/548/336.png: 403 Forbidden
2017/04/18 18:38:47 Error downloading tile file: GET http://c.tile.openstreetmap.org/10/549/335.png: 403 Forbidden
2017/04/18 18:38:47 Error downloading tile file: GET http://a.tile.openstreetmap.org/10/549/336.png: 403 Forbidden
2017/04/18 18:38:48 Error downloading tile file: GET http://a.tile.openstreetmap.org/10/550/335.png: 403 Forbidden
2017/04/18 18:38:48 Error downloading tile file: GET http://b.tile.openstreetmap.org/10/550/336.png: 403 Forbidden
2017/04/18 18:38:48 Error downloading tile file: GET http://b.tile.openstreetmap.org/10/551/335.png: 403 Forbidden
2017/04/18 18:38:48 Error downloading tile file: GET http://c.tile.openstreetmap.org/10/551/336.png: 403 Forbidden

Negative latitude argument for --center interpreted as flag

Thank you for making this tool -- I use it to generate my desktop background (https://github.com/dwrz/config/blob/trunk/scripts/map-bg).

I'm trying to generate a static map for a negative latitude, but it looks like the minus sign is being interpreted as a flag.

 create-static-map --width 2160 --height 1350 --center '-6.694166,39.2253602' --zoom 12 --type arcgis-worldimagery --output test.png
2023/03/07 16:06:07 expected argument for flag `-c, --center', but got option `-6.694166,39.2253602'

The above command works fine if I use '6.694166,39.2253602' instead of '-6.694166,39.2253602'.

From a quick look, this seems like an issue with the flag library being used.

Rendering at/beyond the edges of the latitude/longitude coordinate system

Hi!

We played around with go-staticmaps today and tried to render maps for all countries of the world.
By doing so we ran into some problems.

It seems that for some bounding boxes the implementation is too naive to produce a map.
Especially we need a way to tell the API which way round the world the map should be
(e.g. a bounding box is always upper left first and then lower right).

In addition we had some issue with the copyright notice in the images, when generating small images. There was simply not enough space to properly display them. It might be a good idea to scale the font size in such a case. It would also be great if it would be possible to disable the copyright notice completely. If there is a central copyright notice on our website than it's a redundant information anyway.

Here is the code we use to reproduce the problems including 3 artificial 'countries' that show the problems as extreme cases:

package main

import (
    "image/color"
    "log"

    sm "github.com/flopp/go-staticmaps"
    "github.com/fogleman/gg"
    "github.com/golang/geo/s2"
)

type country struct {
    id   string
    lat1 float64
    lng1 float64
    lat2 float64
    lng2 float64
}   
    
var countries = []country{
    country{"AQ", -60.5155, -180, -89.9999, 180},         // A lot of grey (and almost the whole world)
    country{"CA", 83.1106, -141, 41.676, -52.6363},       // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"FJ", -12.4801, 177.129, -20.676, -178.424},  // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"GL", 83.6274, -73.042, 59.7774, -11.3123},   // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"KI", 4.71957, 169.556, -11.437, -150.215},   // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"NZ", -34.3897, 166.715, -47.286, -180},      // Only partially rendered
    country{"RU", 81.8574, 19.25, 41.1889, -169.05},      // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"TV", -5.64197, 176.065, -10.8012, 179.863},  // Only partially rendered
    country{"UM", 28.2198, -177.392, -0.389006, 166.655}, // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"Test1", -90.0, 25.0, 90.0, 28.0},            // panic: runtime error: index out of range (at tile_fetcher.go:45)
    country{"Test2", 25.0, -180.0, 28.0, 180.0},          // Half the image is grey and only 1 Marker is shown
    country{"Test3", 25.0, 170.0, 28.0, -170.0},          // panic: runtime error: index out of range (at tile_fetcher.go:45)
}

func main() {
    for _, c := range countries {
        log.Printf("INFO: Rendering country '%s'.\n", c.id)
        ctx := sm.NewContext()
        ctx.SetSize(400, 300)
        ctx.AddMarker(sm.NewMarker(s2.LatLngFromDegrees(c.lat1, c.lng1), color.RGBA{0xff, 0, 0, 0xff}, 16.0))
        ctx.AddMarker(sm.NewMarker(s2.LatLngFromDegrees(c.lat2, c.lng2), color.RGBA{0, 0xff, 0, 0xff}, 16.0))
        bbox := s2.RectFromLatLng(s2.LatLngFromDegrees(c.lat1, c.lng1))
        bbox = bbox.AddPoint(s2.LatLngFromDegrees(c.lat2, c.lng2))
        ctx.SetBoundingBox(bbox)
        ctx.SetTileProvider(sm.GetTileProviders()["cycle"])
        img, err := ctx.Render()
        if err != nil {
            log.Printf("ERROR: Unable to render country '%s': %s\n", c.id, err)
        }
        if err := gg.SavePNG(c.id+".png", img); err != nil {
            log.Printf("ERROR: Unable to save image for country '%s': %s\n", c.id, err)
        }
    }
}

Best regards,

Ole

Link to PkgGoDev in README.md

Hi,

The link to PkgGoDev in README.md points to a blank page. The correct link should be https://pkg.go.dev/github.com/flopp/go-staticmaps

Very neat and handy piece of code. Thanks.

Jean-Luc

Labels in thunderforest-transport look weird

create-static-map -t thunderforest-transport -c "52.52,13.38" -z 13

map

E.g. north east quadrant has some cut off/partial labels, although the map itself (roads, rivers, etc.) look perfect :(

Returned map does not match requested bounding box

The returned map image does not exactly match the requested bounding box, making registration of the image with other geo-located data impossible.

See associated pull request to return an image with as-rendered bounding box to support registration of returned map data

Determined zoom level is too large

Hi, we are using OSM as tile provider and in certain cases the calculated zoom level became larger (ex 24) than OSM's maximum zoom level (20), which drives to a black backgrounded rendered image. How can we handle this situation? Is there any way to define the maximum usable zoom level?

Library usage example correction

Hello,

Please correct the example of library usage:

diff --git a/README.md b/README.md
index 5d994f0..e5a0fad 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,7 @@ import (
 func main() {
   ctx := sm.NewContext()
   ctx.SetSize(400, 300)
-  ctx.AddMarker(sm.NewMarker(s2.LatLng{52.514536, 13.350151}, color.RGBA{0xff, 0, 0, 0xff}, 16.0))
+  ctx.AddMarker(sm.NewMarker(s2.LatLngFromDegrees(52.514536, 13.350151), color.RGBA{0xff, 0, 0, 0xff}, 16.0))

   img, err := ctx.Render()
   if err != nil {

Using NewTileProviderThunderforestOutdoors() results in 'API Key Required' watermark

Using NewTileProviderThunderforestOutdoors() results in 'API Key Required' watermark on the generated image.

How do we set an API key when using this tool?

Here's what I'm trying to do:

	ctx := sm.NewContext()
	ctx.SetSize(600, 360)
	ctx.SetZoom(zoom)
	ctx.SetTileProvider(sm.NewTileProviderThunderforestOutdoors())
	ctx.AddObject(
		sm.NewMarker(
			s2.LatLngFromDegrees(lat, long),
			color.RGBA{0xff, 0, 0, 0xff},
			16.0,
		),
	)

	img, err := ctx.Render()

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.