https://github.com/dchest/onmap
Go package onmap puts pins on a world map image.
https://github.com/dchest/onmap
Last synced: 7 months ago
JSON representation
Go package onmap puts pins on a world map image.
- Host: GitHub
- URL: https://github.com/dchest/onmap
- Owner: dchest
- License: mit
- Created: 2022-02-03T10:54:12.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-02T17:08:56.000Z (over 4 years ago)
- Last Synced: 2025-01-24T09:42:47.133Z (over 1 year ago)
- Language: Go
- Size: 806 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
onmap
=====
Go package onmap puts pins on a world map image.
The images (mercator.jpg, pin.png and pin-shadow.png) are embedded in the package,
no need to ship them separately.
Image licensing
---------------
The default world map used is:
```
https://en.wikipedia.org/wiki/File:Mercator_projection_SW.jpg
License: Strebe, CC BY-SA 3.0 , via Wikimedia Commons
```
Pin images are created by the author of the package, licensed under this package license (MIT).
Example
-------
```go
package main
import (
"os"
"log"
"image/png"
"github.com/dchest/onmap"
)
func main() {
coords := []onmap.Coord{
{42.1, 19.1}, // Bar
{55.755833, 37.617222}, // Moscow
{41.9097306, 12.2558141}, // Rome
{-31.952222, 115.858889}, // Perth
{42.441286, 19.262892}, // Podgorica
{38.615925, -27.226598}, // Azores
{45.4628329, 9.1076924}, // Milano
{43.7800607, 11.170928}, // Florence
{37.7775, -122.416389}, // San Francisco
}
m := onmap.Pins(coords, onmap.StandardCrop)
f, err := os.Create("out.png")
if err != nil {
log.Fatal(err)
}
defer f.Close()
if err := png.Encode(f, m); err != nil {
log.Fatal(err)
}
}
```
Result (shown as webp, not png):

Just one coordinate for San Francisco and using StandardCrop:

Other projections
-----------------
You can use a different projection by defining the following interface for it:
```go
// Projection is an interface for converting coordinates.
type Projection interface {
// Convert converts coordinates into a point on a map.
Convert(coord Coord, mapWidth, mapHeight int) image.Point
}
```
and using `MapPinsProjection` with your own world map in that projection.