Skip to content

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

@ole108

Description

@ole108

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions