├── mbgl ├── c │ ├── lib │ │ └── linux │ │ │ ├── libpng.a │ │ │ ├── .gitattributes │ │ │ ├── libicu.a │ │ │ ├── libuv.a │ │ │ ├── libjpeg.a │ │ │ ├── libnunicode.a │ │ │ ├── libpng16.a │ │ │ ├── libsqlite.a │ │ │ ├── libmbgl-core.a │ │ │ ├── libmbgl-loop-uv.a │ │ │ └── libmbgl-filesource.a │ ├── include │ │ ├── mbgl │ │ │ ├── util │ │ │ │ ├── variant.hpp │ │ │ │ ├── async_request.hpp │ │ │ │ ├── compression.hpp │ │ │ │ ├── expected.hpp │ │ │ │ ├── premultiply.hpp │ │ │ │ ├── optional.hpp │ │ │ │ ├── geojson.hpp │ │ │ │ ├── work_request.hpp │ │ │ │ ├── async_task.hpp │ │ │ │ ├── noncopyable.hpp │ │ │ │ ├── util.hpp │ │ │ │ ├── timer.hpp │ │ │ │ ├── convert.hpp │ │ │ │ ├── range.hpp │ │ │ │ ├── font_stack.hpp │ │ │ │ ├── work_task.hpp │ │ │ │ ├── ignore.hpp │ │ │ │ ├── feature.hpp │ │ │ │ ├── size.hpp │ │ │ │ ├── platform.hpp │ │ │ │ ├── traits.hpp │ │ │ │ ├── event.hpp │ │ │ │ ├── exception.hpp │ │ │ │ ├── chrono.hpp │ │ │ │ ├── enum.hpp │ │ │ │ ├── tileset.hpp │ │ │ │ ├── char_array_buffer.hpp │ │ │ │ ├── type_list.hpp │ │ │ │ ├── color.hpp │ │ │ │ └── work_task_impl.hpp │ │ │ ├── math │ │ │ │ ├── clamp.hpp │ │ │ │ ├── wrap.hpp │ │ │ │ ├── log2.hpp │ │ │ │ └── minmax.hpp │ │ │ ├── style │ │ │ │ ├── expression │ │ │ │ │ ├── is_expression.hpp │ │ │ │ │ ├── check_subtype.hpp │ │ │ │ │ ├── get_covering_stops.hpp │ │ │ │ │ ├── find_zoom_curve.hpp │ │ │ │ │ ├── collator.hpp │ │ │ │ │ ├── error.hpp │ │ │ │ │ ├── length.hpp │ │ │ │ │ ├── is_constant.hpp │ │ │ │ │ ├── assertion.hpp │ │ │ │ │ ├── coercion.hpp │ │ │ │ │ ├── case.hpp │ │ │ │ │ ├── coalesce.hpp │ │ │ │ │ ├── at.hpp │ │ │ │ │ ├── match.hpp │ │ │ │ │ ├── step.hpp │ │ │ │ │ ├── literal.hpp │ │ │ │ │ ├── formatted.hpp │ │ │ │ │ ├── collator_expression.hpp │ │ │ │ │ ├── boolean_operator.hpp │ │ │ │ │ ├── format_expression.hpp │ │ │ │ │ └── interpolator.hpp │ │ │ │ ├── undefined.hpp │ │ │ │ ├── conversion │ │ │ │ │ ├── get_json_type.hpp │ │ │ │ │ ├── position.hpp │ │ │ │ │ ├── filter.hpp │ │ │ │ │ ├── light.hpp │ │ │ │ │ ├── tileset.hpp │ │ │ │ │ ├── coordinate.hpp │ │ │ │ │ ├── geojson_options.hpp │ │ │ │ │ ├── transition_options.hpp │ │ │ │ │ ├── custom_geometry_source_options.hpp │ │ │ │ │ ├── source.hpp │ │ │ │ │ ├── color_ramp_property_value.hpp │ │ │ │ │ ├── layer.hpp │ │ │ │ │ ├── geojson.hpp │ │ │ │ │ ├── function.hpp │ │ │ │ │ ├── constant.hpp │ │ │ │ │ └── property_value.hpp │ │ │ │ ├── sources │ │ │ │ │ ├── raster_dem_source.hpp │ │ │ │ │ ├── vector_source.hpp │ │ │ │ │ ├── image_source.hpp │ │ │ │ │ ├── raster_source.hpp │ │ │ │ │ ├── geojson_source.hpp │ │ │ │ │ └── custom_geometry_source.hpp │ │ │ │ ├── conversion.hpp │ │ │ │ ├── image.hpp │ │ │ │ ├── transition_options.hpp │ │ │ │ ├── light.hpp.ejs │ │ │ │ ├── filter.hpp │ │ │ │ ├── light.hpp │ │ │ │ ├── color_ramp_property_value.hpp │ │ │ │ ├── style.hpp │ │ │ │ ├── layers │ │ │ │ │ └── background_layer.hpp │ │ │ │ └── position.hpp │ │ │ ├── renderer │ │ │ │ ├── mode.hpp │ │ │ │ ├── renderer_frontend.hpp │ │ │ │ ├── renderer_observer.hpp │ │ │ │ ├── backend_scope.hpp │ │ │ │ ├── query.hpp │ │ │ │ └── renderer_state.hpp │ │ │ ├── tile │ │ │ │ └── tile_necessity.hpp │ │ │ ├── layermanager │ │ │ │ ├── circle_layer_factory.hpp │ │ │ │ ├── fill_layer_factory.hpp │ │ │ │ ├── line_layer_factory.hpp │ │ │ │ ├── raster_layer_factory.hpp │ │ │ │ ├── symbol_layer_factory.hpp │ │ │ │ ├── heatmap_layer_factory.hpp │ │ │ │ ├── background_layer_factory.hpp │ │ │ │ ├── hillshade_layer_factory.hpp │ │ │ │ ├── fill_extrusion_layer_factory.hpp │ │ │ │ ├── custom_layer_factory.hpp │ │ │ │ └── layer_factory.hpp │ │ │ ├── storage │ │ │ │ ├── resource_transform.hpp │ │ │ │ ├── network_status.hpp │ │ │ │ ├── online_file_source.hpp │ │ │ │ ├── file_source.hpp │ │ │ │ └── response.hpp │ │ │ ├── map │ │ │ │ ├── change.hpp │ │ │ │ ├── map_observer.hpp │ │ │ │ └── mode.hpp │ │ │ └── actor │ │ │ │ ├── mailbox.hpp │ │ │ │ ├── scheduler.hpp │ │ │ │ └── aspiring_actor.hpp │ │ ├── include │ │ │ ├── mbgl │ │ │ │ ├── util │ │ │ │ │ ├── shared_thread_pool.hpp │ │ │ │ │ ├── default_thread_pool.hpp │ │ │ │ │ └── default_styles.hpp │ │ │ │ ├── storage │ │ │ │ │ ├── local_file_request.hpp │ │ │ │ │ ├── file_source_request.hpp │ │ │ │ │ ├── offline_download.hpp │ │ │ │ │ └── offline_schema.hpp │ │ │ │ ├── text │ │ │ │ │ └── unaccent.hpp │ │ │ │ ├── gl │ │ │ │ │ ├── headless_backend.hpp │ │ │ │ │ └── headless_frontend.hpp │ │ │ │ └── map │ │ │ │ │ └── map_snapshotter.hpp │ │ │ └── jni │ │ │ │ └── string_conversion.hpp │ │ ├── mapbox │ │ │ ├── geometry.hpp │ │ │ ├── geometry │ │ │ │ ├── empty.hpp │ │ │ │ ├── line_string.hpp │ │ │ │ ├── multi_point.hpp │ │ │ │ ├── multi_polygon.hpp │ │ │ │ ├── box.hpp │ │ │ │ ├── multi_line_string.hpp │ │ │ │ ├── point.hpp │ │ │ │ ├── envelope.hpp │ │ │ │ ├── polygon.hpp │ │ │ │ ├── for_each_point.hpp │ │ │ │ └── geometry.hpp │ │ │ ├── variant_visitor.hpp │ │ │ ├── variant_io.hpp │ │ │ └── optional.hpp │ │ └── auto_cpu_timer.hpp │ ├── patches │ │ └── 0001-Removed-CURLOPT_CAINFO-so-that-it-can-use-the-system.patch │ ├── Makefile │ └── build_render_with_local.sh ├── error.h ├── renderer_frontend.h ├── file_source.h ├── file_source.go ├── renderer_frontend.go ├── thread_pool_test.go ├── mbgl_darwin.go ├── run_loop.go ├── run_loop.h ├── run_loop.cpp ├── thread_pool.h ├── size.h ├── scheduler.h ├── simplified │ ├── simplified.go │ ├── image.go │ ├── snapshot.h │ ├── simplified_linux.go │ └── snapshot.cpp ├── mbgl_linux.go ├── default_file_source.h ├── lat_lng.h ├── size.cpp ├── premultiplied_image.cpp ├── scheduler.cpp ├── size.go ├── thread_pool.go ├── premultiplied_image.h ├── thread_pool.cpp ├── map.h ├── map.go ├── scheduler_test.go ├── scheduler.go ├── size_test.go ├── default_file_source.cpp ├── headless_frontend.h ├── mbgl.go ├── default_file_source.go ├── lat_lng.cpp ├── default_file_source_test.go ├── scheduler_internal_test.go ├── map_test.go ├── camera_options.h ├── camera_options_test.go ├── lat_lng.go ├── premultiplied_image.go ├── map.cpp ├── headless_frontend.go ├── README_build.md └── README.md ├── version.go ├── .travis.yml ├── .gitignore ├── cmd └── snap │ ├── main.go │ └── cmd │ ├── version.go │ └── root.go ├── README.md └── Dockerfile /mbgl/c/lib/linux/libpng.a: -------------------------------------------------------------------------------- 1 | libpng16.a -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | const Version = "0.0.2" 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/.gitattributes: -------------------------------------------------------------------------------- 1 | *.a filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /mbgl/error.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_error_h 2 | #define _mbgl_error_h 3 | 4 | 5 | 6 | #endif //_mbgl_error_h -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - "1.9" 4 | - "1.10" 5 | - "1.11" 6 | 7 | script: go test -v ./... -------------------------------------------------------------------------------- /mbgl/renderer_frontend.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_renderer_frontend_h 2 | #define _mbgl_renderer_frontend_h 3 | typedef struct {} MbglRendererFrontend; 4 | #endif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.png 3 | mason_packages/ 4 | .idea/ 5 | .DS_Store 6 | mapbox-gl-native/ 7 | mason-js/ 8 | lib/ 9 | cmd/snapshot/snapshot 10 | -------------------------------------------------------------------------------- /mbgl/file_source.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_file_source_h 2 | #define _mbgl_file_source_h 3 | 4 | typedef struct {} MbglFileSource; 5 | 6 | #endif // _mbgl_file_source_h -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libicu.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:f3a0e5906cccfca82855ee3e9caa55c8f269fcf9cf7ab286065575154ca03552 3 | size 871706 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libuv.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:05cf0bd6c50b750eef6c4b6c11cededfa03c71d9b251315e8d3912abda917330 3 | size 1154426 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libjpeg.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:714dab75669de25cae474e1a5b1f0cfaa19a0cfd6d3b41ca6948b3f490e7d78d 3 | size 609056 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libnunicode.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8c0b41daaf716c428e202b5205301b595a65b39d25a457f4900d100fd543b15f 3 | size 314514 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libpng16.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5ad3764d90d38c9890ca2e150e67eda29f60b0f0f68463bc13c1b0bea86c6357 3 | size 360514 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libsqlite.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:14f1dc44095db2eddf3bf4f1342d70bc86dfeffe67f76ccf33c959b1db5cb31e 3 | size 2029926 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libmbgl-core.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c815c49f99cf73697e8c95025c2794fc16c110d009c951e7e3815e46faf40669 3 | size 601564714 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libmbgl-loop-uv.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:3fbdcfacb13534f858777fe803553091d3bc4458a730a1efc1735e46f7f39a37 3 | size 1545320 4 | -------------------------------------------------------------------------------- /mbgl/c/lib/linux/libmbgl-filesource.a: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5d226d700640eeb99561b8b7daa94dc083baf41611102fe6ecebc25cbbabee2c 3 | size 23313442 4 | -------------------------------------------------------------------------------- /mbgl/file_source.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "file_source.h" 5 | */ 6 | import "C" 7 | 8 | type FileSource interface { 9 | fileSource() *C.MbglFileSource 10 | Destruct() 11 | } 12 | -------------------------------------------------------------------------------- /mbgl/renderer_frontend.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "renderer_frontend.h" 5 | */ 6 | import "C" 7 | 8 | type RendererFrontend interface { 9 | rendererFrontend() *C.MbglRendererFrontend 10 | Destruct() 11 | } 12 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/variant.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | using variant = mapbox::util::variant; 9 | 10 | } // namespace mbgl 11 | -------------------------------------------------------------------------------- /mbgl/thread_pool_test.go: -------------------------------------------------------------------------------- 1 | package mbgl_test 2 | 3 | import ( 4 | "testing" 5 | "github.com/go-spatial/go-mbgl/mbgl" 6 | ) 7 | 8 | func TestThreadPool(t *testing.T) { 9 | tpool := mbgl.NewThreadPool(4) 10 | tpool.Destruct() 11 | } -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/util/shared_thread_pool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | std::shared_ptr sharedThreadPool(); 8 | 9 | } // namespace mbgl 10 | -------------------------------------------------------------------------------- /cmd/snap/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/go-spatial/go-mbgl/cmd/snap/cmd" 8 | ) 9 | 10 | func main() { 11 | if err := cmd.RootCmd.Execute(); err != nil { 12 | fmt.Println(err) 13 | os.Exit(1) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/async_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class AsyncRequest : private util::noncopyable { 8 | public: 9 | virtual ~AsyncRequest() = default; 10 | }; 11 | 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/compression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | std::string compress(const std::string& raw); 9 | std::string decompress(const std::string& raw); 10 | 11 | } // namespace util 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/expected.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | using expected = nonstd::expected; 9 | 10 | template 11 | using unexpected = nonstd::unexpected_type; 12 | 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/clamp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | template 9 | T clamp(T value, T min_, T max_) { 10 | return max(min_, min(max_, value)); 11 | } 12 | 13 | } // namespace util 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/premultiply.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | PremultipliedImage premultiply(UnassociatedImage&&); 9 | UnassociatedImage unpremultiply(PremultipliedImage&&); 10 | 11 | } // namespace util 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/storage/local_file_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | class ActorRef; 9 | class FileSourceRequest; 10 | 11 | void requestLocalFile(const std::string&, ActorRef); 12 | 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/mbgl_darwin.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #cgo LDFLAGS: -L${SRCDIR}/../lib/darwin 5 | #cgo LDFLAGS: -lmbgl-loop-darwin 6 | #cgo LDFLAGS: -framework Mapbox 7 | #cgo LDFLAGS: -framework CoreFoundation -framework CoreGraphics -framework ImageIO -framework OpenGL -framework CoreText -framework Foundation 8 | */ 9 | import "C" 10 | -------------------------------------------------------------------------------- /mbgl/run_loop.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "run_loop.h" 5 | */ 6 | import "C" 7 | 8 | type RunLoop C.MbglRunLoop 9 | 10 | func NewRunLoop() *RunLoop { 11 | ptr := C.mbgl_run_loop_new() 12 | 13 | return (*RunLoop)(ptr) 14 | } 15 | 16 | func (rl *RunLoop) Destruct() { 17 | C.mbgl_run_loop_destruct((*C.MbglRunLoop)(rl)) 18 | } 19 | -------------------------------------------------------------------------------- /mbgl/run_loop.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_run_loop_h 2 | #define _mbgl_run_loop_h 3 | 4 | typedef struct {} MbglRunLoop; 5 | 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | MbglRunLoop * mbgl_run_loop_new(); 12 | void mbgl_run_loop_destruct(MbglRunLoop * self); 13 | 14 | #ifdef __cplusplus 15 | } // extern "C" 16 | #endif 17 | 18 | #endif -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/is_expression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace style { 7 | namespace expression { 8 | 9 | bool isExpression(const conversion::Convertible& value); 10 | 11 | } // namespace expression 12 | } // namespace style 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/undefined.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { 4 | namespace style { 5 | 6 | class Undefined {}; 7 | 8 | inline bool operator==(const Undefined&, const Undefined&) { return true; } 9 | inline bool operator!=(const Undefined&, const Undefined&) { return false; } 10 | 11 | } // namespace style 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/optional.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | template 8 | using optional = std::experimental::optional; 9 | 10 | using nullopt_t = std::experimental::nullopt_t; 11 | constexpr nullopt_t nullopt = std::experimental::nullopt; 12 | 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/get_json_type.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | namespace conversion { 9 | 10 | std::string getJSONType(const Convertible& value); 11 | 12 | } // namespace conversion 13 | } // namespace style 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/geojson.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | using GeoJSON = mapbox::geojson::geojson; 9 | using FeatureCollection = mapbox::geojson::feature_collection; 10 | using FeatureExtensionValue = mapbox::util::variant; 11 | 12 | } // namespace mbgl 13 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/text/unaccent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace platform { 7 | 8 | // Non-locale-aware diacritic folding based on nunicode 9 | // Used as a fallback when locale-aware comparisons aren't available 10 | std::string unaccent(const std::string &string); 11 | 12 | } // namespace platform 13 | } // namespace mbgl 14 | -------------------------------------------------------------------------------- /mbgl/run_loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "run_loop.h" 4 | 5 | using namespace mbgl::util; 6 | 7 | MbglRunLoop * mbgl_run_loop_new() { 8 | auto ptr = new RunLoop(); 9 | 10 | return reinterpret_cast(ptr); 11 | } 12 | 13 | void mbgl_run_loop_destruct(MbglRunLoop * self) { 14 | auto _self = reinterpret_cast(self); 15 | 16 | delete _self; 17 | } -------------------------------------------------------------------------------- /mbgl/thread_pool.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_thread_pool_h 2 | #define _mbgl_thread_pool_h 3 | 4 | typedef struct{} MbglThreadPool; 5 | 6 | #ifdef __cplusplus 7 | extern "C"{ 8 | #endif //__cplusplus 9 | 10 | MbglThreadPool *mbgl_thread_pool_new(int threads); 11 | 12 | void mbgl_thread_pool_destruct(MbglThreadPool * self); 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif //__cplusplus 17 | 18 | #endif //_mbgl_thread_pool_h -------------------------------------------------------------------------------- /cmd/snap/cmd/version.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var Version = "version not set" 10 | 11 | var cmdVersion = &cobra.Command{ 12 | Use: "version", 13 | Short: "Print the version number.", 14 | Long: `The version of the software. [` + Version + `]`, 15 | Run: func(cmd *cobra.Command, args []string) { 16 | fmt.Println(Version) 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/wrap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | // Constrains n to the given range (including min, excluding max) via modular 9 | // arithmetic. 10 | template 11 | T wrap(T value, T min, T max) { 12 | T d = max - min; 13 | return std::fmod((std::fmod((value - min), d) + d), d) + min; 14 | } 15 | 16 | } // namespace util 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/work_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class WorkTask; 10 | 11 | class WorkRequest : public AsyncRequest { 12 | public: 13 | using Task = std::shared_ptr; 14 | WorkRequest(Task); 15 | ~WorkRequest() override; 16 | 17 | private: 18 | std::shared_ptr task; 19 | }; 20 | 21 | } // namespace mbgl 22 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/check_subtype.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | namespace type { 11 | 12 | optional checkSubtype(const Type& expected, const Type& t); 13 | 14 | } // namespace type 15 | } // namespace expression 16 | } // namespace style 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/size.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_size_h 2 | #define _mbgl_size_h 3 | 4 | #include 5 | 6 | typedef struct{} MbglSize; 7 | 8 | #ifdef __cplusplus 9 | extern "C"{ 10 | #endif //__cplusplus 11 | 12 | MbglSize * mbgl_size_new(uint32_t width, uint32_t height); 13 | 14 | void mbgl_size_set(MbglSize * self, uint32_t width, uint32_t height); 15 | 16 | void mbgl_size_destruct(MbglSize * self); 17 | 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif //__cplusplus 22 | 23 | #endif // _mbgl_size_h -------------------------------------------------------------------------------- /mbgl/c/include/include/jni/string_conversion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // This file replaces the default implementation in jni.hpp. 4 | 5 | #include 6 | 7 | namespace jni { 8 | 9 | inline std::u16string convertUTF8ToUTF16(const std::string& str) { 10 | return mbgl::util::convertUTF8ToUTF16(str); 11 | } 12 | 13 | inline std::string convertUTF16ToUTF8(const std::u16string& str) { 14 | return mbgl::util::convertUTF16ToUTF8(str); 15 | } 16 | 17 | } // namespace jni 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/position.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | optional operator()(const Convertible& value, Error& error) const; 14 | }; 15 | 16 | } // namespace conversion 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/scheduler.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_scheduler_h 2 | #define _mbgl_scheduler_h 3 | 4 | typedef struct{} MbglScheduler; 5 | 6 | #ifdef __cplusplus 7 | extern "C"{ 8 | #endif 9 | 10 | // instance methods 11 | void mbgl_scheduler_destruct(MbglScheduler * self); 12 | 13 | // Static mehtods 14 | MbglScheduler * mbgl_scheduler_get_current(); 15 | void mbgl_scheduler_set_current(MbglScheduler *); 16 | 17 | 18 | #ifdef __cplusplus 19 | } // extern "C" 20 | #endif 21 | 22 | #endif //_mbgl_scheduler_h 23 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/filter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/light.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/tileset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/async_task.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | namespace util { 10 | 11 | class AsyncTask : private util::noncopyable { 12 | public: 13 | AsyncTask(std::function&&); 14 | ~AsyncTask(); 15 | 16 | void send(); 17 | 18 | private: 19 | class Impl; 20 | std::unique_ptr impl; 21 | }; 22 | 23 | } // namespace util 24 | } // namespace mbgl 25 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/coordinate.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template<> 12 | struct Converter { 13 | public: 14 | optional operator() (const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/mode.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | using EnumType = uint32_t; 8 | 9 | // We can avoid redundant GL calls when it is known that the GL context is not 10 | // being shared. In a shared GL context case, we need to make sure that the 11 | // correct GL configurations are in use - they might have changed between render 12 | // calls. 13 | enum class GLContextMode : EnumType { 14 | Unique, 15 | Shared, 16 | }; 17 | 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/geojson_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | optional operator()(const Convertible& value, Error& error) const; 14 | }; 15 | 16 | } // namespace conversion 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/simplified/simplified.go: -------------------------------------------------------------------------------- 1 | package simplified 2 | 3 | /* 4 | #cgo CFLAGS: -fPIC 5 | #cgo CFLAGS: -D_GLIBCXX_USE_CXX11_ABI=1 6 | #cgo CXXFLAGS: -std=c++14 -std=gnu++14 7 | #cgo CXXFLAGS: -g 8 | */ 9 | import "C" 10 | import "github.com/go-spatial/go-mbgl/mbgl" 11 | 12 | var RunLoop *mbgl.RunLoop 13 | 14 | func NewRunLoop() { 15 | if RunLoop == nil { 16 | RunLoop = mbgl.NewRunLoop() 17 | } 18 | } 19 | 20 | func DestroyRunLoop() { 21 | if RunLoop != nil { 22 | RunLoop.Destruct() 23 | RunLoop = nil 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mbgl/mbgl_linux.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #cgo LDFLAGS: -L${SRCDIR}/c/lib/linux 5 | #cgo LDFLAGS: -lmbgl-loop-uv 6 | #cgo LDFLAGS: -lsqlite -lnunicode -licu 7 | #cgo LDFLAGS: -luv -lpthread -ldl -lcurl 8 | #cgo LDFLAGS: -lpng16 -ljpeg 9 | #cgo LDFLAGS: -lOSMesa 10 | #cgo LDFLAGS: -lGL 11 | */ 12 | import "C" 13 | 14 | /* 15 | #cgo LDFLAGS: -lpng16 -ljpeg -lwebp 16 | #cgo -licuuc -ldl 17 | #cgo -lnu -lm 18 | #cgo LDFLAGS: -lX11 19 | #cgo LDFLAGS: -lOSMesa 20 | #cgo LDFLAGS: -lGL 21 | #cgo LDFLAGS: -lOpenGL -lGLX -lEGL 22 | */ 23 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/transition_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | public: 14 | optional operator()(const Convertible& value, Error& error) const; 15 | }; 16 | 17 | } // namespace conversion 18 | } // namespace style 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/noncopyable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { namespace util { 4 | 5 | namespace non_copyable_ 6 | { 7 | 8 | class noncopyable 9 | { 10 | public: 11 | noncopyable( noncopyable const& ) = delete; 12 | noncopyable& operator=(noncopyable const& ) = delete; 13 | 14 | protected: 15 | constexpr noncopyable() = default; 16 | ~noncopyable() = default; 17 | }; 18 | } // namespace non_copyable_ 19 | 20 | using noncopyable = non_copyable_::noncopyable; 21 | 22 | } // namespace util 23 | } // namespace mbgl 24 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/util.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NDEBUG 4 | 5 | #include 6 | #define MBGL_STORE_THREAD(tid) const std::thread::id tid = std::this_thread::get_id(); 7 | #define MBGL_VERIFY_THREAD(tid) assert(tid == std::this_thread::get_id()); 8 | 9 | #else 10 | 11 | #define MBGL_STORE_THREAD(tid) 12 | #define MBGL_VERIFY_THREAD(tid) 13 | 14 | #endif 15 | 16 | // GCC 4.9 compatibility 17 | #if !defined(__GNUC__) || __GNUC__ >= 5 18 | #define MBGL_CONSTEXPR constexpr 19 | #else 20 | #define MBGL_CONSTEXPR inline 21 | #endif 22 | -------------------------------------------------------------------------------- /mbgl/default_file_source.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_default_file_source_h 2 | #define _mbgl_default_file_source_h 3 | 4 | #include 5 | 6 | typedef struct {} MbglDefaultFileSource; 7 | 8 | #ifdef __cplusplus 9 | extern "C"{ 10 | #endif 11 | 12 | MbglDefaultFileSource * mbgl_default_file_source_new(const char * cachePath, const char * assetRoot, uint64_t * maxCacheSize); 13 | 14 | void mbgl_default_file_source_destruct(MbglDefaultFileSource * self); 15 | 16 | #ifdef __cplusplus 17 | } // extern "C"{ 18 | #endif 19 | 20 | #endif // _mbgl_default_file_source_h -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/tile/tile_necessity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { 4 | 5 | // Tiles can have two states: optional or required. 6 | // - optional means that only low-cost actions should be taken to obtain the data 7 | // (e.g. load from cache, but accept stale data) 8 | // - required means that every effort should be taken to obtain the data (e.g. load 9 | // from internet and keep the data fresh if it expires) 10 | enum class TileNecessity : bool { 11 | Optional = false, 12 | Required = true, 13 | }; 14 | 15 | } // namespace mbgl 16 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/circle_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class CircleLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/fill_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class FillLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/line_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class LineLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/raster_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RasterLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/symbol_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class SymbolLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/heatmap_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class HeatmapLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/background_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class BackgroundLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/hillshade_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class HillshadeLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace util { 11 | 12 | class Timer : private util::noncopyable { 13 | public: 14 | Timer(); 15 | ~Timer(); 16 | 17 | void start(Duration timeout, Duration repeat, std::function&&); 18 | void stop(); 19 | 20 | private: 21 | class Impl; 22 | std::unique_ptr impl; 23 | }; 24 | 25 | } // namespace util 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/simplified/image.go: -------------------------------------------------------------------------------- 1 | package simplified 2 | 3 | import ( 4 | "image" 5 | "image/color" 6 | ) 7 | 8 | type Image struct { 9 | Data []byte 10 | Width, Height int 11 | } 12 | 13 | func (im Image) ColorModel() color.Model { return color.RGBAModel } 14 | func (im Image) Bounds() image.Rectangle { return image.Rect(0, 0, im.Width, im.Height) } 15 | func (im Image) At(x, y int) color.Color { 16 | i := im.Width * 4 * y 17 | i += 4 * x 18 | 19 | return color.RGBA{ 20 | im.Data[i], 21 | im.Data[i+1], 22 | im.Data[i+2], 23 | im.Data[i+3], 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/fill_extrusion_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class FillExtrusionLayerFactory : public LayerFactory { 8 | protected: 9 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 10 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 11 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 12 | }; 13 | 14 | } // namespace mbgl 15 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/custom_geometry_source_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | template <> 12 | struct Converter { 13 | optional operator()(const Convertible& value, Error& error) const; 14 | }; 15 | 16 | } // namespace conversion 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace conversion { 12 | 13 | template <> 14 | struct Converter> { 15 | public: 16 | optional> operator()(const Convertible& value, Error& error, const std::string& id) const; 17 | }; 18 | 19 | } // namespace conversion 20 | } // namespace style 21 | } // namespace mbgl 22 | -------------------------------------------------------------------------------- /mbgl/lat_lng.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_lat_lng_h 2 | #define _mbgl_lat_lng_h 3 | 4 | typedef struct{} MbglLatLng; 5 | typedef struct{} MbglLatLngBounds; 6 | 7 | #ifdef __cplusplus 8 | extern "C"{ 9 | #endif 10 | 11 | // lat long 12 | MbglLatLng * mbgl_lat_lng_new(double lat, double lng); 13 | void mbgl_lat_lng_destruct(MbglLatLng * self); 14 | 15 | // bounds 16 | MbglLatLngBounds * mbgl_lat_lng_bounds_hull(MbglLatLng * a, MbglLatLng * b); 17 | void mbgl_lat_lng_bounds_destruct(MbglLatLngBounds * self); 18 | 19 | #ifdef __cplusplus 20 | } //extern "C" 21 | #endif 22 | 23 | #endif //_mbgl_lat_lng_h -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/color_ramp_property_value.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | namespace conversion { 9 | 10 | template <> 11 | struct Converter { 12 | optional operator()(const Convertible& value, Error& error, bool /* allowDataExpressions */ = false, bool /* convertTokens */ = false) const; 13 | }; 14 | 15 | } // namespace conversion 16 | } // namespace style 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/size.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "size.h" 4 | 5 | using namespace mbgl; 6 | 7 | MbglSize * mbgl_size_new(uint32_t width, uint32_t height) { 8 | auto s = new Size(width, height); 9 | 10 | return reinterpret_cast(s); 11 | } 12 | 13 | void mbgl_size_set(MbglSize * self, uint32_t width, uint32_t height) { 14 | auto obj = reinterpret_cast(self); 15 | obj->width = width; 16 | obj->height = height; 17 | } 18 | 19 | void mbgl_size_destruct(MbglSize* self) { 20 | auto cast = reinterpret_cast(self); 21 | delete cast; 22 | } -------------------------------------------------------------------------------- /mbgl/c/include/auto_cpu_timer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | struct auto_cpu_timer { 7 | std::chrono::time_point start; 8 | auto_cpu_timer() : start(std::chrono::high_resolution_clock::now()) { 9 | } 10 | ~auto_cpu_timer() { 11 | auto end = std::chrono::high_resolution_clock::now(); 12 | std::chrono::microseconds elapsed = 13 | std::chrono::duration_cast(end - start); 14 | std::cerr << elapsed.count() << "us" << std::endl; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/convert.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace util { 9 | 10 | template::value>> 12 | MBGL_CONSTEXPR std::array convert(const std::array&from) { 13 | std::array to {{}}; 14 | std::copy(std::begin(from), std::end(from), std::begin(to)); 15 | return to; 16 | } 17 | 18 | } // namespace util 19 | } // namespace mbgl 20 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/range.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #pragma once 4 | 5 | namespace mbgl { 6 | 7 | template 8 | class Range { 9 | public: 10 | constexpr Range(T min_, T max_) 11 | : min(std::move(min_)), max(std::move(max_)) {} 12 | 13 | T min; 14 | T max; 15 | }; 16 | 17 | template 18 | bool operator==(const Range& a, const Range& b) { 19 | return a.min == b.min && a.max == b.max; 20 | } 21 | 22 | template 23 | bool operator!=(const Range& a, const Range& b) { 24 | return !(a == b); 25 | } 26 | 27 | } // namespace mbgl 28 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/get_covering_stops.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | namespace style { 10 | namespace expression { 11 | 12 | // Return the smallest range of stops that covers the interval [lower, upper] 13 | Range getCoveringStops(const std::map>& stops, 14 | const double lower, const double upper); 15 | 16 | } // namespace expression 17 | } // namespace style 18 | } // namespace mbgl 19 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/custom_layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class CustomLayerFactory : public LayerFactory { 11 | protected: 12 | const style::LayerTypeInfo* getTypeInfo() const noexcept final; 13 | std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept final; 14 | std::unique_ptr createRenderLayer(Immutable) noexcept final; 15 | }; 16 | 17 | } // namespace mbgl 18 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/layer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace conversion { 12 | 13 | template <> 14 | struct Converter> { 15 | public: 16 | optional> operator()(const Convertible& value, Error& error) const; 17 | }; 18 | 19 | optional setPaintProperties(Layer& layer, const Convertible& value); 20 | 21 | } // namespace conversion 22 | } // namespace style 23 | } // namespace mbgl 24 | -------------------------------------------------------------------------------- /mbgl/premultiplied_image.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "premultiplied_image.h" 3 | #include 4 | 5 | // image 6 | 7 | RawImage * mbgl_premultiplied_image_raw(MbglPremultipliedImage * img) { 8 | auto _img = reinterpret_cast(img); 9 | 10 | auto ret = new RawImage{}; 11 | ret->height = _img->size.height; 12 | ret->width = _img->size.width; 13 | ret->data = _img->data.get(); 14 | 15 | return ret; 16 | } 17 | 18 | void mbgl_premultiplied_image_destruct(MbglPremultipliedImage * self) { 19 | auto cast = reinterpret_cast(self); 20 | delete cast; 21 | } 22 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/geojson.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace conversion { 10 | 11 | // Workaround until https://github.com/mapbox/mapbox-gl-native/issues/5623 is done. 12 | optional parseGeoJSON(const std::string&, Error&); 13 | 14 | template <> 15 | struct Converter { 16 | public: 17 | optional operator()(const Convertible&, Error&) const; 18 | }; 19 | 20 | } // namespace conversion 21 | } // namespace style 22 | } // namespace mbgl 23 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/raster_dem_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class RasterDEMSource : public RasterSource { 14 | public: 15 | RasterDEMSource(std::string id, variant urlOrTileset, uint16_t tileSize); 16 | 17 | }; 18 | 19 | template <> 20 | inline bool Source::is() const { 21 | return getType() == SourceType::RasterDEM; 22 | } 23 | 24 | } // namespace style 25 | } // namespace mbgl 26 | -------------------------------------------------------------------------------- /mbgl/scheduler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "scheduler.h" 4 | 5 | using namespace mbgl; 6 | 7 | // instance methods 8 | 9 | void mbgl_scheduler_destruct(MbglScheduler * self) { 10 | auto cast = reinterpret_cast(self); 11 | delete self; 12 | } 13 | 14 | //static methods 15 | 16 | MbglScheduler * mbgl_scheduler_get_current() { 17 | auto sched = Scheduler::GetCurrent(); 18 | return reinterpret_cast(sched); 19 | } 20 | 21 | void mbgl_scheduler_set_current(MbglScheduler * sched) { 22 | auto cast = reinterpret_cast(sched); 23 | Scheduler::SetCurrent(cast); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mbgl/size.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "size.h" 5 | */ 6 | import "C" 7 | 8 | type Size struct { 9 | Width, Height uint32 10 | ptr *C.MbglSize 11 | } 12 | 13 | func (s *Size) update() { 14 | 15 | if s.ptr == nil { 16 | s.ptr = C.mbgl_size_new(C.uint32_t(s.Width), C.uint32_t(s.Height)) 17 | } else { 18 | C.mbgl_size_set(s.ptr, C.uint32_t(s.Width), C.uint32_t(s.Height)) 19 | } 20 | } 21 | 22 | // called within the package 23 | func (s *Size) cSize() *C.MbglSize { 24 | s.update() 25 | return s.ptr 26 | } 27 | 28 | func (s *Size) Destruct() { 29 | if s.ptr != nil { 30 | C.mbgl_size_destruct(s.ptr) 31 | s.ptr = nil 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mbgl/thread_pool.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "scheduler.h" 5 | #include "thread_pool.h" 6 | */ 7 | import "C" 8 | 9 | type ThreadPool C.MbglThreadPool 10 | 11 | func NewThreadPool(threads int) (*ThreadPool) { 12 | ptr := C.mbgl_thread_pool_new(C.int(threads)) 13 | 14 | return (*ThreadPool)(ptr) 15 | } 16 | 17 | func (t *ThreadPool) threadPool() *C.MbglThreadPool { 18 | return (*C.MbglThreadPool)(t) 19 | } 20 | 21 | // Scheduler is a prarent class 22 | func (t *ThreadPool) scheduler() *C.MbglScheduler { 23 | return (*C.MbglScheduler)(t) 24 | } 25 | 26 | func (t *ThreadPool) Destruct() { 27 | C.mbgl_thread_pool_destruct(t.threadPool()) 28 | } 29 | -------------------------------------------------------------------------------- /mbgl/premultiplied_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _premultiplied_image_h 2 | #define _premultiplied_image_h 3 | 4 | #include 5 | #include 6 | 7 | typedef struct{} MbglMapSnapshotter; 8 | typedef struct{} MbglPremultipliedImage; 9 | 10 | typedef struct{ 11 | size_t height; 12 | size_t width; 13 | uint8_t * data; 14 | } RawImage; 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | // image 21 | RawImage * mbgl_premultiplied_image_raw(MbglPremultipliedImage * self); 22 | 23 | void mbgl_premultiplied_image_destruct(MbglPremultipliedImage * self); 24 | 25 | #ifdef __cplusplus 26 | } // extern "C" 27 | #endif 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/empty.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mapbox { 4 | namespace geometry { 5 | 6 | struct empty 7 | { 8 | }; // this Geometry type represents the empty point set, ∅, for the coordinate space (OGC Simple Features). 9 | 10 | constexpr bool operator==(empty, empty) { return true; } 11 | constexpr bool operator!=(empty, empty) { return false; } 12 | constexpr bool operator<(empty, empty) { return false; } 13 | constexpr bool operator>(empty, empty) { return false; } 14 | constexpr bool operator<=(empty, empty) { return true; } 15 | constexpr bool operator>=(empty, empty) { return true; } 16 | 17 | } // namespace geometry 18 | } // namespace mapbox 19 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/util/default_thread_pool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | 12 | class ThreadPool : public Scheduler { 13 | public: 14 | ThreadPool(std::size_t count); 15 | ~ThreadPool() override; 16 | 17 | void schedule(std::weak_ptr) override; 18 | 19 | private: 20 | std::vector threads; 21 | std::queue> queue; 22 | std::mutex mutex; 23 | std::condition_variable cv; 24 | bool terminate { false }; 25 | }; 26 | 27 | } // namespace mbgl 28 | -------------------------------------------------------------------------------- /mbgl/thread_pool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include "thread_pool.h" 7 | 8 | 9 | MbglThreadPool * mbgl_thread_pool_new(int threads) { 10 | auto tpool = new mbgl::ThreadPool(threads); 11 | 12 | std::cout << "new ptr " << tpool << std::endl; 13 | 14 | return reinterpret_cast(tpool); 15 | } 16 | 17 | 18 | void mbgl_thread_pool_destruct(MbglThreadPool * self) { 19 | auto cast = reinterpret_cast(self); 20 | std::cout << "old ptr " << self << std::endl; 21 | // TODO: GDEY/EAR7H need to fix this. 22 | //delete cast; 23 | } 24 | -------------------------------------------------------------------------------- /cmd/snap/cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import "github.com/spf13/cobra" 4 | 5 | var RootCmd = &cobra.Command{ 6 | Use: "snap", 7 | Short: "snap is a raster tile server", 8 | Long: `snap is a raster tile server version: ` + Version, 9 | } 10 | 11 | const DefaultRootStyle = "https://raw.githubusercontent.com/go-spatial/tegola-web-demo/master/styles/hot-osm.json" 12 | 13 | var RootStyle string = DefaultRootStyle 14 | 15 | func init() { 16 | 17 | RootCmd.PersistentFlags().StringVarP(&RootStyle, "style", "s", DefaultRootStyle, "style to use. Style name will be default") 18 | 19 | RootCmd.AddCommand(cmdServer) 20 | RootCmd.AddCommand(cmdVersion) 21 | RootCmd.AddCommand(cmdGenerate) 22 | } 23 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/find_zoom_curve.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | optional> findZoomCurve(const expression::Expression* e); 15 | 16 | variant findZoomCurveChecked(const expression::Expression* e); 17 | 18 | } // namespace expression 19 | } // namespace style 20 | } // namespace mbgl 21 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace style { 7 | namespace conversion { 8 | 9 | // This is a forward-declaration only header intended to minimize dependencies and to improve 10 | // compilation speed. In order to specialize implementations and get access to the actual 11 | // implementation, include . 12 | 13 | struct Error { std::string message; }; 14 | 15 | template 16 | class ConversionTraits; 17 | 18 | class Convertible; 19 | 20 | template 21 | struct Converter; 22 | 23 | } // namespace conversion 24 | } // namespace style 25 | } // namespace mbgl 26 | 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/font_stack.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | 12 | // An array of font names 13 | using FontStack = std::vector; 14 | using FontStackHash = std::size_t; 15 | 16 | std::string fontStackToString(const FontStack&); 17 | 18 | struct FontStackHasher { 19 | FontStackHash operator()(const FontStack&) const; 20 | }; 21 | 22 | // Statically evaluate layer properties to determine what font stacks are used. 23 | std::set fontStacks(const std::vector>&); 24 | 25 | } // namespace mbgl 26 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/work_task.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | // A movable type-erasing function wrapper. This allows to store arbitrary invokable 10 | // things (like std::function<>, or the result of a movable-only std::bind()) in the queue. 11 | // Source: http://stackoverflow.com/a/29642072/331379 12 | class WorkTask : private util::noncopyable { 13 | public: 14 | virtual ~WorkTask() = default; 15 | 16 | virtual void operator()() = 0; 17 | virtual void cancel() = 0; 18 | 19 | template 20 | static std::shared_ptr make(Fn&&, Args&&...); 21 | }; 22 | 23 | } // namespace mbgl 24 | -------------------------------------------------------------------------------- /mbgl/map.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_map_h 2 | #define _mbgl_map_h 3 | 4 | #include "file_source.h" 5 | #include "map.h" 6 | #include "size.h" 7 | #include "scheduler.h" 8 | #include "renderer_frontend.h" 9 | #include "camera_options.h" 10 | 11 | 12 | typedef struct{} MbglMap; 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | MbglMap * mbgl_map_new(MbglRendererFrontend * frontend, 19 | MbglSize * size, 20 | float pixelRatio, 21 | MbglFileSource * src, 22 | MbglScheduler * sched); 23 | 24 | void mbgl_map_destruct(MbglMap * self); 25 | 26 | void mbgl_map_jump_to(MbglMap * self, MbglCameraOptions * opts); 27 | 28 | void mbgl_map_set_style_url(MbglMap * self, const char * addr); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/resource_transform.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class Mailbox; 12 | 13 | class ResourceTransform { 14 | public: 15 | using TransformCallback = std::function; 16 | using FinishedCallback = std::function; 17 | 18 | ResourceTransform(ActorRef, TransformCallback&&); 19 | 20 | void transform(Resource::Kind, const std::string&& url, FinishedCallback&&); 21 | 22 | private: 23 | TransformCallback transformCallback; 24 | }; 25 | 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/collator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class Collator { 14 | public: 15 | Collator(bool caseSensitive, bool diacriticSensitive, optional locale = {}); 16 | 17 | bool operator==(const Collator& other) const; 18 | 19 | int compare(const std::string& lhs, const std::string& rhs) const; 20 | 21 | std::string resolvedLocale() const; 22 | private: 23 | class Impl; 24 | std::shared_ptr impl; 25 | }; 26 | 27 | } // namespace expression 28 | } // namespace style 29 | } // namespace mbgl 30 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/image.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mbgl { 9 | namespace style { 10 | 11 | class Image { 12 | public: 13 | Image(std::string id, PremultipliedImage&&, float pixelRatio, bool sdf = false); 14 | Image(const Image&); 15 | 16 | std::string getID() const; 17 | 18 | const PremultipliedImage& getImage() const; 19 | 20 | // Pixel ratio of the sprite image. 21 | float getPixelRatio() const; 22 | 23 | // Whether this image should be interpreted as a signed distance field icon. 24 | bool isSdf() const; 25 | 26 | class Impl; 27 | Immutable baseImpl; 28 | }; 29 | 30 | } // namespace style 31 | } // namespace mbgl 32 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/network_status.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | namespace util { 10 | class AsyncTask; 11 | } // namespace util 12 | 13 | class NetworkStatus { 14 | public: 15 | enum class Status : uint8_t { 16 | Online, 17 | Offline, 18 | }; 19 | 20 | static Status Get(); 21 | static void Set(Status); 22 | 23 | static void Reachable(); 24 | 25 | static void Subscribe(util::AsyncTask* async); 26 | static void Unsubscribe(util::AsyncTask* async); 27 | 28 | private: 29 | static std::atomic online; 30 | static std::mutex mtx; 31 | static std::unordered_set observers; 32 | }; 33 | 34 | } // namespace mbgl 35 | -------------------------------------------------------------------------------- /mbgl/map.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "map.h" 5 | */ 6 | import "C" 7 | 8 | type Map C.MbglMap 9 | 10 | func NewMap(frontend RendererFrontend, 11 | size Size, 12 | pixelRatio float32, 13 | src FileSource, 14 | sched Scheduler) *Map { 15 | 16 | ptr := C.mbgl_map_new( 17 | frontend.rendererFrontend(), 18 | size.cSize(), 19 | C.float(pixelRatio), 20 | src.fileSource(), 21 | sched.scheduler()) 22 | 23 | return (*Map)(ptr) 24 | } 25 | 26 | func (m *Map) Destruct() { 27 | C.mbgl_map_destruct((*C.MbglMap)(m)) 28 | } 29 | 30 | func (m *Map) jumpTo(opts *CameraOptions) { 31 | C.mbgl_map_jump_to( 32 | (*C.MbglMap)(m), 33 | opts.cPtr()) 34 | } 35 | 36 | func (m *Map) setStyleUrl(str string) { 37 | C.mbgl_map_set_style_url( 38 | (*C.MbglMap)(m), 39 | C.CString(str)) 40 | } 41 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/line_string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct line_string : Cont> 13 | { 14 | using coordinate_type = T; 15 | using point_type = point; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | line_string(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | line_string(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/multi_point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct multi_point : Cont> 13 | { 14 | using coordinate_type = T; 15 | using point_type = point; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | multi_point(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | multi_point(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/scheduler_test.go: -------------------------------------------------------------------------------- 1 | package mbgl_test 2 | 3 | import ( 4 | "testing" 5 | "github.com/go-spatial/go-mbgl/mbgl" 6 | ) 7 | 8 | func TestScheduler(t *testing.T) { 9 | type tcase struct { 10 | sched mbgl.Scheduler 11 | } 12 | 13 | fn := func(tc tcase, t *testing.T) { 14 | mbgl.SchedulerSetCurrent(tc.sched) 15 | 16 | sched := mbgl.SchedulerGetCurrent() 17 | 18 | if (sched == nil) != (tc.sched == nil) { 19 | t.Fatalf("incorrect value %v, expected %v", sched, tc.sched) 20 | } 21 | } 22 | 23 | testcases := map[string]tcase{ 24 | "1" : { 25 | sched: mbgl.NewThreadPool(1), 26 | }, 27 | "2" : { 28 | sched: mbgl.NewThreadPool(4), 29 | }, 30 | "nil" : { 31 | sched: nil, 32 | }, 33 | } 34 | 35 | for k, v := range testcases { 36 | t.Run(k, func(t *testing.T) { 37 | fn(v, t) 38 | }) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/storage/file_source_request.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | 12 | class Mailbox; 13 | 14 | class FileSourceRequest : public AsyncRequest { 15 | public: 16 | FileSourceRequest(FileSource::Callback&& callback); 17 | ~FileSourceRequest() final; 18 | 19 | void onCancel(std::function&& callback); 20 | void setResponse(const Response& res); 21 | 22 | ActorRef actor(); 23 | 24 | private: 25 | FileSource::Callback responseCallback = nullptr; 26 | std::function cancelCallback = nullptr; 27 | 28 | std::shared_ptr mailbox; 29 | }; 30 | 31 | } // namespace mbgl 32 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/multi_polygon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct multi_polygon : Cont> 13 | { 14 | using coordinate_type = T; 15 | using polygon_type = polygon; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | multi_polygon(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | multi_polygon(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/ignore.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | // Accept any number of parameters of any types, and do nothing with them. 9 | // Useful for providing a context for parameter pack expansion where a legal 10 | // expansion context is not otherwise available. 11 | // 12 | // See https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md 13 | // for more details. 14 | // 15 | template void ignore(Ts&&...) {} 16 | 17 | // std::initializer_list overload, for situations where you need sequenced 18 | // modifications. 19 | // 20 | template void ignore(const std::initializer_list&) {} 21 | 22 | // Handle the zero-argument case. 23 | inline void ignore(const std::initializer_list&) {} 24 | 25 | } // namespace util 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/box.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mapbox { 6 | namespace geometry { 7 | 8 | template 9 | struct box 10 | { 11 | using coordinate_type = T; 12 | using point_type = point; 13 | 14 | constexpr box(point_type const& min_, point_type const& max_) 15 | : min(min_), max(max_) 16 | { 17 | } 18 | 19 | point_type min; 20 | point_type max; 21 | }; 22 | 23 | template 24 | constexpr bool operator==(box const& lhs, box const& rhs) 25 | { 26 | return lhs.min == rhs.min && lhs.max == rhs.max; 27 | } 28 | 29 | template 30 | constexpr bool operator!=(box const& lhs, box const& rhs) 31 | { 32 | return lhs.min != rhs.min || lhs.max != rhs.max; 33 | } 34 | 35 | } // namespace geometry 36 | } // namespace mapbox 37 | -------------------------------------------------------------------------------- /mbgl/scheduler.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "scheduler.h" 5 | */ 6 | import "C" 7 | 8 | // Represents the scheduler super class 9 | type Scheduler interface { 10 | scheduler() *C.MbglScheduler 11 | Destruct() 12 | } 13 | 14 | // Satisfies the schduler inteface 15 | type scheduler C.MbglScheduler 16 | 17 | func (s *scheduler) scheduler() *C.MbglScheduler { 18 | return (*C.MbglScheduler)(s) 19 | } 20 | 21 | func (s *scheduler) Destruct() { 22 | C.mbgl_scheduler_destruct(s.scheduler()) 23 | } 24 | 25 | func SchedulerGetCurrent() Scheduler { 26 | ptr := C.mbgl_scheduler_get_current() 27 | if ptr == nil { 28 | return nil 29 | } 30 | 31 | return (*scheduler)(ptr) 32 | } 33 | 34 | func SchedulerSetCurrent(sched Scheduler) { 35 | if sched == nil { 36 | C.mbgl_scheduler_set_current(nil) 37 | } else { 38 | C.mbgl_scheduler_set_current(sched.scheduler()) 39 | } 40 | } -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/multi_line_string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | // stl 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template class Cont = std::vector> 12 | struct multi_line_string : Cont> 13 | { 14 | using coordinate_type = T; 15 | using line_string_type = line_string; 16 | using container_type = Cont; 17 | using size_type = typename container_type::size_type; 18 | 19 | template 20 | multi_line_string(Args&&... args) : container_type(std::forward(args)...) 21 | { 22 | } 23 | multi_line_string(std::initializer_list args) 24 | : container_type(std::move(args)) {} 25 | }; 26 | 27 | } // namespace geometry 28 | } // namespace mapbox 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/map/change.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | enum MapChange : uint8_t { 8 | MapChangeRegionWillChange = 0, 9 | MapChangeRegionWillChangeAnimated = 1, 10 | MapChangeRegionIsChanging = 2, 11 | MapChangeRegionDidChange = 3, 12 | MapChangeRegionDidChangeAnimated = 4, 13 | MapChangeWillStartLoadingMap = 5, 14 | MapChangeDidFinishLoadingMap = 6, 15 | MapChangeDidFailLoadingMap = 7, 16 | MapChangeWillStartRenderingFrame = 8, 17 | MapChangeDidFinishRenderingFrame = 9, 18 | MapChangeDidFinishRenderingFrameFullyRendered = 10, 19 | MapChangeWillStartRenderingMap = 11, 20 | MapChangeDidFinishRenderingMap = 12, 21 | MapChangeDidFinishRenderingMapFullyRendered = 13, 22 | MapChangeDidFinishLoadingStyle = 14, 23 | MapChangeSourceDidChange = 15 24 | }; 25 | 26 | } // namespace mbgl 27 | -------------------------------------------------------------------------------- /mbgl/size_test.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | import "testing" 4 | 5 | func TestSize(t *testing.T) { 6 | type size struct{ 7 | width, height uint32 8 | } 9 | 10 | type tcase struct { 11 | vals []size 12 | } 13 | 14 | fn := func(tc tcase, t *testing.T) { 15 | 16 | s := Size{} 17 | for _, v := range tc.vals { 18 | s.Height = v.height 19 | s.Width = v.width 20 | 21 | s.cSize() 22 | s.Destruct() 23 | 24 | } 25 | 26 | // run on destructed Size 27 | s.cSize() 28 | s.Destruct() 29 | 30 | // finalizer 31 | s = Size{} 32 | } 33 | 34 | testcases := map[string]tcase { 35 | "1": { 36 | []size { 37 | {0, 0}, 38 | }, 39 | }, 40 | "2": { 41 | []size{ 42 | {0, 0}, 43 | {128, 128}, 44 | {128, 1024}, 45 | }, 46 | }, 47 | } 48 | 49 | for k, v := range testcases { 50 | t.Run(k, func(t *testing.T) { 51 | fn(v, t) 52 | }) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mapbox { 4 | namespace geometry { 5 | 6 | template 7 | struct point 8 | { 9 | using coordinate_type = T; 10 | 11 | constexpr point() 12 | : x(), y() 13 | { 14 | } 15 | constexpr point(T x_, T y_) 16 | : x(x_), y(y_) 17 | { 18 | } 19 | 20 | T x; 21 | T y; 22 | }; 23 | 24 | #pragma GCC diagnostic push 25 | #pragma GCC diagnostic ignored "-Wfloat-equal" 26 | 27 | template 28 | constexpr bool operator==(point const& lhs, point const& rhs) 29 | { 30 | return lhs.x == rhs.x && lhs.y == rhs.y; 31 | } 32 | 33 | #pragma GCC diagnostic pop 34 | 35 | template 36 | constexpr bool operator!=(point const& lhs, point const& rhs) 37 | { 38 | return !(lhs == rhs); 39 | } 40 | 41 | } // namespace geometry 42 | } // namespace mapbox 43 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/feature.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | using Value = mapbox::feature::value; 10 | using NullValue = mapbox::feature::null_value_t; 11 | using PropertyMap = mapbox::feature::property_map; 12 | using FeatureIdentifier = mapbox::feature::identifier; 13 | using Feature = mapbox::feature::feature; 14 | 15 | template 16 | optional numericValue(const Value& value) { 17 | return value.match( 18 | [] (uint64_t t) { 19 | return optional(t); 20 | }, 21 | [] (int64_t t) { 22 | return optional(t); 23 | }, 24 | [] (double t) { 25 | return optional(t); 26 | }, 27 | [] (auto) { 28 | return optional(); 29 | }); 30 | } 31 | 32 | } // namespace mbgl 33 | -------------------------------------------------------------------------------- /mbgl/default_file_source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "default_file_source.h" 6 | 7 | using namespace mbgl; 8 | 9 | MbglDefaultFileSource * mbgl_default_file_source_new(const char * cachePath, const char * assetRoot, uint64_t * maxCacheSize) { 10 | auto _cachePath = std::string(cachePath); 11 | auto _assetRoot = std::string(assetRoot); 12 | 13 | DefaultFileSource * fs; 14 | 15 | if (maxCacheSize != nullptr) { 16 | fs = new DefaultFileSource(_cachePath, _assetRoot, *maxCacheSize); 17 | } else { 18 | fs = new DefaultFileSource(_cachePath, _assetRoot); 19 | } 20 | 21 | return reinterpret_cast(fs); 22 | } 23 | 24 | void mbgl_default_file_source_destruct(MbglDefaultFileSource * self) { 25 | auto cast = reinterpret_cast(self); 26 | delete cast; 27 | } -------------------------------------------------------------------------------- /mbgl/simplified/snapshot.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_simplifed_snapshot_h 2 | #define _mbgl_simplifed_snapshot_h 3 | 4 | #include 5 | #include 6 | 7 | 8 | // This is the raw image that we be returned. 9 | typedef struct{ 10 | size_t Height; 11 | size_t Width; 12 | uint8_t *Data; 13 | } RawImage; 14 | 15 | typedef struct { 16 | char * style; 17 | char * cache_file; 18 | char * asset_root; 19 | uint32_t width; 20 | uint32_t height; 21 | double ppi_ratio; 22 | double lat; 23 | double lng; 24 | double zoom; 25 | double pitch; 26 | double bearing; 27 | } snapshot_Params; 28 | 29 | typedef struct { 30 | RawImage * Image; 31 | int DidError; 32 | const char * Err; 33 | } snapshot_Result; 34 | 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | snapshot_Result Snapshot(snapshot_Params params); 41 | 42 | #ifdef __cplusplus 43 | } // extern "C" 44 | #endif 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/variant_visitor.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAPBOX_UTIL_VARIANT_VISITOR_HPP 2 | #define MAPBOX_UTIL_VARIANT_VISITOR_HPP 3 | 4 | namespace mapbox { 5 | namespace util { 6 | 7 | template 8 | struct visitor; 9 | 10 | template 11 | struct visitor : Fn 12 | { 13 | using type = Fn; 14 | using Fn::operator(); 15 | 16 | visitor(Fn fn) : Fn(fn) {} 17 | }; 18 | 19 | template 20 | struct visitor : Fn, visitor 21 | { 22 | using type = visitor; 23 | using Fn::operator(); 24 | using visitor::operator(); 25 | 26 | visitor(Fn fn, Fns... fns) : Fn(fn), visitor(fns...) {} 27 | }; 28 | 29 | template 30 | visitor make_visitor(Fns... fns) 31 | { 32 | return visitor(fns...); 33 | } 34 | 35 | } // namespace util 36 | } // namespace mapbox 37 | 38 | #endif // MAPBOX_UTIL_VARIANT_VISITOR_HPP 39 | -------------------------------------------------------------------------------- /mbgl/headless_frontend.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_headless_frontend_h 2 | #define _mbgl_headless_frontend_h 3 | 4 | 5 | #include "file_source.h" 6 | #include "premultiplied_image.h" 7 | #include "size.h" 8 | #include "scheduler.h" 9 | #include "map.h" 10 | 11 | 12 | typedef struct {} MbglHeadlessFrontend; 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | MbglHeadlessFrontend * mbgl_headless_frontend_new( 19 | MbglSize * size, 20 | float pixelRatio, 21 | MbglFileSource * source, 22 | MbglScheduler * sched, 23 | const char * cacheDir, 24 | const char * fontFamily); 25 | 26 | void mbgl_headless_frontend_destruct(MbglHeadlessFrontend * self); 27 | 28 | MbglPremultipliedImage * mbgl_headless_frontend_render(MbglHeadlessFrontend * self, MbglMap * map); 29 | 30 | MbglSize * mbgl_headless_frontend_get_size(); 31 | void mbgl_headless_frontend_set_size(MbglSize *); 32 | 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /mbgl/mbgl.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #cgo CFLAGS: -fPIC 5 | #cgo CFLAGS: -D_GLIBCXX_USE_CXX11_ABI=1 6 | #cgo CXXFLAGS: -std=c++14 -std=gnu++14 7 | #cgo CXXFLAGS: -g 8 | #cgo CXXFLAGS: -I${SRCDIR}/c/include 9 | #cgo CXXFLAGS: -I${SRCDIR}/c/include/include 10 | #cgo CXXFLAGS: -I${SRCDIR}/c/mapbox-gl-native/platform/default 11 | 12 | #cgo LDFLAGS: -lmbgl-filesource 13 | #cgo LDFLAGS: -lmbgl-core 14 | #cgo LDFLAGS: -lsqlite3 -lz 15 | 16 | 17 | */ 18 | import "C" 19 | 20 | // @cgo CXXFLAGS: -I${SRCDIR}/../mason_packages/.link/include 21 | // @cgo CXXFLAGS: -I${SRCDIR}/../mapbox-gl-native/vendor/expected/include 22 | // @cgo CXXFLAGS: -I${SRCDIR}/../mapbox-gl-native/include 23 | // @cgo CXXFLAGS: -I${SRCDIR}/../mapbox-gl-native/platform/default 24 | // @cgo LDFLAGS: -L${SRCDIR}/../mason_packages/.link/lib 25 | // @cgo LDFLAGS: -lsqlite3 -lz 26 | // @cgo LDFLAGS: -lmbgl-filesource -lmbgl-core 27 | // #cgo CXXFLAGS: -I${SRCDIR}/c/mapbox-gl-native/include 28 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/renderer_frontend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RendererObserver; 8 | class UpdateParameters; 9 | 10 | // The RenderFrontend is the bridge between the Map and 11 | // platform used to update and observer the Renderer 12 | // 13 | // It hides any threading specifics and always replies on 14 | // the original thread. 15 | class RendererFrontend { 16 | public: 17 | 18 | virtual ~RendererFrontend() = default; 19 | 20 | // Must synchronously clean up the Renderer if set 21 | virtual void reset() = 0; 22 | 23 | // Implementer must bind the renderer observer to the renderer in a 24 | // appropriate manner so that the callbacks occur on the main thread 25 | virtual void setObserver(RendererObserver&) = 0; 26 | 27 | // Coalescing updates is up to the implementer 28 | virtual void update(std::shared_ptr) = 0; 29 | }; 30 | 31 | } // namespace mbgl 32 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/renderer_observer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RendererObserver { 8 | public: 9 | virtual ~RendererObserver() = default; 10 | 11 | enum class RenderMode : uint32_t { 12 | Partial, 13 | Full 14 | }; 15 | 16 | // Signals that a repaint is required 17 | virtual void onInvalidate() {} 18 | 19 | // Resource failed to download / parse 20 | virtual void onResourceError(std::exception_ptr) {} 21 | 22 | // First frame 23 | virtual void onWillStartRenderingMap() {} 24 | 25 | // Start of frame, initial is the first frame for this map 26 | virtual void onWillStartRenderingFrame() {} 27 | 28 | // End of frame, boolean flags that a repaint is required 29 | virtual void onDidFinishRenderingFrame(RenderMode, bool) {} 30 | 31 | // Final frame 32 | virtual void onDidFinishRenderingMap() {} 33 | }; 34 | 35 | } // namespace mbgl 36 | -------------------------------------------------------------------------------- /mbgl/default_file_source.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "file_source.h" 5 | #include "default_file_source.h" 6 | */ 7 | import "C" 8 | 9 | type DefaultFileSource C.MbglDefaultFileSource 10 | 11 | func (fs *DefaultFileSource) defaultFileSource() *C.MbglDefaultFileSource { 12 | return (*C.MbglDefaultFileSource)(fs) 13 | } 14 | 15 | // This instantiates a new file source which can handle online and offline sources. It will create a chache file 16 | func NewDefaultFileSource(cachePath, assetRoot string, maxCache *uint64) *DefaultFileSource { 17 | ptr := C.mbgl_default_file_source_new(C.CString(cachePath), 18 | C.CString(assetRoot), 19 | (*C.uint64_t)(maxCache)) 20 | 21 | return (*DefaultFileSource)(ptr) 22 | } 23 | 24 | func (fs *DefaultFileSource) fileSource() *C.MbglFileSource { 25 | return (*C.MbglFileSource)(fs.defaultFileSource()) 26 | } 27 | 28 | func (fs *DefaultFileSource) Destruct() { 29 | C.mbgl_default_file_source_destruct(fs.defaultFileSource()) 30 | } -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/vector_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class VectorSource : public Source { 14 | public: 15 | VectorSource(std::string id, variant urlOrTileset); 16 | ~VectorSource() final; 17 | 18 | const variant& getURLOrTileset() const; 19 | optional getURL() const; 20 | 21 | class Impl; 22 | const Impl& impl() const; 23 | 24 | void loadDescription(FileSource&) final; 25 | 26 | private: 27 | const variant urlOrTileset; 28 | std::unique_ptr req; 29 | }; 30 | 31 | template <> 32 | inline bool Source::is() const { 33 | return getType() == SourceType::Vector; 34 | } 35 | 36 | } // namespace style 37 | } // namespace mbgl 38 | -------------------------------------------------------------------------------- /mbgl/lat_lng.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "lat_lng.h" 4 | 5 | using namespace mbgl; 6 | 7 | //lat long 8 | MbglLatLng * mbgl_lat_lng_new(double lat, double lng) { 9 | auto latLng = new LatLng{ 10 | lat, lng 11 | }; 12 | 13 | return reinterpret_cast(latLng); 14 | } 15 | 16 | void mbgl_lat_lng_destruct(MbglLatLng * self) { 17 | auto latLng = reinterpret_cast(self); 18 | 19 | delete latLng; 20 | } 21 | 22 | // bounds 23 | MbglLatLngBounds * mbgl_lat_lng_bounds_hull(MbglLatLng * a, MbglLatLng * b) { 24 | auto _a = reinterpret_cast(a); 25 | auto _b = reinterpret_cast(b); 26 | 27 | auto bb = LatLngBounds::hull(*_a, *_b); 28 | auto _bb = new LatLngBounds(bb); 29 | 30 | return reinterpret_cast(_bb); 31 | } 32 | 33 | void mbgl_lat_lng_bounds_destruct(MbglLatLngBounds * self) { 34 | auto cast = reinterpret_cast(self); 35 | 36 | delete cast; 37 | } -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/size.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | class Size { 9 | public: 10 | constexpr Size() = default; 11 | 12 | constexpr Size(const uint32_t width_, const uint32_t height_) : width(width_), height(height_) { 13 | } 14 | 15 | constexpr uint32_t area() const { 16 | return width * height; 17 | } 18 | 19 | constexpr float aspectRatio() const { 20 | return static_cast(width) / static_cast(height); 21 | } 22 | 23 | constexpr bool isEmpty() const { 24 | return width == 0 || height == 0; 25 | } 26 | 27 | uint32_t width = 0; 28 | uint32_t height = 0; 29 | }; 30 | 31 | constexpr inline bool operator==(const Size& a, const Size& b) { 32 | return a.width == b.width && a.height == b.height; 33 | } 34 | 35 | constexpr inline bool operator!=(const Size& a, const Size& b) { 36 | return !(a == b); 37 | } 38 | 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/envelope.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace mapbox { 9 | namespace geometry { 10 | 11 | template 12 | box envelope(G const& geometry) 13 | { 14 | using limits = std::numeric_limits; 15 | 16 | T min_t = limits::has_infinity ? -limits::infinity() : limits::min(); 17 | T max_t = limits::has_infinity ? limits::infinity() : limits::max(); 18 | 19 | point min(max_t, max_t); 20 | point max(min_t, min_t); 21 | 22 | for_each_point(geometry, [&](point const& point) { 23 | if (min.x > point.x) min.x = point.x; 24 | if (min.y > point.y) min.y = point.y; 25 | if (max.x < point.x) max.x = point.x; 26 | if (max.y < point.y) max.y = point.y; 27 | }); 28 | 29 | return box(min, max); 30 | } 31 | 32 | } // namespace geometry 33 | } // namespace mapbox 34 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/function.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace conversion { 12 | 13 | bool hasTokens(const std::string&); 14 | std::unique_ptr convertTokenStringToFormatExpression(const std::string&); 15 | std::unique_ptr convertTokenStringToExpression(const std::string&); 16 | 17 | optional> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens); 18 | 19 | template 20 | optional> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens); 21 | 22 | } // namespace conversion 23 | } // namespace style 24 | } // namespace mbgl 25 | -------------------------------------------------------------------------------- /mbgl/c/patches/0001-Removed-CURLOPT_CAINFO-so-that-it-can-use-the-system.patch: -------------------------------------------------------------------------------- 1 | diff --git a/platform/default/src/mbgl/storage/http_file_source.cpp b/platform/default/src/mbgl/storage/http_file_source.cpp 2 | index 213b53d..009eb9b 100644 3 | --- a/platform/default/src/mbgl/storage/http_file_source.cpp 4 | +++ b/platform/default/src/mbgl/storage/http_file_source.cpp 5 | @@ -325,7 +325,7 @@ HTTPRequest::HTTPRequest(HTTPFileSource::Impl* context_, Resource resource_, Fil 6 | 7 | handleError(curl::easy_setopt(handle, CURLOPT_PRIVATE, this)); 8 | handleError(curl::easy_setopt(handle, CURLOPT_ERRORBUFFER, error)); 9 | - handleError(curl::easy_setopt(handle, CURLOPT_CAINFO, "ca-bundle.crt")); 10 | + //handleError(curl::easy_setopt(handle, CURLOPT_CAINFO, "ca-bundle.crt")); 11 | handleError(curl::easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1)); 12 | handleError(curl::easy_setopt(handle, CURLOPT_URL, resource.url.c_str())); 13 | handleError(curl::easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeCallback)); 14 | -------------------------------------------------------------------------------- /mbgl/default_file_source_test.go: -------------------------------------------------------------------------------- 1 | package mbgl_test 2 | 3 | import ( 4 | "testing" 5 | "github.com/go-spatial/go-mbgl/mbgl" 6 | "github.com/arolek/p" 7 | ) 8 | 9 | func TestDefaultFileSource(t *testing.T) { 10 | 11 | type tcase struct { 12 | cachePath, assetRoot string 13 | maxCache *uint64 14 | } 15 | 16 | fn := func(tc tcase, t *testing.T) { 17 | mbgl.NewDefaultFileSource(tc.cachePath, tc.assetRoot, tc.maxCache) 18 | 19 | } 20 | 21 | testcases := map[string]tcase{ 22 | "1" : { 23 | cachePath: "", 24 | assetRoot: "https://osm.tegola.io/capabilities/osm", 25 | maxCache: nil, 26 | }, 27 | "2" : { 28 | cachePath: "./cache", 29 | assetRoot: "https://osm.tegola.io/capabilities/osm", 30 | maxCache: p.Uint64(200), 31 | }, 32 | } 33 | 34 | for k, v := range testcases { 35 | t.Run(k, func (t *testing.T) { 36 | fn(v, t) 37 | }) 38 | } 39 | 40 | } 41 | 42 | func TestFileSourceInterface(t *testing.T) { 43 | fs := mbgl.NewDefaultFileSource("", "", nil) 44 | mbgl.FileSource(fs).Destruct() 45 | } 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/log2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #if defined(__ANDROID__) 8 | #include 9 | #endif 10 | 11 | namespace mbgl { 12 | namespace util { 13 | 14 | // Computes the log2(x) rounded up to the next integer. 15 | // (== number of bits required to store x) 16 | uint32_t ceil_log2(uint64_t x); 17 | 18 | template 19 | T log2(T x) { 20 | // log2() is producing wrong results on ARMv5 binaries 21 | // running on ARMv7+ CPUs. 22 | #if defined(__ANDROID__) 23 | return ::log(x) / M_LN2; 24 | #else 25 | return ::log2(x); 26 | #endif 27 | } 28 | 29 | } // namespace util 30 | } // namespace mbgl 31 | 32 | // log2 is not available on Android before API 18. 33 | #if defined(__ANDROID__) && defined(__GNUC__) && \ 34 | defined(__ANDROID_API__) && __ANDROID_API__ < 18 35 | 36 | template 37 | typename std::enable_if_t::value, T> log2(T x) { 38 | return ::log(x) / M_LN2; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /mbgl/scheduler_internal_test.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | import ( 4 | "testing" 5 | "fmt" 6 | ) 7 | 8 | func TestScheduler(t *testing.T) { 9 | type tcase struct { 10 | sched Scheduler 11 | } 12 | 13 | fn := func(tc tcase, t *testing.T) { 14 | SchedulerSetCurrent(tc.sched) 15 | 16 | sched := SchedulerGetCurrent() 17 | 18 | if (sched == nil) != (tc.sched == nil) { 19 | fmt.Printf("%p, %v\n", tc.sched, tc.sched == nil) 20 | t.Fatalf("incorrect value %v, expected %v", sched, tc.sched) 21 | } else if tc.sched == nil { 22 | // they are both nil, pass 23 | } else if sched.scheduler() != tc.sched.scheduler() { 24 | t.Fatalf("incorrect value %v, expected %v",sched.scheduler(), tc.sched.scheduler()) 25 | } 26 | } 27 | 28 | testcases := map[string]tcase{ 29 | "1" : { 30 | sched: NewThreadPool(1), 31 | }, 32 | "2" : { 33 | sched: NewThreadPool(4), 34 | }, 35 | "nil" : { 36 | sched: nil, 37 | }, 38 | } 39 | 40 | for k, v := range testcases { 41 | t.Run(k, func(t *testing.T) { 42 | fn(v, t) 43 | }) 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | 11 | class Error : public Expression { 12 | public: 13 | Error(std::string message_) 14 | : Expression(Kind::Error, type::Error), 15 | message(std::move(message_)) {} 16 | 17 | void eachChild(const std::function&) const override {} 18 | 19 | bool operator==(const Expression& e) const override { 20 | return e.getKind() == Kind::Error; 21 | } 22 | 23 | EvaluationResult evaluate(const EvaluationContext&) const override { 24 | return EvaluationError{message}; 25 | } 26 | 27 | std::vector> possibleOutputs() const override { 28 | return {}; 29 | } 30 | 31 | std::string getOperator() const override { return "error"; } 32 | 33 | private: 34 | std::string message; 35 | }; 36 | 37 | } // namespace expression 38 | } // namespace style 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/length.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Length : public Expression { 15 | public: 16 | Length(std::unique_ptr input); 17 | 18 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 19 | 20 | EvaluationResult evaluate(const EvaluationContext& params) const override; 21 | void eachChild(const std::function& visit) const override; 22 | bool operator==(const Expression& e) const override; 23 | std::vector> possibleOutputs() const override; 24 | std::string getOperator() const override { return "length"; } 25 | 26 | private: 27 | std::unique_ptr input; 28 | }; 29 | 30 | } // namespace expression 31 | } // namespace style 32 | } // namespace mbgl 33 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/image_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | class LatLng; 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class ImageSource : public Source { 14 | public: 15 | ImageSource(std::string id, const std::array); 16 | ~ImageSource() override; 17 | 18 | optional getURL() const; 19 | void setURL(const std::string& url); 20 | 21 | void setImage(PremultipliedImage&&); 22 | 23 | void setCoordinates(const std::array&); 24 | std::array getCoordinates() const; 25 | 26 | class Impl; 27 | const Impl& impl() const; 28 | 29 | void loadDescription(FileSource&) final; 30 | private: 31 | optional url; 32 | std::unique_ptr req; 33 | }; 34 | 35 | template <> 36 | inline bool Source::is() const { 37 | return getType() == SourceType::Image; 38 | } 39 | 40 | } // namespace style 41 | } // namespace mbgl 42 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/raster_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | 9 | class AsyncRequest; 10 | 11 | namespace style { 12 | 13 | class RasterSource : public Source { 14 | public: 15 | RasterSource(std::string id, variant urlOrTileset, uint16_t tileSize, SourceType sourceType = SourceType::Raster); 16 | ~RasterSource() override; 17 | 18 | const variant& getURLOrTileset() const; 19 | optional getURL() const; 20 | 21 | uint16_t getTileSize() const; 22 | 23 | class Impl; 24 | const Impl& impl() const; 25 | 26 | void loadDescription(FileSource&) final; 27 | 28 | private: 29 | const variant urlOrTileset; 30 | std::unique_ptr req; 31 | }; 32 | 33 | template <> 34 | inline bool Source::is() const { 35 | return getType() == SourceType::Raster; 36 | } 37 | 38 | } // namespace style 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/Makefile: -------------------------------------------------------------------------------- 1 | # PLACE YOUR MAPBOXGL INCLUDES HERE 2 | INCLUDES=\ 3 | -I/Users/julio/lib/c/mapbox-gl-native/include \ 4 | -I/Users/julio/lib/c/mapbox-gl-native/platform/default 5 | 6 | LINKS_DW=\ 7 | -lmbgl-loop-darwin\ 8 | -framework Mapbox\ 9 | -framework CoreFoundation\ 10 | -framework CoreGraphics\ 11 | -framework ImageIO\ 12 | -framework OpenGL\ 13 | -framework CoreText\ 14 | -framework Foundation 15 | 16 | # reflecetd in mblg.go file 17 | BUILD_FLAGS=-fPIC\ 18 | -D_GLIBCXX_USE_CXX11_ABI=1\ 19 | -std=c++14 -std=gnu++14\ 20 | -g\ 21 | -I./mason_packages/\.link/include\ 22 | -L./mason_packages/.link/lib\ 23 | -lsqlite3 -lz\ 24 | -lmbgl-filesource -lmbgl-core 25 | 26 | CGO_CXXFLAGS=$(INCLUDES) 27 | 28 | GO_FLAGS=CGO_CXXFLAGS="$(CGO_CXXFLAGS)" 29 | 30 | run= 31 | dir=./... 32 | 33 | .PHONY: test 34 | test: 35 | $(GO_FLAGS) go test -v $(dir) --run=$(run) 36 | 37 | f= 38 | .PHONY: dwfile 39 | dwfile: 40 | g++ $(BUILD_FLAGS) $(CGO_CXXFLAGS) $(LINKS_DW) -c $(f) 41 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/backend_scope.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mbgl { 4 | 5 | class RendererBackend; 6 | 7 | class BackendScope { 8 | public: 9 | // There are two types of scopes: Creating an "Implicit" scope tells Mapbox GL that the 10 | // supporting windowing system has already activated the GL Backend and that no further actions 11 | // are required. Creating an "Explicit" scope actually enables the GL Backend, and disables it 12 | // when the BackendScope is destroyed. 13 | enum class ScopeType : bool { 14 | Implicit, 15 | Explicit, 16 | }; 17 | 18 | BackendScope(RendererBackend&, ScopeType = ScopeType::Explicit); 19 | ~BackendScope(); 20 | 21 | // Returns true when there is currently a BackendScope active in this thread. 22 | static bool exists(); 23 | 24 | private: 25 | void activate(); 26 | void deactivate(); 27 | 28 | BackendScope* priorScope; 29 | BackendScope* nextScope; 30 | RendererBackend& backend; 31 | const ScopeType scopeType; 32 | bool activated = false; 33 | }; 34 | 35 | } // namespace mbgl 36 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/transition_options.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | 9 | class TransitionOptions { 10 | public: 11 | optional duration; 12 | optional delay; 13 | bool enablePlacementTransitions; 14 | 15 | TransitionOptions(optional duration_ = {}, 16 | optional delay_ = {}, 17 | bool enablePlacementTransitions_ = true) 18 | : duration(std::move(duration_)), 19 | delay(std::move(delay_)), 20 | enablePlacementTransitions(enablePlacementTransitions_) {} 21 | 22 | TransitionOptions reverseMerge(const TransitionOptions& defaults) const { 23 | return { 24 | duration ? duration : defaults.duration, 25 | delay ? delay : defaults.delay, 26 | enablePlacementTransitions 27 | }; 28 | } 29 | 30 | bool isDefined() const { 31 | return duration || delay; 32 | } 33 | }; 34 | 35 | } // namespace style 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/variant_io.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MAPBOX_UTIL_VARIANT_IO_HPP 2 | #define MAPBOX_UTIL_VARIANT_IO_HPP 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace mapbox { 9 | namespace util { 10 | 11 | namespace detail { 12 | // operator<< helper 13 | template 14 | class printer 15 | { 16 | public: 17 | explicit printer(Out& out) 18 | : out_(out) {} 19 | printer& operator=(printer const&) = delete; 20 | 21 | // visitor 22 | template 23 | void operator()(T const& operand) const 24 | { 25 | out_ << operand; 26 | } 27 | 28 | private: 29 | Out& out_; 30 | }; 31 | } 32 | 33 | // operator<< 34 | template 35 | VARIANT_INLINE std::basic_ostream& 36 | operator<<(std::basic_ostream& out, variant const& rhs) 37 | { 38 | detail::printer> visitor(out); 39 | apply_visitor(visitor, rhs); 40 | return out; 41 | } 42 | } // namespace util 43 | } // namespace mapbox 44 | 45 | #endif // MAPBOX_UTIL_VARIANT_IO_HPP 46 | -------------------------------------------------------------------------------- /mbgl/map_test.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/arolek/p" 7 | ) 8 | 9 | func TestMap(t *testing.T) { 10 | type tcase struct { 11 | size Size 12 | pixelRatio float32 13 | src FileSource 14 | sched Scheduler 15 | } 16 | 17 | fn := func(tc tcase, t *testing.T) { 18 | loop := NewRunLoop() 19 | defer loop.Destruct() 20 | 21 | front := NewHeadlessFrontend(&tc.size, 22 | tc.pixelRatio, 23 | tc.src, 24 | tc.sched, 25 | nil, nil) 26 | 27 | NewMap(front, 28 | tc.size, 29 | tc.pixelRatio, 30 | tc.src, 31 | tc.sched). 32 | Destruct() 33 | 34 | front.Destruct() 35 | tc.size.Destruct() 36 | tc.src.Destruct() 37 | tc.sched.Destruct() 38 | } 39 | 40 | testcases := map[string]tcase{ 41 | "1": { 42 | size: Size{Height: 256, Width: 256}, 43 | pixelRatio: 1.0, 44 | src: NewDefaultFileSource("", "https://osm.tegola.io/maps/osm/style.json", p.Uint64(0)), 45 | sched: NewThreadPool(4), 46 | }, 47 | } 48 | 49 | for k, v := range testcases { 50 | t.Run(k, func(t *testing.T) { 51 | fn(v, t) 52 | }) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/is_constant.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace style { 8 | namespace expression { 9 | 10 | template 11 | bool isGlobalPropertyConstant(const Expression& expression, const T& properties) { 12 | if (expression.getKind() == Kind::CompoundExpression) { 13 | auto e = static_cast(&expression); 14 | for (const std::string& property : properties) { 15 | if (e->getOperator() == property) { 16 | return false; 17 | } 18 | } 19 | } 20 | 21 | bool isConstant = true; 22 | expression.eachChild([&](const Expression& e) { 23 | if (isConstant && !isGlobalPropertyConstant(e, properties)) { 24 | isConstant = false; 25 | } 26 | }); 27 | return isConstant; 28 | }; 29 | 30 | bool isFeatureConstant(const Expression& expression); 31 | bool isZoomConstant(const Expression& e); 32 | 33 | 34 | } // namespace expression 35 | } // namespace style 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/platform.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace platform { 8 | 9 | class Request; 10 | 11 | // Uppercase a string, potentially using platform-specific routines. 12 | std::string uppercase(const std::string &string); 13 | 14 | // Lowercase a string, potentially using platform-specific routines. 15 | std::string lowercase(const std::string &string); 16 | 17 | // Gets the name of the current thread. 18 | std::string getCurrentThreadName(); 19 | 20 | // Set the name of the current thread, truncated at 15. 21 | void setCurrentThreadName(const std::string& name); 22 | 23 | // Makes the current thread low priority. 24 | void makeThreadLowPriority(); 25 | 26 | // Shows an alpha image with the specified dimensions in a named window. 27 | void showDebugImage(std::string name, const char *data, size_t width, size_t height); 28 | 29 | // Shows an alpha image with the specified dimensions in a named window. 30 | void showColorDebugImage(std::string name, const char *data, size_t logical_width, size_t logical_height, size_t width, size_t height); 31 | } // namespace platform 32 | } // namespace mbgl 33 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/math/minmax.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace util { 9 | 10 | template 11 | typename std::enable_if_t::value, T> max(T a, T b) { 12 | return std::max(a, b); 13 | } 14 | 15 | template 16 | typename std::enable_if_t::value, T> max(T a, T b) { 17 | return ::fmax(a, b); 18 | } 19 | 20 | template 21 | typename std::enable_if_t::value, T> max(T a, T b, Ts... args) { 22 | return max(a, max(b, args...)); 23 | } 24 | 25 | template 26 | typename std::enable_if_t::value, T> min(T a, T b) { 27 | return std::min(a, b); 28 | } 29 | 30 | template 31 | typename std::enable_if_t::value, T> min(T a, T b) { 32 | return ::fmin(a, b); 33 | } 34 | 35 | template 36 | typename std::enable_if_t::value, T> min(T a, T b, Ts... args) { 37 | return min(a, min(b, args...)); 38 | } 39 | 40 | } // namespace util 41 | } // namespace mbgl 42 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/assertion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Assertion : public Expression { 15 | public: 16 | Assertion(type::Type type_, std::vector> inputs_); 17 | 18 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 19 | 20 | EvaluationResult evaluate(const EvaluationContext& params) const override; 21 | void eachChild(const std::function& visit) const override; 22 | 23 | bool operator==(const Expression& e) const override; 24 | 25 | std::vector> possibleOutputs() const override; 26 | 27 | mbgl::Value serialize() const override; 28 | std::string getOperator() const override; 29 | 30 | private: 31 | std::vector> inputs; 32 | }; 33 | 34 | } // namespace expression 35 | } // namespace style 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/coercion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class Coercion : public Expression { 14 | public: 15 | Coercion(type::Type type_, std::vector> inputs_); 16 | 17 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 18 | 19 | EvaluationResult evaluate(const EvaluationContext& params) const override; 20 | void eachChild(const std::function& visit) const override; 21 | 22 | mbgl::Value serialize() const override; 23 | 24 | bool operator==(const Expression& e) const override; 25 | 26 | std::vector> possibleOutputs() const override; 27 | 28 | std::string getOperator() const override; 29 | private: 30 | EvaluationResult (*coerceSingleValue) (const Value& v); 31 | std::vector> inputs; 32 | }; 33 | 34 | } // namespace expression 35 | } // namespace style 36 | } // namespace mbgl 37 | 38 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/light.hpp.ejs: -------------------------------------------------------------------------------- 1 | <% 2 | const properties = locals.properties; 3 | -%> 4 | // This file is generated. Do not edit. 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace mbgl { 14 | namespace style { 15 | 16 | class LightObserver; 17 | 18 | class Light { 19 | public: 20 | Light(); 21 | ~Light(); 22 | 23 | <% for (const property of properties) { -%> 24 | static <%- evaluatedType(property) %> getDefault<%- camelize(property.name) %>(); 25 | <%- propertyValueType(property) %> get<%- camelize(property.name) %>() const; 26 | void set<%- camelize(property.name) %>(<%- propertyValueType(property) %>); 27 | void set<%- camelize(property.name) %>Transition(const TransitionOptions&); 28 | TransitionOptions get<%- camelize(property.name) %>Transition() const; 29 | 30 | <% } -%> 31 | class Impl; 32 | Immutable impl; 33 | Mutable mutableImpl() const; 34 | 35 | LightObserver* observer = nullptr; 36 | void setObserver(LightObserver*); 37 | }; 38 | 39 | } // namespace style 40 | } // namespace mbgl 41 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/layermanager/layer_factory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | class RenderLayer; 8 | 9 | /** 10 | * @brief The LayerFactory abstract class 11 | * 12 | * This class is responsible for creation of the layer objects that belong to a concrete layer type. 13 | */ 14 | class LayerFactory { 15 | public: 16 | virtual ~LayerFactory() = default; 17 | /// Returns the layer type data. 18 | virtual const style::LayerTypeInfo* getTypeInfo() const noexcept = 0; 19 | /// Returns a new Layer instance on success call; returns `nulltptr` otherwise. 20 | virtual std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept = 0; 21 | /// Returns a new RenderLayer instance on success call; returns `nulltptr` otherwise. 22 | virtual std::unique_ptr createRenderLayer(Immutable) noexcept = 0; 23 | 24 | protected: 25 | optional getSource(const style::conversion::Convertible& value) const noexcept; 26 | bool initSourceLayerAndFilter(style::Layer*, const style::conversion::Convertible& value) const noexcept; 27 | }; 28 | 29 | } // namespace mbgl 30 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/traits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | template 9 | constexpr auto underlying_type(T t) -> typename std::underlying_type_t { 10 | return typename std::underlying_type_t(t); 11 | } 12 | 13 | template struct is_utf16char_like: std::false_type {}; 14 | template struct is_utf16char_like: is_utf16char_like {}; 15 | template <> struct is_utf16char_like: std::true_type {}; 16 | template <> struct is_utf16char_like: std::true_type {}; 17 | template <> struct is_utf16char_like: std::true_type {}; 18 | 19 | template using is_utf16char_like_pointer = std::integral_constant::value 20 | && is_utf16char_like::type>::value>; 21 | 22 | template 23 | typename std::enable_if::value && is_utf16char_like_pointer::value, OutPointer>::type utf16char_cast(InChar *in) 24 | { 25 | return reinterpret_cast(in); 26 | } 27 | 28 | } // namespace mbgl 29 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/event.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | 7 | enum class EventSeverity : uint8_t { 8 | Debug, 9 | Info, 10 | Warning, 11 | Error, 12 | }; 13 | 14 | enum class Event : uint8_t { 15 | General, 16 | Setup, 17 | Shader, 18 | ParseStyle, 19 | ParseTile, 20 | Render, 21 | Style, 22 | Database, 23 | HttpRequest, 24 | Sprite, 25 | Image, 26 | OpenGL, 27 | JNI, 28 | Android, 29 | Crash, 30 | Glyph, 31 | Timing 32 | }; 33 | 34 | struct EventPermutation { 35 | const EventSeverity severity; 36 | const Event event; 37 | 38 | constexpr bool operator==(const EventPermutation &rhs) const { 39 | return severity == rhs.severity && event == rhs.event; 40 | } 41 | }; 42 | 43 | constexpr EventSeverity disabledEventSeverities[] = { 44 | #ifndef NDEBUG 45 | EventSeverity(-1) // Avoid zero size array 46 | #else 47 | EventSeverity::Debug 48 | #endif 49 | }; 50 | 51 | constexpr Event disabledEvents[] = { 52 | Event(-1) // Avoid zero size array 53 | }; 54 | 55 | constexpr EventPermutation disabledEventPermutations[] = { 56 | { EventSeverity::Debug, Event::Shader } 57 | }; 58 | 59 | } // namespace mbgl 60 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/query.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | /** 12 | * Options for query rendered features. 13 | */ 14 | class RenderedQueryOptions { 15 | public: 16 | RenderedQueryOptions(optional> layerIDs_ = {}, 17 | optional filter_ = {}) 18 | : layerIDs(std::move(layerIDs_)), 19 | filter(std::move(filter_)) {} 20 | 21 | /** layerIDs to include in the query */ 22 | optional> layerIDs; 23 | 24 | optional filter; 25 | }; 26 | 27 | /** 28 | * Options for query source features 29 | */ 30 | class SourceQueryOptions { 31 | public: 32 | SourceQueryOptions(optional> sourceLayers_ = {}, 33 | optional filter_ = {}) 34 | : sourceLayers(std::move(sourceLayers_)), 35 | filter(std::move(filter_)) {} 36 | 37 | // Required for VectorSource, ignored for GeoJSONSource 38 | optional> sourceLayers; 39 | 40 | optional filter; 41 | }; 42 | 43 | } // namespace mbgl 44 | -------------------------------------------------------------------------------- /mbgl/camera_options.h: -------------------------------------------------------------------------------- 1 | #ifndef _mbgl_camera_options_h 2 | #define _mbgl_camera_options_h 3 | 4 | #include "lat_lng.h" 5 | 6 | typedef struct{} MbglCameraOptions; 7 | typedef struct{} MbglEdgeInsets; 8 | typedef struct{} MbglPoint; 9 | 10 | 11 | #ifdef __cplusplus 12 | extern "C"{ 13 | #endif 14 | 15 | // camera options 16 | MbglCameraOptions * mbgl_camera_options_new(MbglLatLng * latLng, 17 | MbglEdgeInsets * padding, 18 | MbglPoint * anchor, 19 | double * zoom, 20 | double * angle, 21 | double * pitch); 22 | 23 | void mbgl_camera_options_update(MbglCameraOptions * self, 24 | MbglLatLng * latLng, 25 | MbglEdgeInsets * padding, 26 | MbglPoint * anchor, 27 | double * zoom, 28 | double * angle, 29 | double * pitch); 30 | 31 | void mbgl_camera_options_destruct(MbglCameraOptions * self); 32 | 33 | // edge insets 34 | MbglEdgeInsets * mbgl_edge_insets_new(double top, double left, double bottom, double right); 35 | void mbgl_edge_insets_destruct(MbglEdgeInsets * self); 36 | 37 | // point 38 | MbglPoint * mbgl_point_new(double x, double y); 39 | void mbgl_point_update(MbglPoint * self, double x, double y); 40 | void mbgl_point_destruct(MbglPoint * self); 41 | 42 | #ifdef __cplusplus 43 | } //extern "C" 44 | #endif 45 | 46 | 47 | #endif // _mbgl_camera_options_h -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/gl/headless_backend.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class HeadlessBackend : public RendererBackend { 11 | public: 12 | HeadlessBackend(Size = { 256, 256 }); 13 | ~HeadlessBackend() override; 14 | 15 | void bind() override; 16 | Size getFramebufferSize() const override; 17 | void updateAssumedState() override; 18 | 19 | void setSize(Size); 20 | PremultipliedImage readStillImage(); 21 | 22 | class Impl { 23 | public: 24 | virtual ~Impl() = default; 25 | virtual gl::ProcAddress getExtensionFunctionPointer(const char*) = 0; 26 | virtual void activateContext() = 0; 27 | virtual void deactivateContext() {} 28 | }; 29 | 30 | private: 31 | // Implementation specific functions 32 | gl::ProcAddress getExtensionFunctionPointer(const char*) override; 33 | 34 | void activate() override; 35 | void deactivate() override; 36 | 37 | void createImpl(); 38 | 39 | private: 40 | std::unique_ptr impl; 41 | 42 | Size size; 43 | float pixelRatio; 44 | bool active = false; 45 | 46 | class View; 47 | std::unique_ptr view; 48 | }; 49 | 50 | } // namespace mbgl 51 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/online_file_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class ResourceTransform; 11 | 12 | class OnlineFileSource : public FileSource { 13 | public: 14 | OnlineFileSource(); 15 | ~OnlineFileSource() override; 16 | 17 | void setAPIBaseURL(const std::string& t) { apiBaseURL = t; } 18 | std::string getAPIBaseURL() const { return apiBaseURL; } 19 | 20 | void setAccessToken(const std::string& t) { accessToken = t; } 21 | std::string getAccessToken() const { return accessToken; } 22 | 23 | void setResourceTransform(optional>&&); 24 | 25 | std::unique_ptr request(const Resource&, Callback) override; 26 | 27 | void setMaximumConcurrentRequests(uint32_t); 28 | uint32_t getMaximumConcurrentRequests() const; 29 | 30 | // For testing only. 31 | void setOnlineStatus(bool); 32 | 33 | private: 34 | friend class OnlineFileRequest; 35 | 36 | class Impl; 37 | const std::unique_ptr impl; 38 | std::string accessToken; 39 | std::string apiBaseURL = mbgl::util::API_BASE_URL; 40 | }; 41 | 42 | } // namespace mbgl 43 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/exception.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | struct Exception : std::runtime_error { 9 | Exception(const char *msg) : std::runtime_error(msg) {} 10 | Exception(const std::string &msg) : std::runtime_error(msg) {} 11 | }; 12 | 13 | struct SpriteImageException : Exception { 14 | SpriteImageException(const char *msg) : Exception(msg) {} 15 | SpriteImageException(const std::string &msg) : Exception(msg) {} 16 | }; 17 | 18 | struct MisuseException : Exception { 19 | MisuseException(const char *msg) : Exception(msg) {} 20 | MisuseException(const std::string &msg) : Exception(msg) {} 21 | }; 22 | 23 | struct StyleParseException : Exception { 24 | StyleParseException(const char *msg) : Exception(msg) {} 25 | StyleParseException(const std::string &msg) : Exception(msg) {} 26 | }; 27 | 28 | struct StyleLoadException : Exception { 29 | StyleLoadException(const char *msg) : Exception(msg) {} 30 | StyleLoadException(const std::string &msg) : Exception(msg) {} 31 | }; 32 | 33 | struct NotFoundException : Exception { 34 | NotFoundException(const char *msg) : Exception(msg) {} 35 | NotFoundException(const std::string &msg) : Exception(msg) {} 36 | }; 37 | 38 | } // namespace util 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/camera_options_test.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | import ( 4 | "testing" 5 | "github.com/arolek/p" 6 | ) 7 | 8 | func TestCameraOptions(t *testing.T) { 9 | type coptions struct { 10 | center *LatLng 11 | padding *EdgeInsets 12 | anchor *Point 13 | zoom *float64 14 | angle *float64 15 | pitch *float64 16 | } 17 | 18 | type tcase struct { 19 | opts []coptions 20 | } 21 | 22 | fn := func (tc tcase, t *testing.T) { 23 | 24 | // this test will leak memory out of 25 | opts := &CameraOptions{} 26 | opts.update() 27 | for _, v:= range tc.opts { 28 | opts.Center = v.center 29 | opts.Padding = v.padding 30 | opts.Anchor = v.anchor 31 | opts.Zoom = v.zoom 32 | opts.Angle = v.angle 33 | opts.Pitch = v.pitch 34 | opts.update() 35 | } 36 | 37 | opts.Destruct() 38 | } 39 | 40 | testcases := map[string]tcase{ 41 | "1": { 42 | []coptions{ 43 | {}, 44 | }, 45 | }, 46 | "2": { 47 | []coptions{ 48 | {}, 49 | { 50 | center: NewLatLng(32, 117), 51 | padding: NewEdgeInsets(0, 0, 0, 0), 52 | anchor: &Point{X:0, Y:0}, 53 | zoom: p.Float64(12), 54 | angle: p.Float64(0), 55 | pitch: p.Float64(0), 56 | }, 57 | }, 58 | }, 59 | } 60 | 61 | for k, v := range testcases { 62 | t.Run(k, func(t *testing.T) { 63 | fn(v, t) 64 | }) 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /mbgl/lat_lng.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "lat_lng.h" 5 | */ 6 | import "C" 7 | import "github.com/go-spatial/geom/slippy" 8 | 9 | //TODO (@ear7h): use github.com/go-spatial/geom type 10 | type LatLng C.MbglLatLng 11 | 12 | func NewLatLng(lat, lng float64) *LatLng { 13 | ptr := C.mbgl_lat_lng_new(C.double(lat), C.double(lng)) 14 | 15 | return (*LatLng)(ptr) 16 | } 17 | 18 | func (ll *LatLng) latLng() *C.MbglLatLng { 19 | return (*C.MbglLatLng)(ll) 20 | } 21 | 22 | func (ll *LatLng) Destruct() { 23 | C.mbgl_lat_lng_destruct(ll.latLng()) 24 | } 25 | 26 | 27 | // bounds 28 | type LatLngBounds C.MbglLatLngBounds 29 | 30 | func NewLatLngBounds(a, b *LatLng) *LatLngBounds { 31 | ptr := C.mbgl_lat_lng_bounds_hull(a.latLng(), b.latLng()) 32 | return (*LatLngBounds)(ptr) 33 | } 34 | 35 | func NewLatLngBoundsFromTile(tile *slippy.Tile) *LatLngBounds { 36 | // east, north, west, south 37 | bound := tile.Extent4326() 38 | a := NewLatLng(bound[1], bound[0]) 39 | b := NewLatLng(bound[3], bound[2]) 40 | 41 | ret := NewLatLngBounds(a, b) 42 | 43 | a.Destruct() 44 | b.Destruct() 45 | 46 | return ret 47 | } 48 | 49 | func (bb *LatLngBounds) latLngBounds() *C.MbglLatLngBounds { 50 | return (*C.MbglLatLngBounds)(bb) 51 | } 52 | 53 | func (bb *LatLngBounds) Destruct() { 54 | C.mbgl_lat_lng_bounds_destruct(bb.latLngBounds()) 55 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-mbgl 2 | 3 | go-mbgl aims to provide Go bindings for [Mapbox GL native's C++ API.](https://github.com/mapbox/mapbox-gl-native) 4 | 5 | **WARNING**: This project is under heavly development, and is not production ready. 6 | 7 | **WARNING**: This will only work on Linux 8 | 9 | This repository depends on [*git-lfs*](https://git-lfs.github.com/) 10 | 11 | ## Repoistory Layout 12 | 13 | * [cmd/snap](cmd/snap) -- Holds the primary CLI (command line interface) tool. This tool servers both as a raster tile server, and static map generator. 14 | * [mbgl/simplifed](mbgl/simplifed) -- Go bindings for snapshot API. 15 | * [mbgl/c](mbgl/c) -- the C bridge for Go. (_Not working?_) 16 | * [mbgl/c/linux/lib](mbgl/c/linux/lib) -- location of the precompiled Linux libraries. 17 | 18 | 19 | ## Development Env 20 | 21 | Running the following commands should set up a working development environment 22 | 23 | ```console 24 | 25 | docker build -t mbgl . 26 | 27 | docker run --rm -v "$(pwd)":/go/src/github.com/go-spatial/go-mbgl -it mbgl 28 | 29 | ``` 30 | 31 | In the docker image if you need to rebuil the c archive files, you can use the `mbgl/c/install.sh` bash script 32 | to rebuild them. 33 | 34 | ## Build snap commandline utility. 35 | 36 | ```console 37 | 38 | cd cmd/snap 39 | 40 | go build 41 | 42 | ``` 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /mbgl/premultiplied_image.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "premultiplied_image.h" 5 | */ 6 | import "C" 7 | import ( 8 | "image" 9 | "image/color" 10 | "unsafe" 11 | ) 12 | 13 | type PremultipliedImage C.MbglPremultipliedImage 14 | 15 | func (im *PremultipliedImage) premultipliedImage() *C.MbglPremultipliedImage { 16 | return (*C.MbglPremultipliedImage)(im) 17 | } 18 | 19 | func (im *PremultipliedImage) Image() image.Image { 20 | raw := C.mbgl_premultiplied_image_raw(im.premultipliedImage()) 21 | 22 | bytes := int(raw.width) * int(raw.height) * 4 23 | 24 | return &img{ 25 | data: C.GoBytes(unsafe.Pointer(raw.data), C.int(bytes)), 26 | width: int(raw.width), 27 | height: int(raw.height), 28 | } 29 | } 30 | 31 | func (im *PremultipliedImage) Destruct() { 32 | C.mbgl_premultiplied_image_destruct(im.premultipliedImage()) 33 | } 34 | 35 | type img struct { 36 | data []byte 37 | width, height int 38 | } 39 | 40 | func (im img) ColorModel() color.Model { 41 | return color.RGBAModel 42 | } 43 | 44 | func (im img) Bounds() image.Rectangle { 45 | return image.Rect(0, 0, im.width, im.height) 46 | } 47 | 48 | func (im img) At(x, y int) color.Color { 49 | i := im.width * 4 * y 50 | i += 4 * x 51 | 52 | return color.RGBA{ 53 | im.data[i], 54 | im.data[i+1], 55 | im.data[i+2], 56 | im.data[i+3], 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/map/map_observer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class MapObserver { 12 | public: 13 | virtual ~MapObserver() = default; 14 | 15 | static MapObserver& nullObserver() { 16 | static MapObserver mapObserver; 17 | return mapObserver; 18 | } 19 | 20 | enum class CameraChangeMode : uint32_t { 21 | Immediate, 22 | Animated 23 | }; 24 | 25 | enum class RenderMode : uint32_t { 26 | Partial, 27 | Full 28 | }; 29 | 30 | virtual void onCameraWillChange(CameraChangeMode) {} 31 | virtual void onCameraIsChanging() {} 32 | virtual void onCameraDidChange(CameraChangeMode) {} 33 | virtual void onWillStartLoadingMap() {} 34 | virtual void onDidFinishLoadingMap() {} 35 | virtual void onDidFailLoadingMap(std::exception_ptr) {} 36 | virtual void onWillStartRenderingFrame() {} 37 | virtual void onDidFinishRenderingFrame(RenderMode) {} 38 | virtual void onWillStartRenderingMap() {} 39 | virtual void onDidFinishRenderingMap(RenderMode) {} 40 | virtual void onDidFinishLoadingStyle() {} 41 | virtual void onSourceChanged(style::Source&) {} 42 | virtual void onDidBecomeIdle() {} 43 | }; 44 | 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/include/mbgl/util/default_styles.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | namespace util { 8 | namespace default_styles { 9 | 10 | struct DefaultStyle { 11 | const char* url; 12 | const char* name; 13 | const unsigned currentVersion; 14 | }; 15 | 16 | constexpr const DefaultStyle streets = { "mapbox://styles/mapbox/streets-v11", "Streets", 11 }; 17 | constexpr const DefaultStyle outdoors = { "mapbox://styles/mapbox/outdoors-v11", "Outdoors", 11 }; 18 | constexpr const DefaultStyle light = { "mapbox://styles/mapbox/light-v10", "Light", 10 }; 19 | constexpr const DefaultStyle dark = { "mapbox://styles/mapbox/dark-v10", "Dark", 10 }; 20 | constexpr const DefaultStyle satellite = { "mapbox://styles/mapbox/satellite-v9", "Satellite", 9 }; 21 | constexpr const DefaultStyle satelliteStreets = { "mapbox://styles/mapbox/satellite-streets-v11", "Satellite Streets", 11 }; 22 | 23 | const DefaultStyle orderedStyles[] = { 24 | streets, outdoors, light, dark, satellite, satelliteStreets, 25 | }; 26 | const size_t numOrderedStyles = sizeof(orderedStyles) / sizeof(DefaultStyle); 27 | 28 | } // end namespace default_styles 29 | } // end namespace util 30 | } // end namespace mbgl 31 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/chrono.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | using Clock = std::chrono::steady_clock; 9 | 10 | using Seconds = std::chrono::seconds; 11 | using Milliseconds = std::chrono::milliseconds; 12 | 13 | using TimePoint = Clock::time_point; 14 | using Duration = Clock::duration; 15 | 16 | // Used to measure second-precision times, such as times gathered from HTTP responses. 17 | using Timestamp = std::chrono::time_point; 18 | 19 | namespace util { 20 | 21 | inline Timestamp now() { 22 | return std::chrono::time_point_cast(std::chrono::system_clock::now()); 23 | } 24 | 25 | // Returns the RFC1123 formatted date. E.g. "Tue, 04 Nov 2014 02:13:24 GMT" 26 | std::string rfc1123(Timestamp); 27 | 28 | // YYYY-mm-dd HH:MM:SS e.g. "2015-11-26 16:11:23" 29 | std::string iso8601(Timestamp); 30 | 31 | Timestamp parseTimestamp(const char *); 32 | 33 | Timestamp parseTimestamp(const int32_t timestamp); 34 | 35 | // C++17 polyfill 36 | template ::min() < std::chrono::duration::zero()>> 38 | constexpr std::chrono::duration abs(std::chrono::duration d) 39 | { 40 | return d >= d.zero() ? d : -d; 41 | } 42 | 43 | } // namespace util 44 | 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/case.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Case : public Expression { 15 | public: 16 | using Branch = std::pair, std::unique_ptr>; 17 | 18 | Case(type::Type type_, std::vector branches_, std::unique_ptr otherwise_) 19 | : Expression(Kind::Case, type_), branches(std::move(branches_)), otherwise(std::move(otherwise_)) { 20 | } 21 | 22 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 23 | 24 | EvaluationResult evaluate(const EvaluationContext& params) const override; 25 | void eachChild(const std::function& visit) const override; 26 | 27 | bool operator==(const Expression& e) const override; 28 | 29 | std::vector> possibleOutputs() const override; 30 | 31 | std::string getOperator() const override { return "case"; } 32 | private: 33 | std::vector branches; 34 | std::unique_ptr otherwise; 35 | }; 36 | 37 | } // namespace expression 38 | } // namespace style 39 | } // namespace mbgl 40 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/polygon.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // mapbox 4 | #include 5 | 6 | // stl 7 | #include 8 | 9 | namespace mapbox { 10 | namespace geometry { 11 | 12 | template class Cont = std::vector> 13 | struct linear_ring : Cont> 14 | { 15 | using coordinate_type = T; 16 | using point_type = point; 17 | using container_type = Cont; 18 | using size_type = typename container_type::size_type; 19 | 20 | template 21 | linear_ring(Args&&... args) : container_type(std::forward(args)...) 22 | { 23 | } 24 | linear_ring(std::initializer_list args) 25 | : container_type(std::move(args)) {} 26 | }; 27 | 28 | template class Cont = std::vector> 29 | struct polygon : Cont> 30 | { 31 | using coordinate_type = T; 32 | using linear_ring_type = linear_ring; 33 | using container_type = Cont; 34 | using size_type = typename container_type::size_type; 35 | 36 | template 37 | polygon(Args&&... args) : container_type(std::forward(args)...) 38 | { 39 | } 40 | polygon(std::initializer_list args) 41 | : container_type(std::move(args)) {} 42 | }; 43 | 44 | } // namespace geometry 45 | } // namespace mapbox 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/geojson_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace mbgl { 9 | 10 | class AsyncRequest; 11 | 12 | namespace style { 13 | 14 | struct GeoJSONOptions { 15 | // GeoJSON-VT options 16 | uint8_t minzoom = 0; 17 | uint8_t maxzoom = 18; 18 | uint16_t tileSize = util::tileSize; 19 | uint16_t buffer = 128; 20 | double tolerance = 0.375; 21 | bool lineMetrics = false; 22 | 23 | // Supercluster options 24 | bool cluster = false; 25 | uint16_t clusterRadius = 50; 26 | uint8_t clusterMaxZoom = 17; 27 | }; 28 | 29 | class GeoJSONSource : public Source { 30 | public: 31 | GeoJSONSource(const std::string& id, const GeoJSONOptions& = {}); 32 | ~GeoJSONSource() final; 33 | 34 | void setURL(const std::string& url); 35 | void setGeoJSON(const GeoJSON&); 36 | 37 | optional getURL() const; 38 | 39 | class Impl; 40 | const Impl& impl() const; 41 | 42 | void loadDescription(FileSource&) final; 43 | 44 | private: 45 | optional url; 46 | std::unique_ptr req; 47 | }; 48 | 49 | template <> 50 | inline bool Source::is() const { 51 | return getType() == SourceType::GeoJSON; 52 | } 53 | 54 | } // namespace style 55 | } // namespace mbgl 56 | -------------------------------------------------------------------------------- /mbgl/map.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "map.h" 7 | #include "size.h" 8 | #include "file_source.h" 9 | #include "scheduler.h" 10 | 11 | using namespace mbgl; 12 | 13 | MbglMap * mbgl_map_new (MbglRendererFrontend * frontend, 14 | MbglSize * size, 15 | float pixelRatio, 16 | MbglFileSource * src, 17 | MbglScheduler * sched) { 18 | 19 | auto _frontend = reinterpret_cast(frontend); 20 | auto _size = reinterpret_cast(size); 21 | auto _src = reinterpret_cast(src); 22 | auto _sched = reinterpret_cast(sched); 23 | 24 | auto ptr = new Map(*_frontend, MapObserver::nullObserver(), *_size, pixelRatio, *_src, *_sched, MapMode::Static); 25 | 26 | return reinterpret_cast(ptr); 27 | } 28 | 29 | void mbgl_map_destruct(MbglMap * self) { 30 | auto _self = reinterpret_cast(self); 31 | delete _self; 32 | } 33 | 34 | void mbgl_map_jump_to(MbglMap * self, MbglCameraOptions * opts) { 35 | auto _self = reinterpret_cast(self); 36 | auto _opts = reinterpret_cast(opts); 37 | 38 | _self->jumpTo(*_opts); 39 | } 40 | 41 | 42 | void mbgl_map_set_style_url(MbglMap * self, const char * addr) { 43 | auto _self = reinterpret_cast(self); 44 | auto _addr = std::string(addr); 45 | 46 | _self->getStyle().loadURL(_addr); 47 | } -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/storage/file_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | class FileSource : private util::noncopyable { 15 | public: 16 | virtual ~FileSource() = default; 17 | 18 | using Callback = std::function; 19 | 20 | // Request a resource. The callback will be called asynchronously, in the same 21 | // thread as the request was made. This thread must have an active RunLoop. The 22 | // request may be cancelled before completion by releasing the returned AsyncRequest. 23 | // If the request is cancelled before the callback is executed, the callback will 24 | // not be executed. 25 | virtual std::unique_ptr request(const Resource&, Callback) = 0; 26 | 27 | // When a file source supports consulting a local cache only, it must return true. 28 | // Cache-only requests are requests that aren't as urgent, but could be useful, e.g. 29 | // to cover part of the map while loading. The FileSource should only do cheap actions to 30 | // retrieve the data, e.g. load it from a cache, but not from the internet. 31 | virtual bool supportsCacheOnlyRequests() const { 32 | return false; 33 | } 34 | }; 35 | 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/actor/mailbox.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class Scheduler; 12 | class Message; 13 | 14 | class Mailbox : public std::enable_shared_from_this { 15 | public: 16 | 17 | // Create a "holding" mailbox, messages to which will remain queued, 18 | // unconsumed, until the mailbox is associated with a Scheduler using 19 | // start(). This allows a Mailbox object to be created on one thread and 20 | // later transferred to a different target thread that may not yet exist. 21 | Mailbox(); 22 | 23 | Mailbox(Scheduler&); 24 | 25 | // Attach the given scheduler to this mailbox and begin processing messages 26 | // sent to it. The mailbox must be a "holding" mailbox, as created by the 27 | // default constructor Mailbox(). 28 | void open(Scheduler& scheduler_); 29 | void close(); 30 | 31 | bool isOpen() const; 32 | 33 | void push(std::unique_ptr); 34 | void receive(); 35 | 36 | static void maybeReceive(std::weak_ptr); 37 | 38 | private: 39 | optional scheduler; 40 | 41 | std::recursive_mutex receivingMutex; 42 | std::mutex pushingMutex; 43 | 44 | bool closed { false }; 45 | 46 | std::mutex queueMutex; 47 | std::queue> queue; 48 | }; 49 | 50 | } // namespace mbgl 51 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/coalesce.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | namespace expression { 13 | 14 | class Coalesce : public Expression { 15 | public: 16 | using Args = std::vector>; 17 | Coalesce(const type::Type& type_, Args args_) : 18 | Expression(Kind::Coalesce, type_), 19 | args(std::move(args_)) 20 | {} 21 | 22 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 23 | 24 | 25 | EvaluationResult evaluate(const EvaluationContext& params) const override; 26 | 27 | void eachChild(const std::function& visit) const override; 28 | 29 | bool operator==(const Expression& e) const override; 30 | 31 | std::vector> possibleOutputs() const override; 32 | 33 | std::size_t getLength() const { 34 | return args.size(); 35 | } 36 | 37 | Expression* getChild(std::size_t i) const { 38 | return args.at(i).get(); 39 | } 40 | 41 | std::string getOperator() const override { return "coalesce"; } 42 | private: 43 | Args args; 44 | }; 45 | 46 | } // namespace expression 47 | } // namespace style 48 | } // namespace mbgl 49 | -------------------------------------------------------------------------------- /mbgl/c/include/mapbox/geometry/for_each_point.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mapbox { 6 | namespace geometry { 7 | 8 | template 9 | void for_each_point(mapbox::geometry::empty const&, F&&) 10 | { 11 | } 12 | 13 | template 14 | auto for_each_point(Point&& point, F&& f) 15 | -> decltype(point.x, point.y, void()) 16 | { 17 | f(std::forward(point)); 18 | } 19 | 20 | template 21 | auto for_each_point(Container&& container, F&& f) 22 | -> decltype(container.begin(), container.end(), void()); 23 | 24 | template 25 | void for_each_point(mapbox::util::variant const& geom, F&& f) 26 | { 27 | mapbox::util::variant::visit(geom, [&](auto const& g) { 28 | for_each_point(g, f); 29 | }); 30 | } 31 | 32 | template 33 | void for_each_point(mapbox::util::variant& geom, F&& f) 34 | { 35 | mapbox::util::variant::visit(geom, [&](auto& g) { 36 | for_each_point(g, f); 37 | }); 38 | } 39 | 40 | template 41 | auto for_each_point(Container&& container, F&& f) 42 | -> decltype(container.begin(), container.end(), void()) 43 | { 44 | for (auto& e : container) 45 | { 46 | for_each_point(e, f); 47 | } 48 | } 49 | 50 | } // namespace geometry 51 | } // namespace mapbox 52 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/renderer/renderer_state.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | class UpdateParameters; 9 | 10 | /** 11 | * RendererState acts as a Memento object that is able to extract data out of UpdateParameters (an opaque object 12 | * from the public API perspective). 13 | */ 14 | class RendererState { 15 | public: 16 | 17 | // Obtains a CameraOptions out of a given UpdateParameters object. 18 | static CameraOptions getCameraOptions(const UpdateParameters&, const EdgeInsets& = {}); 19 | 20 | // Returns whether an image with the given ID exists from a given UpdateParamters object. 21 | static bool hasImage(const UpdateParameters&, const std::string& id); 22 | 23 | // Returns whether a layer with the given ID exists from a given UpdateParamters object. 24 | static bool hasLayer(const UpdateParameters&, const std::string& id); 25 | 26 | // Returns whether a source with the given ID exists from a given UpdateParamters object. 27 | static bool hasSource(const UpdateParameters&, const std::string& id); 28 | 29 | // Obtains the geographical coordinate out of a given screen coordinate. 30 | static ScreenCoordinate pixelForLatLng(const UpdateParameters&, const LatLng&); 31 | 32 | // Obtains the screen coordinate out of a given geographical coordinate. 33 | static LatLng latLngForPixel(const UpdateParameters&, const ScreenCoordinate&); 34 | }; 35 | 36 | } // namespace mbgl 37 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/at.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace mbgl { 8 | namespace style { 9 | namespace expression { 10 | 11 | class At : public Expression { 12 | public: 13 | At(std::unique_ptr index_, std::unique_ptr input_) : 14 | Expression(Kind::At, input_->getType().get().itemType), 15 | index(std::move(index_)), 16 | input(std::move(input_)) 17 | {} 18 | 19 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 20 | 21 | EvaluationResult evaluate(const EvaluationContext& params) const override; 22 | void eachChild(const std::function&) const override; 23 | 24 | bool operator==(const Expression& e) const override { 25 | if (e.getKind() == Kind::At) { 26 | auto rhs = static_cast(&e); 27 | return *index == *(rhs->index) && *input == *(rhs->input); 28 | } 29 | return false; 30 | } 31 | 32 | std::vector> possibleOutputs() const override { 33 | return { nullopt }; 34 | } 35 | 36 | std::string getOperator() const override { return "at"; } 37 | 38 | private: 39 | std::unique_ptr index; 40 | std::unique_ptr input; 41 | }; 42 | 43 | } // namespace expression 44 | } // namespace style 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/headless_frontend.go: -------------------------------------------------------------------------------- 1 | package mbgl 2 | 3 | /* 4 | #include "headless_frontend.h" 5 | */ 6 | import "C" 7 | 8 | import ( 9 | "fmt" 10 | "os" 11 | ) 12 | 13 | type HeadlessFrontend C.MbglHeadlessFrontend 14 | 15 | func NewHeadlessFrontend(size *Size, pixelRatio float32, src FileSource, sched Scheduler, cacheDir *string, fontFamily *string) *HeadlessFrontend { 16 | 17 | var _cacheDir *C.char 18 | if cacheDir != nil { 19 | _cacheDir = C.CString(*cacheDir) 20 | } 21 | 22 | var _fontFamily *C.char 23 | if fontFamily != nil { 24 | _fontFamily = C.CString(*fontFamily) 25 | } 26 | fmt.Fprintf(os.Stderr, "Starting to startup mbgl_headless_frontend_new\n") 27 | 28 | ptr := C.mbgl_headless_frontend_new( 29 | size.cSize(), 30 | C.float(pixelRatio), 31 | src.fileSource(), 32 | sched.scheduler(), 33 | _cacheDir, 34 | _fontFamily) 35 | fmt.Fprintf(os.Stderr, "After call to mbgl_headless_frontend_new") 36 | 37 | return (*HeadlessFrontend)(ptr) 38 | } 39 | 40 | func (hfe *HeadlessFrontend) rendererFrontend() *C.MbglRendererFrontend { 41 | return (*C.MbglRendererFrontend)(hfe) 42 | } 43 | 44 | func (hfe *HeadlessFrontend) Render(m *Map) *PremultipliedImage { 45 | fmt.Fprintf(os.Stderr, "Before the Render") 46 | ptr := C.mbgl_headless_frontend_render( 47 | (*C.MbglHeadlessFrontend)(hfe), 48 | (*C.MbglMap)(m)) 49 | fmt.Fprintf(os.Stderr, "After the Render") 50 | 51 | return (*PremultipliedImage)(ptr) 52 | } 53 | 54 | func (hfe *HeadlessFrontend) Destruct() { 55 | C.mbgl_headless_frontend_destruct((*C.MbglHeadlessFrontend)(hfe)) 56 | } 57 | -------------------------------------------------------------------------------- /mbgl/simplified/simplified_linux.go: -------------------------------------------------------------------------------- 1 | package simplified 2 | 3 | /* 4 | #cgo CXXFLAGS: -I${SRCDIR}/../c/include 5 | #cgo CXXFLAGS: -I${SRCDIR}/../c/include/include 6 | #cgo LDFLAGS: -L${SRCDIR}/../c/lib/linux 7 | 8 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libmbgl-core.a 9 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libmbgl-filesource.a 10 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libmbgl-loop-uv.a 11 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libsqlite.a 12 | 13 | #cgo LDFLAGS: -Wl,--no-as-needed -lcurl 14 | #cgo LDFLAGS: -Wl,--as-needed ${SRCDIR}/../c/lib/linux/libmbgl-core.a 15 | #cgo LDFLAGS: -lOSMesa 16 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libpng.a 17 | #cgo LDFLAGS: -lz -lm 18 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libjpeg.a 19 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libnunicode.a 20 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libicu.a 21 | #cgo LDFLAGS: ${SRCDIR}/../c/lib/linux/libuv.a 22 | #cgo LDFLAGS: -lrt -lpthread 23 | #cgo LDFLAGS: -lnsl -ldl 24 | #cgo LDFLAGS: -static-libstdc++ 25 | 26 | */ 27 | import "C" 28 | 29 | // @cgo CXXFLAGS: -I${SRCDIR}/../mason_packages/.link/include 30 | // @cgo CXXFLAGS: -I${SRCDIR}/../mapbox-gl-native/vendor/expected/include 31 | // @cgo CXXFLAGS: -I${SRCDIR}/../mapbox-gl-native/include 32 | // @cgo CXXFLAGS: -I${SRCDIR}/../mapbox-gl-native/platform/default 33 | // @cgo LDFLAGS: -L${SRCDIR}/../mason_packages/.link/lib 34 | // @cgo LDFLAGS: -lsqlite3 -lz 35 | // @cgo LDFLAGS: -lmbgl-filesource -lmbgl-core 36 | // #cgo CXXFLAGS: -I${SRCDIR}/c/mapbox-gl-native/include 37 | // #cgo LDFLAGS: -Wl,-Bsymbolic-functions ${SRCDIR}/../c/lib/linux/libuv.a 38 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/match.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | template 14 | class Match : public Expression { 15 | public: 16 | using Branches = std::unordered_map>; 17 | 18 | Match(type::Type type_, 19 | std::unique_ptr input_, 20 | Branches branches_, 21 | std::unique_ptr otherwise_ 22 | ) : Expression(Kind::Match, type_), 23 | input(std::move(input_)), 24 | branches(std::move(branches_)), 25 | otherwise(std::move(otherwise_)) 26 | {} 27 | 28 | EvaluationResult evaluate(const EvaluationContext& params) const override; 29 | 30 | void eachChild(const std::function& visit) const override; 31 | 32 | bool operator==(const Expression& e) const override; 33 | 34 | std::vector> possibleOutputs() const override; 35 | 36 | mbgl::Value serialize() const override; 37 | std::string getOperator() const override { return "match"; } 38 | private: 39 | std::unique_ptr input; 40 | Branches branches; 41 | std::unique_ptr otherwise; 42 | }; 43 | 44 | ParseResult parseMatch(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 45 | 46 | } // namespace expression 47 | } // namespace style 48 | } // namespace mbgl 49 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/step.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | namespace style { 14 | namespace expression { 15 | 16 | class Step : public Expression { 17 | public: 18 | Step(const type::Type& type_, 19 | std::unique_ptr input_, 20 | std::map> stops_); 21 | 22 | EvaluationResult evaluate(const EvaluationContext& params) const override; 23 | void eachChild(const std::function& visit) const override; 24 | void eachStop(const std::function& visit) const; 25 | 26 | const std::unique_ptr& getInput() const { return input; } 27 | Range getCoveringStops(const double lower, const double upper) const; 28 | 29 | bool operator==(const Expression& e) const override; 30 | 31 | std::vector> possibleOutputs() const override; 32 | 33 | static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); 34 | 35 | mbgl::Value serialize() const override; 36 | std::string getOperator() const override { return "step"; } 37 | 38 | private: 39 | const std::unique_ptr input; 40 | const std::map> stops; 41 | }; 42 | 43 | } // namespace expression 44 | } // namespace style 45 | } // namespace mbgl 46 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/filter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | namespace style { 14 | 15 | class Filter { 16 | public: 17 | optional> expression; 18 | private: 19 | optional legacyFilter; 20 | public: 21 | Filter() : expression() {} 22 | 23 | Filter(expression::ParseResult _expression, optional _filter = {}) 24 | : expression(std::move(*_expression)), 25 | legacyFilter(std::move(_filter)){ 26 | assert(!expression || *expression != nullptr); 27 | } 28 | 29 | bool operator()(const expression::EvaluationContext& context) const; 30 | 31 | friend bool operator==(const Filter& lhs, const Filter& rhs) { 32 | if (!lhs.expression || !rhs.expression) { 33 | return lhs.expression == rhs.expression; 34 | } else { 35 | return *(lhs.expression) == *(rhs.expression); 36 | } 37 | } 38 | 39 | friend bool operator!=(const Filter& lhs, const Filter& rhs) { 40 | return !(lhs == rhs); 41 | } 42 | 43 | mbgl::Value serialize() const { 44 | if (legacyFilter) { 45 | return *legacyFilter; 46 | } 47 | else if (expression) { 48 | return (**expression).serialize(); 49 | } 50 | return NullValue(); 51 | } 52 | }; 53 | 54 | } // namespace style 55 | } // namespace mbgl 56 | -------------------------------------------------------------------------------- /mbgl/README_build.md: -------------------------------------------------------------------------------- 1 | # go-mbgl 2 | go bindings for mapbox gl native's c++ api 3 | 4 | ## Development 5 | 6 | ### Dev Deps 7 | **Darwin**: 8 | see inssructions [on the mblg page](https://github.com/mapbox/mapbox-gl-native/blob/master/platform/macos/INSTALL.md), but do not build the library. 9 | In list form: 10 | * xcode 11 | * node 12 | * cmake 13 | * ccache 14 | * xcpretty 15 | * jazzy 16 | 17 | **Linux**: 18 | todo 19 | 20 | ### install 21 | run the install script provided in the repo. Note, it'll install a node package, [`mason-js`](https://github.com/mapbox/mason-js) globally with `npm i -g`. 22 | ```bash 23 | ./install.sh 24 | ``` 25 | 26 | ### build/tests 27 | regular go tool commands (`go build`, `go test`) can be used for building the library. 28 | 29 | ### Old install instructions (deprecated) 30 | 31 | 1. Download and build [Mapbox-GL-Native](https://github.com/mapbox/mapbox-gl-native) for your platform. 32 | 33 | 2. Add the absolute or relative path to the `include` and `platform/default` to the CGO_CXXFLAGS variable in the makefile as `-I` flags 34 | 35 | 3. Make library binaries accessible to linker 36 | * For `darwin` this requires copying a `.framework` file into `/Libray/Frameworks` and `.a` files into `./mason_packages/.link/lib` 37 | * For `linux` this can be done by copying `.a` files into `./mason_packages/.link/lib` 38 | 39 | 4. Install [mason-js](https://github.com/mapbox/mason-js) and run `mason-js install` and then `mason-js link` in the atto root directory to download the required dependencies 40 | 41 | 5. `go build` to build... 42 | 43 | There is a Dockerfile in /docker which details the steps required to set up a build and runtime environment for go-mbgl. 44 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/literal.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class Literal : public Expression { 14 | public: 15 | Literal(Value value_) 16 | : Expression(Kind::Literal, typeOf(value_)) 17 | , value(value_) 18 | {} 19 | 20 | Literal(type::Array type_, std::vector value_) 21 | : Expression(Kind::Literal, type_) 22 | , value(value_) 23 | {} 24 | 25 | EvaluationResult evaluate(const EvaluationContext&) const override { 26 | return value; 27 | } 28 | 29 | static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); 30 | 31 | void eachChild(const std::function&) const override {} 32 | 33 | bool operator==(const Expression& e) const override { 34 | if (e.getKind() == Kind::Literal) { 35 | auto rhs = static_cast(&e); 36 | return value == rhs->value; 37 | } 38 | return false; 39 | } 40 | 41 | std::vector> possibleOutputs() const override { 42 | return {{ value }}; 43 | } 44 | 45 | Value getValue() const { 46 | return value; 47 | } 48 | 49 | mbgl::Value serialize() const override; 50 | std::string getOperator() const override { return "literal"; } 51 | 52 | private: 53 | Value value; 54 | }; 55 | 56 | } // namespace expression 57 | } // namespace style 58 | } // namespace mbgl 59 | -------------------------------------------------------------------------------- /mbgl/README.md: -------------------------------------------------------------------------------- 1 | # mbgl 2 | 3 | This directory contains direct go bindings against the Mapbox GL Native C++ API. 4 | 5 | ## Design overview 6 | 7 | * follow the C++ api as closely as possible, not idiomatic Go 8 | * keeping in mind Go can only interface with C defintions 9 | * manual memory management through `(T).Destruct()` methods 10 | * C++ types are aliased in C as empty structs 11 | * they are named `MbglTypeName` 12 | * [WIP] C++ classes are aliased in Go as the C type 13 | * ie. `type TypeName C.TypeName` 14 | * C++ classes will always be passed around as pointers to C aliases and `reinterpret_cast<>`ed 15 | * [WIP] C++ structs are represented in Go as normal structs with Go memebers 16 | * ie. `type TypeName struct{ field1 *TypeNameX, field2 *TypeNameY }` 17 | * they must be accesse through a `(TypeName).cPtr() *C.MbglTypeName` method which updates the values of a C++ instance of the struct with the current values of the Go struct 18 | * this keeps us from having to write a getter and setter for every struct 19 | * Memory management is the responsibility of the programmer, through use of `(TypeName).Destruct()` methods which will call `delete` on the object 20 | 21 | ## Using the bindings 22 | 23 | * in the higher level package, `runtime.SetFinalizer` is used for memory management, note that this cannot be done for classes (which are aliased as empty structs) as: 24 | 25 | > It is not guaranteed that a finalizer will run if the size of *obj is zero bytes. 26 | > https://golang.org/pkg/runtime/#SetFinalizer 27 | 28 | * after calling `(T).Destruct()` make sure to not reuse the variable, this will result in strange errors; another `(T).Destruct()` call might yeild something like "freed block must be allocated with malloc". -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/sources/custom_geometry_source.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | class OverscaledTileID; 12 | class CanonicalTileID; 13 | template 14 | class Actor; 15 | 16 | namespace style { 17 | 18 | using TileFunction = std::function; 19 | 20 | class CustomTileLoader; 21 | 22 | class CustomGeometrySource : public Source { 23 | public: 24 | struct TileOptions { 25 | double tolerance = 0.375; 26 | uint16_t tileSize = util::tileSize; 27 | uint16_t buffer = 128; 28 | bool clip = false; 29 | bool wrap = false; 30 | }; 31 | 32 | struct Options { 33 | TileFunction fetchTileFunction; 34 | TileFunction cancelTileFunction; 35 | Range zoomRange = { 0, 18}; 36 | TileOptions tileOptions; 37 | }; 38 | public: 39 | CustomGeometrySource(std::string id, CustomGeometrySource::Options options); 40 | ~CustomGeometrySource() final; 41 | void loadDescription(FileSource&) final; 42 | void setTileData(const CanonicalTileID&, const GeoJSON&); 43 | void invalidateTile(const CanonicalTileID&); 44 | void invalidateRegion(const LatLngBounds&); 45 | // Private implementation 46 | class Impl; 47 | const Impl& impl() const; 48 | private: 49 | std::unique_ptr> loader; 50 | }; 51 | 52 | template <> 53 | inline bool Source::is() const { 54 | return getType() == SourceType::CustomVector; 55 | } 56 | 57 | } // namespace style 58 | } // namespace mbgl 59 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/light.hpp: -------------------------------------------------------------------------------- 1 | // This file is generated. Do not edit. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace mbgl { 11 | namespace style { 12 | 13 | class LightObserver; 14 | 15 | class Light { 16 | public: 17 | Light(); 18 | ~Light(); 19 | 20 | static LightAnchorType getDefaultAnchor(); 21 | PropertyValue getAnchor() const; 22 | void setAnchor(PropertyValue); 23 | void setAnchorTransition(const TransitionOptions&); 24 | TransitionOptions getAnchorTransition() const; 25 | 26 | static Position getDefaultPosition(); 27 | PropertyValue getPosition() const; 28 | void setPosition(PropertyValue); 29 | void setPositionTransition(const TransitionOptions&); 30 | TransitionOptions getPositionTransition() const; 31 | 32 | static Color getDefaultColor(); 33 | PropertyValue getColor() const; 34 | void setColor(PropertyValue); 35 | void setColorTransition(const TransitionOptions&); 36 | TransitionOptions getColorTransition() const; 37 | 38 | static float getDefaultIntensity(); 39 | PropertyValue getIntensity() const; 40 | void setIntensity(PropertyValue); 41 | void setIntensityTransition(const TransitionOptions&); 42 | TransitionOptions getIntensityTransition() const; 43 | 44 | class Impl; 45 | Immutable impl; 46 | Mutable mutableImpl() const; 47 | 48 | LightObserver* observer = nullptr; 49 | void setObserver(LightObserver*); 50 | }; 51 | 52 | } // namespace style 53 | } // namespace mbgl 54 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/conversion/constant.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace mbgl { 14 | namespace style { 15 | namespace conversion { 16 | 17 | template <> 18 | struct Converter { 19 | optional operator()(const Convertible& value, Error& error) const; 20 | }; 21 | 22 | template <> 23 | struct Converter { 24 | optional operator()(const Convertible& value, Error& error) const; 25 | }; 26 | 27 | template <> 28 | struct Converter { 29 | optional operator()(const Convertible& value, Error& error) const; 30 | }; 31 | 32 | template 33 | struct Converter::value>> { 34 | optional operator()(const Convertible& value, Error& error) const; 35 | }; 36 | 37 | template <> 38 | struct Converter { 39 | optional operator()(const Convertible& value, Error& error) const; 40 | }; 41 | 42 | template 43 | struct Converter> { 44 | optional> operator()(const Convertible& value, Error& error) const; 45 | }; 46 | 47 | template <> 48 | struct Converter> { 49 | optional> operator()(const Convertible& value, Error& error) const; 50 | }; 51 | 52 | template <> 53 | struct Converter> { 54 | optional> operator()(const Convertible& value, Error& error) const; 55 | }; 56 | 57 | } // namespace conversion 58 | } // namespace style 59 | } // namespace mbgl 60 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/formatted.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace mbgl { 12 | namespace style { 13 | namespace expression { 14 | 15 | struct FormattedSection { 16 | FormattedSection(std::string text_, optional fontScale_, optional fontStack_) 17 | : text(std::move(text_)) 18 | , fontScale(std::move(fontScale_)) 19 | , fontStack(std::move(fontStack_)) 20 | {} 21 | std::string text; 22 | optional fontScale; 23 | optional fontStack; 24 | }; 25 | 26 | class Formatted { 27 | public: 28 | Formatted() = default; 29 | 30 | Formatted(const char* plainU8String) { 31 | sections.emplace_back(std::string(plainU8String), nullopt, nullopt); 32 | } 33 | 34 | Formatted(std::vector sections_) 35 | : sections(std::move(sections_)) 36 | {} 37 | 38 | bool operator==(const Formatted& ) const; 39 | 40 | std::string toString() const; 41 | 42 | bool empty() const { 43 | return sections.empty() || sections.at(0).text.empty(); 44 | } 45 | 46 | std::vector sections; 47 | }; 48 | 49 | } // namespace expression 50 | 51 | namespace conversion { 52 | 53 | template <> 54 | struct Converter { 55 | public: 56 | optional operator()(const Convertible& value, Error& error) const; 57 | }; 58 | 59 | } // namespace conversion 60 | 61 | } // namespace style 62 | } // namespace mbgl 63 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/enum.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mbgl { 10 | 11 | template 12 | class Enum { 13 | public: 14 | using Type = T; 15 | static const char * toString(T); 16 | static optional toEnum(const std::string&); 17 | }; 18 | 19 | #define MBGL_DEFINE_ENUM(T, values...) \ 20 | \ 21 | static const constexpr std::pair T##_names[] = values; \ 22 | \ 23 | template <> \ 24 | const char * Enum::toString(T t) { \ 25 | auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ 26 | [&] (const auto& v) { return t == v.first; }); \ 27 | assert(it != std::end(T##_names)); return it->second; \ 28 | } \ 29 | \ 30 | template <> \ 31 | optional Enum::toEnum(const std::string& s) { \ 32 | auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ 33 | [&] (const auto& v) { return s == v.second; }); \ 34 | return it == std::end(T##_names) ? optional() : it->first; \ 35 | } 36 | 37 | } // namespace mbgl 38 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/tileset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace mbgl { 13 | 14 | class Tileset { 15 | public: 16 | enum class Scheme : bool { XYZ, TMS }; 17 | enum class DEMEncoding : bool { Mapbox, Terrarium }; 18 | 19 | std::vector tiles; 20 | Range zoomRange; 21 | std::string attribution; 22 | Scheme scheme; 23 | // DEMEncoding is not supported by the TileJSON spec 24 | DEMEncoding encoding; 25 | optional bounds; 26 | 27 | 28 | Tileset(std::vector tiles_ = std::vector(), 29 | Range zoomRange_ = { 0, util::DEFAULT_MAX_ZOOM }, 30 | std::string attribution_ = {}, 31 | Scheme scheme_ = Scheme::XYZ, 32 | DEMEncoding encoding_ = DEMEncoding::Mapbox) 33 | : tiles(std::move(tiles_)), 34 | zoomRange(std::move(zoomRange_)), 35 | attribution(std::move(attribution_)), 36 | scheme(scheme_), 37 | encoding(encoding_), 38 | bounds() {}; 39 | 40 | // TileJSON also includes center and zoom but they are not used by mbgl. 41 | 42 | friend bool operator==(const Tileset& lhs, const Tileset& rhs) { 43 | return std::tie(lhs.tiles, lhs.zoomRange, lhs.attribution, lhs.scheme, lhs.bounds) 44 | == std::tie(rhs.tiles, rhs.zoomRange, rhs.attribution, rhs.scheme, rhs.bounds); 45 | } 46 | 47 | friend bool operator!=(const Tileset& lhs, const Tileset& rhs) { 48 | return !(lhs == rhs); 49 | } 50 | }; 51 | 52 | } // namespace mbgl 53 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/char_array_buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mbgl { 6 | namespace util { 7 | 8 | // ref https://artofcode.wordpress.com/2010/12/12/deriving-from-stdstreambuf/ 9 | 10 | class CharArrayBuffer : public std::streambuf 11 | { 12 | public: 13 | CharArrayBuffer(char const* data, std::size_t size) 14 | : begin_(data), end_(data + size), current_(data) {} 15 | 16 | private: 17 | int_type underflow() final { 18 | if (current_ == end_) { 19 | return traits_type::eof(); 20 | } 21 | return traits_type::to_int_type(*current_); 22 | } 23 | 24 | int_type uflow() final { 25 | if (current_ == end_) { 26 | return traits_type::eof(); 27 | } 28 | return traits_type::to_int_type(*current_++); 29 | } 30 | 31 | int_type pbackfail(int_type ch) final { 32 | if (current_ == begin_ || (ch != traits_type::eof() && ch != current_[-1])) { 33 | return traits_type::eof(); 34 | } 35 | return traits_type::to_int_type(*--current_); 36 | } 37 | 38 | std::streamsize showmanyc() final { 39 | return end_ - current_; 40 | } 41 | 42 | pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode) final { 43 | if (dir == std::ios_base::beg) current_ = std::min(begin_ + off, end_); 44 | else if (dir == std::ios_base::cur) current_ = std::min(current_ + off, end_); 45 | else current_ = std::max(end_ - off, begin_); // dir == std::ios_base::end 46 | return pos_type(off_type(current_ - begin_)); 47 | } 48 | 49 | char const * const begin_; 50 | char const * const end_; 51 | char const * current_; 52 | }; 53 | 54 | } // namespace util 55 | } // namespace mbgl 56 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/style/expression/collator_expression.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace mbgl { 10 | namespace style { 11 | namespace expression { 12 | 13 | class CollatorExpression : public Expression { 14 | public: 15 | CollatorExpression(std::unique_ptr caseSensitive, 16 | std::unique_ptr diacriticSensitive, 17 | optional> locale); 18 | 19 | EvaluationResult evaluate(const EvaluationContext&) const override; 20 | static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); 21 | 22 | void eachChild(const std::function&) const override; 23 | 24 | bool operator==(const Expression& e) const override; 25 | 26 | std::vector> possibleOutputs() const override { 27 | // Technically the set of possible outputs is the combinatoric set of Collators produced 28 | // by all possibleOutputs of locale/caseSensitive/diacriticSensitive 29 | // But for the primary use of Collators in comparison operators, we ignore the Collator's 30 | // possibleOutputs anyway, so we can get away with leaving this undefined for now. 31 | return { nullopt }; 32 | } 33 | 34 | mbgl::Value serialize() const override; 35 | std::string getOperator() const override { return "collator"; } 36 | private: 37 | std::unique_ptr caseSensitive; 38 | std::unique_ptr diacriticSensitive; 39 | optional> locale; 40 | }; 41 | 42 | } // namespace expression 43 | } // namespace style 44 | } // namespace mbgl 45 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | RUN apt-get update; \ 4 | apt-get install software-properties-common; \ 5 | add-apt-repository --yes ppa:ubuntu-toolchain-r/test; \ 6 | apt-get update; 7 | 8 | 9 | # Go 10 | RUN apt-get install -y golang-1.10 git build-essential; \ 11 | ln -s /usr/lib/go-1.10/bin/go /bin/go; \ 12 | ln -s /usr/lib/go-1.10/bin/gofmt /bin/gofmt 13 | 14 | # gcc 15 | 16 | RUN apt-get install -y gcc g++ 17 | # 18 | RUN apt-get install -y curl zlib1g-dev automake \ 19 | libtool xutils-dev make pkg-config python-pip \ 20 | libcurl4-openssl-dev \ 21 | libllvm3.9 \ 22 | git-lfs;\ 23 | apt-get update; 24 | 25 | # 26 | RUN apt-get update 27 | RUN apt-get install -y cmake cmake-data 28 | RUN apt-get install -y ccache 29 | RUN apt-get install -y libglu1-mesa-dev 30 | RUN apt-get install -y libosmesa6-dev libsqlite3-dev 31 | RUN apt-get update 32 | 33 | # 34 | #RUN apt-get install -y libxi-dev libglu1-mesa-dev x11proto-randr-dev \ 35 | # x11proto-xext-dev libxrandr-dev \ 36 | # x11proto-xf86vidmode-dev libxxf86vm-dev \ 37 | # libxcursor-dev libxinerama-dev 38 | # 39 | # 40 | 41 | RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - 42 | RUN apt-get install -y nodejs 43 | 44 | # Tools for Development 45 | RUN apt-get install -y neovim tree 46 | 47 | ENV GOPATH=/go 48 | RUN go get \ 49 | github.com/arolek/p \ 50 | github.com/go-spatial/geom \ 51 | github.com/dimfeld/httptreemux \ 52 | github.com/disintegration/imaging \ 53 | github.com/spf13/cobra 54 | 55 | #RUN go get -d github.com/go-spatial/go-mbgl 56 | 57 | 58 | #RUN mkdir -p /go/src/github.com/go-spatial/go-mbgl 59 | #WORKDIR /go/src/github.com/go-spatial/go-mbgl 60 | 61 | ENTRYPOINT bash 62 | -------------------------------------------------------------------------------- /mbgl/c/include/mbgl/util/type_list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace mbgl { 7 | 8 | template 9 | struct TypeList { 10 | template