Skip to content

Commit b1b4112

Browse files
committed
Initial commit.
0 parents  commit b1b4112

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

COPYING

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2015 Matt Amos <[email protected]>
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
8+
1. Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the
14+
distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Go Vector Map Tile Server
2+
3+
A tile server using [vecamole](https://github.com/zerebubuth/vecamole) and [Mapnik](http://mapnik.org) to render vector tiles from a Mapnik data source and configuration.
4+
5+
## Installation
6+
7+
First, install [vecamole](https://github.com/zerebubuth/vecamole). That's the only hard bit. From then, it should be as simple as:
8+
9+
```
10+
go install github.com/zerebubuth/go-vector-map-tile-server
11+
```
12+
13+
## Running it
14+
15+
Currently it just dumps a static `tile.pbf` in the current directory. Working in progress to make it more useful.

main.go

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"flag"
6+
"fmt"
7+
"io"
8+
"os"
9+
"github.com/zerebubuth/govecamole"
10+
)
11+
12+
var outputFile = flag.String("outputFile", "tile.pbf", "The file name to write the output to.")
13+
14+
func main() {
15+
flag.Parse()
16+
17+
err := govecamole.RegisterDefaultDatasources()
18+
if err != nil {
19+
fmt.Printf("Ooops, can't register datasources: %s\n", err.Error())
20+
return
21+
}
22+
23+
m, err := govecamole.New(256, 256)
24+
if err != nil {
25+
fmt.Printf("Ooops, got an error: %s\n", err.Error())
26+
return
27+
}
28+
defer m.Close()
29+
30+
sampleconf := `<!DOCTYPE Map>
31+
<Map srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
32+
<Style name="point">
33+
</Style>
34+
<Layer name="point" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">
35+
<StyleName>point</StyleName>
36+
<Datasource>
37+
<Parameter name="type">csv</Parameter>
38+
<Parameter name="inline">
39+
type,WKT
40+
point,"POINT (0 0)"
41+
</Parameter>
42+
</Datasource>
43+
</Layer>
44+
</Map>`
45+
46+
err = m.LoadString(sampleconf, true, "sampleconf")
47+
if err != nil {
48+
fmt.Printf("Unable to load sample config string into map: %s\n", err.Error())
49+
return
50+
}
51+
52+
req, err := govecamole.NewRequestZXY(256, 256, 0, 0, 0)
53+
if err != nil {
54+
fmt.Printf("Unable to create a request: %s\n", err.Error())
55+
return
56+
}
57+
defer req.Close()
58+
59+
opts, err := govecamole.DefaultOptions()
60+
if err != nil {
61+
fmt.Printf("Unable to create default options: %s\n", err.Error())
62+
return
63+
}
64+
defer opts.Close()
65+
66+
var buf bytes.Buffer
67+
err = govecamole.Render(&buf, m, req, opts)
68+
if err != nil {
69+
fmt.Printf("Unable render tile: %s\n", err.Error())
70+
return
71+
}
72+
73+
fmt.Printf("Got tile size=%v\n", buf.Len())
74+
75+
file, err := os.Create(*outputFile)
76+
if err != nil {
77+
fmt.Printf("Unable to create output file %v: %s\n", *outputFile, err.Error())
78+
return
79+
}
80+
defer file.Close()
81+
82+
_, err = io.Copy(file, &buf)
83+
if err != nil {
84+
fmt.Printf("Unable to copy tile to file: %s\n", err.Error())
85+
return
86+
}
87+
}

0 commit comments

Comments
 (0)