func (m *Map) RenderToMemoryUTFGrid(lname string, key string, res uint) (string, error) { l := &Layer{} n := int(C.mapnik_map_layer_count(m.m)) for i := 0; i < n; i++ { ml := C.mapnik_map_get_layer(m.m, C.size_t(i)) defer C.free(unsafe.Pointer(ml)) if C.GoString(C.mapnik_layer_name(ml)) == lname { l.l = ml break } } if l.l == nil { return "", fmt.Errorf("no such layer %s", lname) } cs := C.CString(key) defer C.free(unsafe.Pointer(cs)) g := C.mapnik_map_render_to_grid(m.m, l.l, cs) if g == nil { return "", m.lastError() } defer C.mapnik_grid_free(g) json := C.mapnik_grid_to_json(g, C.uint(res)) if json == nil { return "", m.lastError() } defer C.free(unsafe.Pointer(json)) return C.GoString(json), nil }
func (m *Map) printLayerStatus() { n := C.mapnik_map_layer_count(m.m) for i := 0; i < int(n); i++ { fmt.Println( C.GoString(C.mapnik_map_layer_name(m.m, C.size_t(i))), C.mapnik_map_layer_is_active(m.m, C.size_t(i)), ) } }
func (m *Map) currentLayerStatus() []bool { n := C.mapnik_map_layer_count(m.m) active := make([]bool, n) for i := 0; i < int(n); i++ { if C.mapnik_map_layer_is_active(m.m, C.size_t(i)) == 1 { active[i] = true } } return active }
func (m *Map) SetActiveLayer(lname string) { n := int(C.mapnik_map_layer_count(m.m)) for i := 0; i < n; i++ { l := C.mapnik_map_get_layer(m.m, C.size_t(i)) defer C.free(unsafe.Pointer(l)) if C.GoString(C.mapnik_layer_name(l)) == lname { C.mapnik_layer_set_active(l, 1) } else { C.mapnik_layer_set_active(l, 0) } } }
// SelectLayers enables/disables single layers. LayerSelector or SelectorFunc gets called for each layer. func (m *Map) SelectLayers(selector LayerSelector) { m.storeLayerStatus() n := C.mapnik_map_layer_count(m.m) for i := 0; i < int(n); i++ { layerName := C.GoString(C.mapnik_map_layer_name(m.m, C.size_t(i))) switch selector.Select(layerName) { case Include: C.mapnik_map_layer_set_active(m.m, C.size_t(i), 1) case Exclude: C.mapnik_map_layer_set_active(m.m, C.size_t(i), 0) case Default: } } }
func (m *Map) resetLayerStatus() { if len(m.layerStatus) == 0 { return // not stored } n := C.mapnik_map_layer_count(m.m) if int(n) > len(m.layerStatus) { // should not happen return } for i := 0; i < int(n); i++ { if m.layerStatus[i] { C.mapnik_map_layer_set_active(m.m, C.size_t(i), 1) } else { C.mapnik_map_layer_set_active(m.m, C.size_t(i), 0) } } m.layerStatus = nil }