Exemplo n.º 1
0
func enable_leaflet(mbt *mbtiles.Map, libpath string) error {
	leaflettmpl, err := template.New("leaflettmpl").Parse(leaflettext)
	if err != nil {
		return err
	}
	liburl, err := url.Parse(libpath)
	if err != nil {
		return err
	}
	if !liburl.IsAbs() {
		// url is local path, serve contents at /leaflet/
		source := libpath
		libpath = "/leaflet/"
		http.Handle(libpath, http.StripPrefix(libpath,
			http.FileServer(http.Dir(source))))
	}
	http.Handle("/", http.HandlerFunc(
		func(w http.ResponseWriter, req *http.Request) {
			metadata := mbt.Metadata()
			err := leaflettmpl.Execute(w, leafletparams{metadata, libpath})
			if err != nil {
				http.Error(w, "template error: "+err.Error(), 500)
			}
		}))
	return nil
}
Exemplo n.º 2
0
func TileJson(mbt *mbtiles.Map, callback string) (io.ReadSeeker, time.Time, error) {
	md := mbt.Metadata()

	mapdata := &MapData{
		"1.0.0",
		md.Name,
		md.MinZoom,
		md.MaxZoom,
		[]float64{md.Bounds.W, md.Bounds.S, md.Bounds.E, md.Bounds.N},
		[]float64{md.Center.Lat, md.Center.Lon, md.Center.Zoom},
		[]string{"./tiles/{z}/{x}/{y}.png"},
		[]string{"./grids/{z}/{x}/{y}.json"},
		md.Template,
		md.Legend,
	}

	var buf bytes.Buffer
	if callback != "" {
		buf.WriteString(callback + "(")
	}
	if err := json.NewEncoder(&buf).Encode(mapdata); err != nil {
		return nil, time.Time{}, err
	}
	if callback != "" {
		buf.WriteString(");")
	}

	return bytes.NewReader(buf.Bytes()), mbt.Mtime, nil
}
Exemplo n.º 3
0
func enable_modestmaps(mbt *mbtiles.Map) error {
	mmtmpl, err := template.New("mmtmpl").Parse(mmtext)
	if err != nil {
		return err
	}
	http.Handle("/", http.HandlerFunc(
		func(w http.ResponseWriter, req *http.Request) {
			metadata := mbt.Metadata()
			err = mmtmpl.Execute(w, metadata)
			if err != nil {
				http.Error(w, "template error: "+err.Error(), 500)
			}
		}))
	return nil
}