Documentation ¶
Overview ¶
map180 draws SVG maps on EPSG3857. It handles maps that cross the 180 meridian and allows high zoom level data in a specified region. Land and lake layer queries are cached for speed.
Index ¶
- Constants
- func BboxToWKTPolygon(boundingBox string) (p string, err error)
- func SVGTriangle(m Marker, b *bytes.Buffer)
- func ValidBbox(boundingBox string) error
- type Map180
- func (w *Map180) Map(boundingBox string, width int, pts Points, insetBbox string, buf *bytes.Buffer) (err error)
- func (w *Map180) MapRaw(boundingBox string, width int) (mr Raw, err error)
- func (w *Map180) SVG(boundingBox string, width int, markers []Marker, insetBbox string) (buf bytes.Buffer, err error)
- type Marker
- type Point
- type Points
- type Raw
- type Region
- type SVGMarker
Constants ¶
const (
Width3857 = 40075016.6855785
)
Variables ¶
This section is empty.
Functions ¶
func BboxToWKTPolygon ¶
func ValidBbox ¶
ValidBbox returns a nil error for a valid boundingBox. Valid options are one of:
- an empty string: ""
- a string definition of a bounding box using ',' separated longitude latitude (float) on EPSG4327. This should be lower left and upper right corners. It may cross 180. Longitude can be -180 to 180 or 0 to 360. Latitude must be <= 85.0 && >= -85.0 Examples: "165,-48,179,-34" // New Zealand "165,-48,-175,-34" // New Zealand and Chathams "165,-48,185,-34" // New Zealand and Chathams
Types ¶
type Map180 ¶
type Map180 struct { }
func Init ¶
Init returns an initialised Map180. d must have access to the map180 tables in the public schema. cacheBytes is the size of the memory cache for land and lake layers. region must be a valid Region.
Example:
wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000)
func (*Map180) Map ¶
func (w *Map180) Map(boundingBox string, width int, pts Points, insetBbox string, buf *bytes.Buffer) (err error)
Map draws an SVG image to buf for the bbox regions. The returned map uses EPSG3857. Width is the SVG image width in pixels (height is calculated). pts haz X Y and values initialised for later drawing. The SVG in buf is not closed. See ValidBbox for boundingBox options.
func (*Map180) MapRaw ¶
MapRaw returns a Raw struct which can be used for drawing SVG maps e.g.,
raw, err := wm.MapRaw(bbox, width) b := bytes.Buffer b.WriteString(`<?xml version="1.0"?>`) b.WriteString(fmt.Sprintf("<svg viewBox=\"0 0 %d %d\" xmlns=\"http://www.w3.org/2000/svg\">", raw.Width, raw.Height)) b.WriteString(fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" style=\"fill: azure\"/>", raw.Width, raw.Height)) b.WriteString(fmt.Sprintf("<path style=\"fill: wheat; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Land)) b.WriteString(fmt.Sprintf("<path style=\"fill: azure; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Lakes)) b.WriteString("</svg>")
The other properties can be used to scale and translate for drawing on the map e.g.,
type point struct { latitude, longitude float64 x, y float64 } // create pts []point with x,y, set to EPSG3857 and latitude longitude EPSG4326 // range of pts ... switch raw.CrossesCentral && p.longitude > -180.0 && p.longitude < 0.0 { case true: p.x = (p.x + map180.Width3857 - raw.LLX) * raw.DX p.y = (p.y - math.Abs(raw.YShift)) * raw.DX case false: p.x = (p.x - math.Abs(raw.XShift)) * raw.DX p.y = (p.y - math.Abs(raw.YShift)) * raw.DX } // draw p on SVG.
func (*Map180) SVG ¶
func (w *Map180) SVG(boundingBox string, width int, markers []Marker, insetBbox string) (buf bytes.Buffer, err error)
SVG draws an SVG image showing a map of markers. The returned map uses EPSG3857. Width is the SVG image width in pixels (height is calculated). If boundingBox is the empty string then the map bounds are calculated from the markers. See ValidBbox for boundingBox options.
type Marker ¶
type Marker struct {
// contains filtered or unexported fields
}
func NewMarker ¶
NewMarker returns a Marker to be drawn at longitude, latitude (EPSG:4327). Latitude must be in the range -85 to 85 otherwise the Marker will not be drawn. Defaults to a red triangle size 10.
func (*Marker) SetSVGMarker ¶
SetSVGMarker sets the SVGMarker func that will be used to draw the marker.
func (*Marker) SetSvgColour ¶
type Point ¶
type Point struct {
Longitude, Latitude float64
Value float64 // Points can be sorted by Value.
Stroke, Fill, Opacity string // Optional for any later drawing funcs
Size int // Optional for any later drawing funcs
// contains filtered or unexported fields
}
type Raw ¶
type Raw struct {
Land, Lakes string // land or lake polygons as strings for use in the d property of an SVG path.
Height, Width int // the height and width for the map.
DX float64 // for scaling.
XShift, YShift float64 // for translation.
LLX float64 // for translation.
CrossesCentral bool // true if the map crosses the 180 meridian.
}