├── basemap.gif ├── geojson.gif ├── splitmap.gif ├── velocity.gif ├── docs ├── source │ ├── _static │ │ └── main_stylesheet.css │ ├── releasing.rst │ ├── api_reference │ │ ├── fullscreen_control.rst │ │ ├── layers_control.rst │ │ ├── marker_cluster.rst │ │ ├── image_video_overlay.rst │ │ ├── split_map_control.rst │ │ ├── polygon.rst │ │ ├── rectangle.rst │ │ ├── geo_json.rst │ │ ├── draw_control.rst │ │ ├── circle.rst │ │ ├── circle_marker.rst │ │ ├── widget_control.rst │ │ ├── heatmap.rst │ │ ├── icon.rst │ │ ├── velocity.rst │ │ ├── tile_layer.rst │ │ ├── layer_group.rst │ │ ├── measure_control.rst │ │ ├── marker.rst │ │ ├── wms_layer.rst │ │ ├── popup.rst │ │ └── embed_widgets │ │ │ ├── fullscreen_control.html │ │ │ └── wms_layer.html │ ├── conf.py │ ├── installation.rst │ ├── conda.svg │ ├── index.rst │ ├── embed_widgets │ │ └── index_example.ipynb │ ├── binder-logo.svg │ └── usage.rst ├── environment.yml └── Doxyfile ├── notebooks ├── images │ └── xleaflet.png ├── WMSLayer.ipynb ├── Video.ipynb ├── MeasureControl.ipynb ├── SplitMap.ipynb ├── Velocity.ipynb ├── FullScreenControl.ipynb ├── LayersControl.ipynb ├── GeoJSON.ipynb ├── Geometry.ipynb ├── Popup.ipynb ├── LayerGroup.ipynb └── Heatmap.ipynb ├── environment.yml ├── src ├── xmap.cpp ├── xicon.cpp ├── xpath.cpp ├── xlayer.cpp ├── xpopup.cpp ├── xcircle.cpp ├── xcontrol.cpp ├── xmarker.cpp ├── xheatmap.cpp ├── xpolygon.cpp ├── xgeo_json.cpp ├── xpolyline.cpp ├── xui_layer.cpp ├── xvelocity.cpp ├── xrectangle.cpp ├── xwms_layer.cpp ├── xtile_layer.cpp ├── xlayer_group.cpp ├── xraster_layer.cpp ├── xdraw_control.cpp ├── xvector_layer.cpp ├── xzoom_control.cpp ├── xcircle_marker.cpp ├── xfeature_group.cpp ├── ximage_overlay.cpp ├── xvideo_overlay.cpp ├── xlayers_control.cpp ├── xmarker_cluster.cpp ├── xwidget_control.cpp ├── xmeasure_control.cpp ├── xsplit_map_control.cpp └── xfullscreen_control.cpp ├── readthedocs.yml ├── environment-dev.yml ├── include └── xleaflet │ ├── xleaflet_config_cling.hpp.in │ ├── xget_basemaps_path.hpp.in │ ├── xleaflet_config.hpp │ ├── xfeature_group.hpp │ ├── xlayers_control.hpp │ ├── xfullscreen_control.hpp │ ├── xui_layer.hpp │ ├── xpolygon.hpp │ ├── xvector_layer.hpp │ ├── xrectangle.hpp │ ├── xcircle_marker.hpp │ ├── xmarker_cluster.hpp │ ├── xbasemaps.hpp │ ├── xcircle.hpp │ ├── xraster_layer.hpp │ ├── xcontrol.hpp │ ├── xsplit_map_control.hpp │ ├── xpolyline.hpp │ ├── ximage_overlay.hpp │ ├── xvideo_overlay.hpp │ ├── xzoom_control.hpp │ ├── xlayer.hpp │ └── xwidget_control.hpp ├── test ├── test_xmap.cpp ├── main.cpp ├── CMakeLists.txt └── check_attributes.hpp ├── .gitignore ├── xleafletConfig.cmake.in ├── LICENSE ├── .github └── workflows │ └── main.yml └── README.md /basemap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jupyter-xeus/xleaflet/HEAD/basemap.gif -------------------------------------------------------------------------------- /geojson.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jupyter-xeus/xleaflet/HEAD/geojson.gif -------------------------------------------------------------------------------- /splitmap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jupyter-xeus/xleaflet/HEAD/splitmap.gif -------------------------------------------------------------------------------- /velocity.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jupyter-xeus/xleaflet/HEAD/velocity.gif -------------------------------------------------------------------------------- /docs/source/_static/main_stylesheet.css: -------------------------------------------------------------------------------- 1 | .wy-nav-content{ 2 | max-width: 1000px; 3 | margin: auto; 4 | } 5 | -------------------------------------------------------------------------------- /notebooks/images/xleaflet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jupyter-xeus/xleaflet/HEAD/notebooks/images/xleaflet.png -------------------------------------------------------------------------------- /docs/environment.yml: -------------------------------------------------------------------------------- 1 | name: xleaflet-docs 2 | 3 | channels: 4 | - conda-forge 5 | 6 | dependencies: 7 | - breathe 8 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: xleaflet 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - xtensor=0.23 6 | - xleaflet=0.16.0 7 | - xeus-cling=0.13.0 8 | - ipyleaflet>=0.14.0,<0.15 9 | - widgetsnbextension >=3.0.0 10 | -------------------------------------------------------------------------------- /src/xmap.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xmap.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xicon.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xicon.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xpath.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xpath.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xlayer.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xlayer.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xpopup.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xpopup.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xcircle.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xcircle.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xcontrol.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xcontrol.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; -------------------------------------------------------------------------------- /src/xmarker.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xmarker.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xheatmap.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xheatmap.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xpolygon.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xpolygon.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xgeo_json.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xgeo_json.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xpolyline.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xpolyline.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xui_layer.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xui_layer.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xvelocity.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xvelocity.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xrectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xrectangle.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xwms_layer.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xwms_layer.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xtile_layer.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xtile_layer.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: "ubuntu-22.04" 5 | tools: 6 | python: "mambaforge-22.9" 7 | 8 | sphinx: 9 | # Path to Sphinx configuration file 10 | configuration: docs/source/conf.py 11 | 12 | conda: 13 | environment: docs/environment.yml 14 | -------------------------------------------------------------------------------- /src/xlayer_group.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xlayer_group.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xraster_layer.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xraster_layer.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; -------------------------------------------------------------------------------- /src/xdraw_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xdraw_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xvector_layer.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xvector_layer.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xzoom_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xzoom_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xcircle_marker.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xcircle_marker.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xfeature_group.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xfeature_group.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/ximage_overlay.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/ximage_overlay.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xvideo_overlay.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xvideo_overlay.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xlayers_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xlayers_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xmarker_cluster.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xmarker_cluster.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xwidget_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xwidget_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xmeasure_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xmeasure_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xsplit_map_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xsplit_map_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /src/xfullscreen_control.cpp: -------------------------------------------------------------------------------- 1 | #include "xleaflet/xfullscreen_control.hpp" 2 | 3 | template class XLEAFLET_API xw::xmaterialize; 4 | template xw::xmaterialize::xmaterialize(); 5 | template class XLEAFLET_API xw::xtransport>; 6 | -------------------------------------------------------------------------------- /docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "xleaflet" 2 | XML_OUTPUT = xml 3 | INPUT = ../include 4 | GENERATE_LATEX = NO 5 | GENERATE_MAN = NO 6 | GENERATE_RTF = NO 7 | CASE_SENSE_NAMES = NO 8 | GENERATE_HTML = NO 9 | GENERATE_XML = YES 10 | RECURSIVE = YES 11 | QUIET = YES 12 | JAVADOC_AUTOBRIEF = YES 13 | WARN_IF_UNDOCUMENTED = NO 14 | -------------------------------------------------------------------------------- /environment-dev.yml: -------------------------------------------------------------------------------- 1 | name: xleaflet 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | # Build dependencies 6 | - cmake 7 | - cxx-compiler 8 | - ninja 9 | # Host dependencies 10 | - cppzmq 11 | - xproperty 12 | - xwidgets>=0.29.2 13 | - xtensor>=0.27,<0.28 14 | # Test dependencies 15 | - doctest 16 | - pybind11=2.7.1 17 | - pybind11_json=0.2.11 18 | - ipyleaflet=0.14.0 19 | 20 | -------------------------------------------------------------------------------- /include/xleaflet/xleaflet_config_cling.hpp.in: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | *******************************************************************************/ 8 | 9 | #ifndef XLEAFLET_CONFIG_CLING_HPP 10 | #define XLEAFLET_CONFIG_CLING_HPP 11 | 12 | #pragma cling add_library_path(@XLEAFLET_INSTALL_LIBRARY_DIR@) 13 | #pragma cling load("libxleaflet") 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /test/test_xmap.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille and Sylvain Corlay * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #include 10 | #include "xleaflet/xmap.hpp" 11 | 12 | namespace xleaflet 13 | { 14 | TEST_SUITE("xmap") 15 | { 16 | TEST_CASE("map") 17 | { 18 | int res = 64; 19 | CHECK_EQ(64, res); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # Vim tmp files 31 | *.swp 32 | 33 | # Build directory 34 | build/ 35 | 36 | # Test build artefacts 37 | test/test_xwidgets 38 | test/CMakeCache.txt 39 | test/Makefile 40 | test/CMakeFiles/ 41 | test/cmake_install.cmake 42 | 43 | # Documentation build artefacts 44 | docs/CMakeCache.txt 45 | docs/xml/ 46 | docs/build/ 47 | 48 | # Jupyter artefacts 49 | .ipynb_checkpoints/ 50 | 51 | # Generated files 52 | *.pc 53 | 54 | # Generated header 55 | include/xleaflet/xleaflet_config_cling.hpp 56 | include/xleaflet/xget_basemaps_path.hpp 57 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (c) 2016, Johan Mabille and Sylvain Corlay * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | ****************************************************************************/ 8 | 9 | #define DOCTEST_CONFIG_IMPLEMENT 10 | #include 11 | 12 | #include 13 | namespace py = pybind11; 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | py::scoped_interpreter guard{}; 18 | doctest::Context context; 19 | context.applyCommandLine(argc, argv); 20 | int res = context.run(); 21 | return res; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /include/xleaflet/xget_basemaps_path.hpp.in: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_GET_BASEMAPS_PATH_HPP 11 | #define XLEAFLET_GET_BASEMAPS_PATH_HPP 12 | 13 | #include 14 | 15 | namespace xlf 16 | { 17 | inline std::string get_basemaps_path() 18 | { 19 | static std::string basemaps_path = @XLEAFLET_BASEMAPS_PATH@; 20 | return basemaps_path; 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /docs/source/releasing.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille and Sylvain Corlay, and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Releasing xleaflet 8 | ================== 9 | 10 | Releasing a new version 11 | ----------------------- 12 | 13 | From the master branch of xleaflet 14 | 15 | - Make sure that you are in sync with the master branch of the upstream remote. 16 | - In file ``xleaflet_config.hpp``, set the macros for ``XLEAFLET_VERSION_MAJOR``, ``XLEAFLET_VERSION_MINOR`` and ``XLEAFLET_VERSION_PATCH`` to the desired values. 17 | - Update the readme file w.r.t. dependencies on xleaflet 18 | - Stage the changes (``git add``), commit the changes (``git commit``) and add a tag of the form ``Major.minor.patch``. It is important to not add any other content to the tag name. 19 | - Push the new commit and tag to the main repository. (``git push``, and ``git push --tags``) 20 | - Release the new version on conda 21 | - Update the stable branch to point to the new tag 22 | -------------------------------------------------------------------------------- /docs/source/api_reference/fullscreen_control.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | 8 | .. raw:: html 9 | :file: embed_widgets/fullscreen_control.html 10 | 11 | 12 | Fullscreen Control 13 | ================== 14 | 15 | The ``fullscreen_control`` allows one to display a selector on the top left of the map in order to display the map in fullscreen. 16 | 17 | .. code:: 18 | 19 | #include "xleaflet/xmap.hpp" 20 | #include "xleaflet/xfullscreen_control.hpp" 21 | 22 | auto map = xlf::map::initialize() 23 | .center({51.64, -76.52}) 24 | .zoom(5) 25 | .finalize(); 26 | 27 | map.add_control(xlf::fullscreen_control()); 28 | 29 | map 30 | 31 | .. raw:: html 32 | 33 | 40 |
41 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import subprocess 6 | 7 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True' 8 | 9 | if on_rtd: 10 | subprocess.call('cd ..; doxygen', shell=True) 11 | 12 | import sphinx_rtd_theme 13 | 14 | html_theme = "sphinx_rtd_theme" 15 | 16 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] 17 | 18 | 19 | def setup(app): 20 | app.add_javascript("https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js") 21 | app.add_javascript("https://unpkg.com/@jupyter-widgets/html-manager@*/dist/embed-amd.js") 22 | 23 | app.add_stylesheet("main_stylesheet.css") 24 | 25 | extensions = ['breathe'] 26 | breathe_projects = { 'xleaflet': '../xml' } 27 | templates_path = ['_templates'] 28 | html_static_path = ['_static'] 29 | source_suffix = '.rst' 30 | master_doc = 'index' 31 | project = 'xleaflet' 32 | copyright = '2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou' 33 | author = 'Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou' 34 | 35 | html_logo = 'quantstack-white.svg' 36 | 37 | exclude_patterns = [] 38 | highlight_language = 'c++' 39 | pygments_style = 'sphinx' 40 | todo_include_todos = False 41 | htmlhelp_basename = 'xleafletdoc' 42 | -------------------------------------------------------------------------------- /xleafletConfig.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2018, Sylvain Corlay, Johan Mabille, and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | # xwidgets cmake module 10 | # This module sets the following variables in your project:: 11 | # 12 | # xleaflet_FOUND - true if xleaflet found on the system 13 | # xleaflet_INCLUDE_DIRS - the directory containing xleaflet headers 14 | # xleaflet_LIBRARY - empty 15 | 16 | @PACKAGE_INIT@ 17 | 18 | @XLEAFLET_CONFIG_CODE@ 19 | 20 | include(CMakeFindDependencyMacro) 21 | find_dependency(xproperty @xproperty_REQUIRED_VERSION@) 22 | find_dependency(xwidgets @xwidgets_REQUIRED_VERSION@) 23 | 24 | if (NOT TARGET xleaflet) 25 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 26 | 27 | if (TARGET xleaflet) 28 | get_target_property(@PROJECT_NAME@_INCLUDE_DIR xleaflet INTERFACE_INCLUDE_DIRECTORIES) 29 | get_target_property(@PROJECT_NAME@_LIBRARY xleaflet LOCATION) 30 | endif () 31 | endif () 32 | 33 | -------------------------------------------------------------------------------- /docs/source/installation.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille and Sylvain Corlay, and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | 8 | .. raw:: html 9 | 10 | 20 | 21 | Installation 22 | ============ 23 | 24 | .. image:: conda.svg 25 | 26 | Using the conda-forge package 27 | ----------------------------- 28 | 29 | A package for xleaflet is available on the mamba package manager. 30 | The package will also pull all the dependencies. 31 | 32 | .. code:: 33 | 34 | mamba install xleaflet -c conda-forge 35 | 36 | .. image:: cmake.svg 37 | 38 | From source with cmake 39 | ---------------------- 40 | 41 | You can also install ``xleaflet`` from source with cmake. On Unix platforms, from the source directory: 42 | However, you need to make sure to have the required libraries available on your machine. 43 | 44 | .. code:: 45 | 46 | mkdir build 47 | cd build 48 | cmake -DCMAKE_INSTALL_PREFIX=/path/to/prefix .. 49 | make install 50 | 51 | On Windows platforms, from the source directory: 52 | 53 | .. code:: 54 | 55 | mkdir build 56 | cd build 57 | cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=/path/to/prefix .. 58 | nmake 59 | nmake install 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Sylvain Corlay, Johan Mabille, and Wolf Vollprecht 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the copyright holder nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /docs/source/api_reference/layers_control.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/layers_control.html 9 | 10 | Layers Control 11 | ============== 12 | 13 | The ``layers_control`` allows one to display a selector on the top right of the map in order to select which tile layer to display on the map. 14 | 15 | .. code:: 16 | 17 | #include "xleaflet/xmap.hpp" 18 | #include "xleaflet/xbasemaps.hpp" 19 | #include "xleaflet/xtile_layer.hpp" 20 | #include "xleaflet/xwms_layer.hpp" 21 | #include "xleaflet/xlayers_control.hpp" 22 | 23 | auto map = xlf::map::initialize() 24 | .center({50, 354}) 25 | .zoom(4) 26 | .finalize(); 27 | 28 | auto nasa_layer = xlf::basemap({"NASAGIBS", "ModisTerraTrueColorCR"}, "2018-03-30"); 29 | map.add_layer(nasa_layer); 30 | 31 | auto wms = xlf::wms_layer::initialize() 32 | .url("https://demo.boundlessgeo.com/geoserver/ows?") 33 | .layers("nasa:bluemarble") 34 | .name("nasa:bluemarble") 35 | .finalize(); 36 | map.add_layer(wms); 37 | 38 | map.add_control(xlf::layers_control()); 39 | 40 | map 41 | 42 | .. raw:: html 43 | 44 | 51 | -------------------------------------------------------------------------------- /docs/source/api_reference/marker_cluster.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Marker Cluster 8 | ============== 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xbasemaps.hpp" 17 | #include "xleaflet/xmarker.hpp" 18 | #include "xleaflet/xmarker_cluster.hpp" 19 | 20 | auto map = xlf::map::initialize() 21 | .center({50, 354}) 22 | .zoom(5) 23 | .finalize(); 24 | 25 | auto marker1 = xlf::marker::initialize() 26 | .location({50, 354}) 27 | .finalize(); 28 | auto marker2 = xlf::marker::initialize() 29 | .location({52, 356}) 30 | .finalize(); 31 | auto marker3 = xlf::marker::initialize() 32 | .location({48, 352}) 33 | .finalize(); 34 | 35 | auto marker_cluster = xlf::marker_cluster::initialize() 36 | .markers({marker1, marker2, marker3}) 37 | .finalize(); 38 | 39 | map.add_layer(marker_cluster); 40 | 41 | map 42 | 43 | Attributes 44 | ---------- 45 | 46 | ===================== ======================================== ================ === 47 | Attribute Type Default Value Doc 48 | ===================== ======================================== ================ === 49 | markers ``std::vector`` {} Array of markers 50 | ===================== ======================================== ================ === 51 | -------------------------------------------------------------------------------- /notebooks/WMSLayer.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

WMS Layer

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xwms_layer.hpp\"" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "auto wms = xlf::wms_layer::initialize()\n", 41 | " .url(\"https://demo.boundlessgeo.com/geoserver/ows?\")\n", 42 | " .layers(\"nasa:bluemarble\")\n", 43 | " .finalize();\n", 44 | "\n", 45 | "auto map = xlf::map::initialize()\n", 46 | " .layers({wms})\n", 47 | " .center({42.5531, -48.6914})\n", 48 | " .zoom(3)\n", 49 | " .finalize();\n", 50 | "\n", 51 | "map" 52 | ] 53 | } 54 | ], 55 | "metadata": { 56 | "kernelspec": { 57 | "display_name": "C++14", 58 | "language": "C++14", 59 | "name": "xcpp14" 60 | }, 61 | "language_info": { 62 | "codemirror_mode": "text/x-c++src", 63 | "file_extension": ".cpp", 64 | "mimetype": "text/x-c++src", 65 | "name": "c++", 66 | "version": "14" 67 | } 68 | }, 69 | "nbformat": 4, 70 | "nbformat_minor": 4 71 | } 72 | -------------------------------------------------------------------------------- /docs/source/conda.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /notebooks/Video.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Video Overlay

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xvideo_overlay.hpp\"" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "auto map = xlf::map::initialize()\n", 41 | " .center({25, -115})\n", 42 | " .zoom(4)\n", 43 | " .finalize();\n", 44 | "\n", 45 | "auto video = xlf::video_overlay::initialize()\n", 46 | " .url(\"https://www.mapbox.com/bites/00188/patricia_nasa.webm\")\n", 47 | " .bounds({{{13, -130}, {32, -100}}})\n", 48 | " .finalize();\n", 49 | "\n", 50 | "map.add_layer(video);\n", 51 | "map" 52 | ] 53 | } 54 | ], 55 | "metadata": { 56 | "kernelspec": { 57 | "display_name": "C++14", 58 | "language": "C++14", 59 | "name": "xcpp14" 60 | }, 61 | "language_info": { 62 | "codemirror_mode": "text/x-c++src", 63 | "file_extension": ".cpp", 64 | "mimetype": "text/x-c++src", 65 | "name": "c++", 66 | "version": "14" 67 | } 68 | }, 69 | "nbformat": 4, 70 | "nbformat_minor": 4 71 | } 72 | -------------------------------------------------------------------------------- /docs/source/api_reference/image_video_overlay.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/image_video_overlay.html 9 | 10 | Image overlay and Video overlay 11 | =============================== 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xleaflet/xmap.hpp" 19 | #include "xleaflet/xvideo_overlay.hpp" 20 | 21 | auto map = xlf::map::initialize() 22 | .center({25, -115}) 23 | .zoom(4) 24 | .finalize(); 25 | 26 | auto video = xlf::video_overlay::initialize() 27 | .url("https://www.mapbox.com/bites/00188/patricia_nasa.webm") 28 | .bounds({{{13, -130}, {32, -100}}}) 29 | .finalize(); 30 | 31 | map.add_layer(video); 32 | map 33 | 34 | .. raw:: html 35 | 36 | 43 | 44 | Attributes 45 | ---------- 46 | 47 | ===================== ========================================= ======================== === 48 | Attribute Type Default Value Doc 49 | ===================== ========================================= ======================== === 50 | url ``std::string`` "" Url to the footage 51 | bounds ``std::array, 2>`` {{0.0, 0.0}, {0.0, 0.0}} SW and NE corners of the image 52 | ===================== ========================================= ======================== === 53 | -------------------------------------------------------------------------------- /docs/source/api_reference/split_map_control.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/split_map_control.html 9 | 10 | Split Map Control 11 | ================= 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xleaflet/xmap.hpp" 19 | #include "xleaflet/xbasemaps.hpp" 20 | #include "xleaflet/xsplit_map_control.hpp" 21 | 22 | auto map = xlf::map::initialize() 23 | .center({42.6824, 365.581}) 24 | .zoom(5) 25 | .finalize(); 26 | 27 | auto right_layer = xlf::basemap({"NASAGIBS", "ModisTerraTrueColorCR"}, "2017-11-11"); 28 | auto left_layer = xlf::basemap({"NASAGIBS", "ModisAquaBands721CR"}, "2017-11-11"); 29 | 30 | auto control = xlf::split_map_control::initialize() 31 | .left_layer(left_layer) 32 | .right_layer(right_layer) 33 | .finalize(); 34 | map.add_control(control); 35 | 36 | map 37 | 38 | .. raw:: html 39 | 40 | 47 | 48 | Attributes 49 | ---------- 50 | 51 | ===================== ======================================== ================ === 52 | Attribute Type Default Value Doc 53 | ===================== ======================================== ================ === 54 | left_layer ``xlf::layer`` Left layer 55 | right_layer ``xlf::layer`` Right layer 56 | ===================== ======================================== ================ === 57 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2018, Sylvain Corlay, Johan Mabille, and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 3.8) 10 | 11 | find_package(pybind11 REQUIRED) 12 | 13 | message(STATUS "Forcing tests build type to Release") 14 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 15 | 16 | if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 17 | project(xleaflet-test) 18 | 19 | find_package(xleaflet REQUIRED CONFIG) 20 | set(XWIDGETS_INCLUDE_DIR ${xwidgets_INCLUDE_DIRS}) 21 | set(XLEAFLET_INCLUDE_DIR ${xleaflet_INCLUDE_DIRS}) 22 | endif () 23 | 24 | # Dependencies 25 | # ============ 26 | 27 | find_package(doctest) 28 | find_package(Threads) 29 | 30 | # Source files 31 | # ============ 32 | 33 | include_directories(${XLEAFLET_INCLUDE_DIR}) 34 | 35 | set(XLEAFLET_TESTS 36 | main.cpp 37 | test_xleaflet.cpp 38 | ) 39 | 40 | # Output 41 | # ====== 42 | 43 | add_executable(test_xleaflet ${XLEAFLET_TESTS} ${XLEAFLET_HEADERS}) 44 | include_directories(${pybind11_INCLUDE_DIRS}) 45 | target_compile_features(test_xleaflet PRIVATE cxx_std_20) 46 | 47 | target_link_libraries(test_xleaflet 48 | PUBLIC xeus 49 | PUBLIC xwidgets 50 | PUBLIC xleaflet 51 | PRIVATE doctest::doctest 52 | PRIVATE ${CMAKE_THREAD_LIBS_INIT} 53 | PRIVATE ${PYTHON_LIBRARIES} pybind11::embed ) 54 | target_include_directories(test_xleaflet PRIVATE ${XLEAFLET_INCLUDE_DIR} ${XWIDGETS_INCLUDE_DIR}) 55 | -------------------------------------------------------------------------------- /notebooks/MeasureControl.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Draw control

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \n", 31 | "#include \n", 32 | "\n", 33 | "#include \"xleaflet/xmap.hpp\"\n", 34 | "#include \"xleaflet/xmeasure_control.hpp\"\n", 35 | "#include \"xleaflet/xbasemaps.hpp\"" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "auto water_color = xlf::basemap({\"Stamen\", \"Watercolor\"});\n", 45 | "\n", 46 | "auto map = xlf::map::initialize()\n", 47 | " .layers({water_color})\n", 48 | " .center({50, 354})\n", 49 | " .zoom(5)\n", 50 | " .finalize();\n", 51 | "\n", 52 | "map" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "## Create the `measure_control` with the options" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "auto measure_control = xlf::measure_control::initialize()\n", 69 | " .finalize();\n", 70 | "\n", 71 | "map.add_control(measure_control);" 72 | ] 73 | } 74 | ], 75 | "metadata": { 76 | "kernelspec": { 77 | "display_name": "C++14", 78 | "language": "C++14", 79 | "name": "xcpp14" 80 | }, 81 | "language_info": { 82 | "codemirror_mode": "text/x-c++src", 83 | "file_extension": ".cpp", 84 | "mimetype": "text/x-c++src", 85 | "name": "c++", 86 | "version": "-std=c++14" 87 | } 88 | }, 89 | "nbformat": 4, 90 | "nbformat_minor": 4 91 | } 92 | -------------------------------------------------------------------------------- /docs/source/api_reference/polygon.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Polygon 8 | ======= 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xpolygon.hpp" 17 | 18 | auto polygon = xlf::polygon::initialize() 19 | .locations({{{42, -49}, {43, -49}, {43, -48}}}) 20 | .color("green") 21 | .fill_color("green") 22 | .finalize(); 23 | 24 | auto map = xlf::map::initialize() 25 | .center({42.5531, -48.6914}) 26 | .zoom(6) 27 | .finalize(); 28 | map.add_layer(polygon); 29 | 30 | map 31 | 32 | Attributes 33 | ---------- 34 | 35 | ===================== ====================================== ================ === 36 | Attribute Type Default Value Doc 37 | ===================== ====================================== ================ === 38 | locations ``std::vector>`` {} List of points of the polygon 39 | stroke ``bool`` true Set it to `false` to disable borders 40 | color ``std::string`` "#0033FF" Color of the stroke 41 | opacity ``float`` 1.0 Opacity of the stroke 42 | weight ``int`` 5 Width of the stroke in pixels 43 | fill ``bool`` true Whether to fill the polygon or not 44 | fill_color ``std::string`` "#0033FF" 45 | fill_opacity ``float`` 0.2 46 | dash_array ``std::string`` 47 | line_cap ``std::string`` "round" 48 | line_join ``std::string`` "round" 49 | ===================== ====================================== ================ === 50 | -------------------------------------------------------------------------------- /notebooks/SplitMap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Split Map Control

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xbasemaps.hpp\"\n", 32 | "#include \"xleaflet/xsplit_map_control.hpp\"" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "auto map = xlf::map::initialize()\n", 42 | " .center({42.6824, 365.581})\n", 43 | " .zoom(5)\n", 44 | " .finalize();\n", 45 | "\n", 46 | "map" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "auto right_layer = xlf::basemap({\"NASAGIBS\", \"ModisTerraTrueColorCR\"}, \"2017-11-11\");\n", 56 | "auto left_layer = xlf::basemap({\"NASAGIBS\", \"ModisAquaBands721CR\"}, \"2017-11-11\");" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "auto control = xlf::split_map_control::initialize()\n", 66 | " .left_layer(left_layer)\n", 67 | " .right_layer(right_layer)\n", 68 | " .finalize();\n", 69 | "map.add_control(control)" 70 | ] 71 | } 72 | ], 73 | "metadata": { 74 | "kernelspec": { 75 | "display_name": "C++14", 76 | "language": "C++14", 77 | "name": "xcpp14" 78 | }, 79 | "language_info": { 80 | "codemirror_mode": "text/x-c++src", 81 | "file_extension": ".cpp", 82 | "mimetype": "text/x-c++src", 83 | "name": "c++", 84 | "version": "-std=c++14" 85 | } 86 | }, 87 | "nbformat": 4, 88 | "nbformat_minor": 4 89 | } 90 | -------------------------------------------------------------------------------- /include/xleaflet/xleaflet_config.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | *******************************************************************************/ 8 | 9 | #ifndef XLEAFLET_CONFIG_HPP 10 | #define XLEAFLET_CONFIG_HPP 11 | 12 | #include 13 | 14 | // Visual C++ declspec macros 15 | #ifdef _WIN32 16 | #ifdef XLEAFLET_EXPORTS 17 | #define XLEAFLET_API __declspec(dllexport) 18 | #else 19 | #define XLEAFLET_API __declspec(dllimport) 20 | #endif 21 | #else 22 | #define XLEAFLET_API 23 | #endif 24 | 25 | // Project version 26 | #define XLEAFLET_VERSION_MAJOR 0 27 | #define XLEAFLET_VERSION_MINOR 20 28 | #define XLEAFLET_VERSION_PATCH 0 29 | 30 | // Binary version 31 | #define XLEAFLET_BINARY_CURRENT 3 32 | #define XLEAFLET_BINARY_REVISION 1 33 | #define XLEAFLET_BINARY_AGE 0 34 | 35 | // Semver requirement for jupyter-leaflet 36 | #define XJUPYTER_LEAFLET_VERSION_MAJOR 0 37 | #define XJUPYTER_LEAFLET_VERSION_MINOR 14 38 | #define XJUPYTER_LEAFLET_VERSION_PATCH 0 39 | 40 | // Composing the version strings from major, minor and patch 41 | #define XLEAFLET_CONCATENATE(A, B) XLEAFLET_CONCATENATE_IMPL(A, B) 42 | #define XLEAFLET_CONCATENATE_IMPL(A, B) A##B 43 | #define XLEAFLET_STRINGIFY(a) XLEAFLET_STRINGIFY_IMPL(a) 44 | #define XLEAFLET_STRINGIFY_IMPL(a) #a 45 | 46 | #define XJUPYTER_LEAFLET_VERSION XLEAFLET_STRINGIFY(XLEAFLET_CONCATENATE(XJUPYTER_LEAFLET_VERSION_MAJOR, \ 47 | XLEAFLET_CONCATENATE(.,XLEAFLET_CONCATENATE(XJUPYTER_LEAFLET_VERSION_MINOR, \ 48 | XLEAFLET_CONCATENATE(.,XJUPYTER_LEAFLET_VERSION_PATCH))))) 49 | 50 | inline std::string jupyter_leaflet_semver() 51 | { 52 | return std::string("^") + XJUPYTER_LEAFLET_VERSION; 53 | } 54 | 55 | #ifdef __CLING__ 56 | #include "xleaflet_config_cling.hpp" 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /include/xleaflet/xfeature_group.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_FEATURE_GROUP_HPP 11 | #define XLEAFLET_FEATURE_GROUP_HPP 12 | 13 | #include "xwidgets/xmaterialize.hpp" 14 | #include "xwidgets/xwidget.hpp" 15 | 16 | #include "xlayer_group.hpp" 17 | #include "xleaflet_config.hpp" 18 | 19 | namespace xlf 20 | { 21 | /***************************** 22 | * feature_group declaration * 23 | *****************************/ 24 | 25 | template 26 | class xfeature_group : public xlayer_group 27 | { 28 | public: 29 | 30 | using base_type = xlayer_group; 31 | using derived_type = D; 32 | 33 | protected: 34 | 35 | xfeature_group(); 36 | using base_type::base_type; 37 | 38 | private: 39 | 40 | void set_defaults(); 41 | }; 42 | 43 | using feature_group = xw::xmaterialize; 44 | 45 | /********************************* 46 | * xfeature_group implementation * 47 | *********************************/ 48 | 49 | template 50 | inline xfeature_group::xfeature_group() 51 | : base_type() 52 | { 53 | set_defaults(); 54 | } 55 | 56 | template 57 | inline void xfeature_group::set_defaults() 58 | { 59 | this->_model_name() = "LeafletFeatureGroupModel"; 60 | this->_view_name() = "LeafletFeatureGroupView"; 61 | } 62 | } 63 | 64 | /********************* 65 | * precompiled types * 66 | *********************/ 67 | 68 | extern template class xw::xmaterialize; 69 | extern template class xw::xtransport>; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/xleaflet/xlayers_control.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_LAYERS_CONTROL_HPP 11 | #define XLEAFLET_LAYERS_CONTROL_HPP 12 | 13 | #include "xwidgets/xmaterialize.hpp" 14 | #include "xwidgets/xwidget.hpp" 15 | 16 | #include "xcontrol.hpp" 17 | #include "xleaflet_config.hpp" 18 | 19 | namespace xlf 20 | { 21 | /****************************** 22 | * layers_control declaration * 23 | ******************************/ 24 | 25 | template 26 | class xlayers_control : public xcontrol 27 | { 28 | public: 29 | 30 | using base_type = xcontrol; 31 | using derived_type = D; 32 | 33 | protected: 34 | 35 | xlayers_control(); 36 | using base_type::base_type; 37 | 38 | private: 39 | 40 | void set_defaults(); 41 | }; 42 | 43 | using layers_control = xw::xmaterialize; 44 | 45 | /********************************** 46 | * xlayers_control implementation * 47 | **********************************/ 48 | 49 | template 50 | inline xlayers_control::xlayers_control() 51 | : base_type() 52 | { 53 | set_defaults(); 54 | } 55 | 56 | template 57 | inline void xlayers_control::set_defaults() 58 | { 59 | this->_model_name() = "LeafletLayersControlModel"; 60 | this->_view_name() = "LeafletLayersControlView"; 61 | } 62 | 63 | } 64 | 65 | /********************* 66 | * precompiled types * 67 | *********************/ 68 | 69 | extern template class xw::xmaterialize; 70 | extern template class xw::xtransport>; 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /docs/source/api_reference/rectangle.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Rectangle 8 | ========= 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xbasemaps.hpp" 17 | #include "xleaflet/xrectangle.hpp" 18 | 19 | auto terrain = xlf::basemap({"Stamen", "Watercolor"}); 20 | 21 | auto map = xlf::map::initialize() 22 | .layers({terrain}) 23 | .center({53, 354}) 24 | .zoom(5) 25 | .finalize(); 26 | 27 | auto rectangle = xlf::rectangle::initialize() 28 | .bounds({{{52, 354}, {53, 360}}}) 29 | .finalize(); 30 | 31 | map.add_layer(rectangle); 32 | 33 | map 34 | 35 | Attributes 36 | ---------- 37 | 38 | ===================== ======================================== ================ === 39 | Attribute Type Default Value Doc 40 | ===================== ======================================== ================ === 41 | bounds ``std::array, 2>`` {} SW and NE corners of the rectangle 42 | stroke ``bool`` true Set it to `false` to disable borders 43 | color ``std::string`` "#0033FF" Color of the stroke 44 | opacity ``float`` 1.0 Opacity of the stroke 45 | weight ``int`` 5 Width of the stroke in pixels 46 | fill ``bool`` true Whether to fill the polygon or not 47 | fill_color ``std::string`` "#0033FF" 48 | fill_opacity ``float`` 0.2 49 | dash_array ``std::string`` 50 | line_cap ``std::string`` "round" 51 | line_join ``std::string`` "round" 52 | ===================== ======================================== ================ === 53 | -------------------------------------------------------------------------------- /include/xleaflet/xfullscreen_control.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_FULLSCREEN_CONTROL_HPP 11 | #define XLEAFLET_FULLSCREEN_CONTROL_HPP 12 | 13 | #include "xwidgets/xmaterialize.hpp" 14 | #include "xwidgets/xwidget.hpp" 15 | 16 | #include "xcontrol.hpp" 17 | #include "xleaflet_config.hpp" 18 | 19 | namespace xlf 20 | { 21 | /****************************** 22 | * fullscreen_control declaration * 23 | ******************************/ 24 | 25 | template 26 | class xfullscreen_control : public xcontrol 27 | { 28 | public: 29 | 30 | using base_type = xcontrol; 31 | using derived_type = D; 32 | 33 | protected: 34 | 35 | xfullscreen_control(); 36 | using base_type::base_type; 37 | 38 | private: 39 | 40 | void set_defaults(); 41 | }; 42 | 43 | using fullscreen_control = xw::xmaterialize; 44 | 45 | /********************************** 46 | * xfullscreen_control implementation * 47 | **********************************/ 48 | 49 | template 50 | inline xfullscreen_control::xfullscreen_control() 51 | : base_type() 52 | { 53 | set_defaults(); 54 | } 55 | 56 | template 57 | inline void xfullscreen_control::set_defaults() 58 | { 59 | this->_model_name() = "LeafletFullScreenControlModel"; 60 | this->_view_name() = "LeafletFullScreenControlView"; 61 | } 62 | } 63 | 64 | /********************* 65 | * precompiled types * 66 | *********************/ 67 | 68 | extern template class xw::xmaterialize; 69 | extern template class xw::xtransport>; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /test/check_attributes.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEST_PYTHON_ATTRIBUTES_HPP 2 | #define TEST_PYTHON_ATTRIBUTES_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "pybind11_json/pybind11_json.hpp" 10 | 11 | namespace py = pybind11; 12 | namespace nl = nlohmann; 13 | 14 | std::vector compare_attributes(const std::set& python_attributes, 15 | const std::set& cpp_attributes) 16 | { 17 | std::cout << std::endl << "Attributes present in Python not in C++: " << std::endl; 18 | 19 | std::vector difference; 20 | std::set_difference(begin(python_attributes), end(python_attributes), 21 | begin(cpp_attributes), end(cpp_attributes), 22 | std::back_inserter(difference)); 23 | std::vector::iterator it = difference.begin(); 24 | while(it != difference.end()) 25 | { 26 | std::cout << *it++ << std::endl; 27 | } 28 | std::cout << std::endl; 29 | return difference; 30 | } 31 | 32 | std::set extract_attributes_names(const nl::json& widget_representation) 33 | { 34 | std::set attribute_names; 35 | for(const auto& el: widget_representation.items()) 36 | { 37 | attribute_names.insert(el.key()); 38 | } 39 | return attribute_names; 40 | } 41 | 42 | template 43 | void check_attributes(const std::string& python_module_name, const std::string& python_class_name) 44 | { 45 | std::cout << python_module_name << '.' << python_class_name << std::endl; 46 | 47 | // Get Python widget state as nl::json 48 | auto python_module = py::module::import(python_module_name.c_str()); 49 | nl::json python_state = python_module.attr(python_class_name.c_str())().attr("get_state")(); 50 | 51 | // Get C++ widget state as nl::json 52 | nl::json cpp_state; 53 | xeus::buffer_sequence cpp_buffers; 54 | 55 | WT widget; 56 | widget.serialize_state(cpp_state, cpp_buffers); 57 | 58 | // Check for missing attributes 59 | std::set python_attribute_names = extract_attributes_names(python_state); 60 | std::set cpp_attribute_names = extract_attributes_names(cpp_state); 61 | std::vector leaflet_difference = compare_attributes(python_attribute_names, cpp_attribute_names); 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | defaults: 12 | run: 13 | shell: bash -l {0} 14 | 15 | jobs: 16 | 17 | unix: 18 | runs-on: ${{ matrix.os }} 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | os: [ubuntu-22.04, ubuntu-24.04, macos-14, macos-15] 24 | 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - name: Get number of CPU cores 29 | uses: SimenB/github-actions-cpu-cores@v2 30 | 31 | - name: Install micromamba 32 | uses: mamba-org/setup-micromamba@v1 33 | with: 34 | environment-file: environment-dev.yml 35 | 36 | - name: Make build directory 37 | run: mkdir build 38 | 39 | 40 | - name: Configure cmake 41 | run: | 42 | cmake .. \ 43 | -D CMAKE_PREFIX_PATH=$CONDA_PREFIX \ 44 | -D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX \ 45 | -D XLEAFLET_BUILD_TESTS=ON \ 46 | -D CMAKE_INSTALL_LIBDIR=lib \ 47 | -D CMAKE_C_COMPILER=$CC \ 48 | -D CMAKE_CXX_COMPILER=$CXX \ 49 | -D PYTHON_EXECUTABLE=`which python` 50 | working-directory: build 51 | 52 | - name: Build 53 | run: make -j ${{ steps.cpu-cores.outputs.count }} 54 | working-directory: build 55 | 56 | - name: Test xleaflet 57 | run: ./test_xleaflet 58 | working-directory: build/test 59 | 60 | win: 61 | runs-on: ${{ matrix.os }} 62 | 63 | strategy: 64 | fail-fast: false 65 | matrix: 66 | os: [windows-2022, windows-2025] 67 | 68 | steps: 69 | - uses: actions/checkout@v4 70 | 71 | - name: Install micromamba 72 | uses: mamba-org/setup-micromamba@v1 73 | with: 74 | init-shell: cmd.exe 75 | environment-file: environment-dev.yml 76 | 77 | - name: Make build directory 78 | run: mkdir build 79 | 80 | - name: Cmake configure 81 | shell: cmd /C call {0} 82 | run: | 83 | cmake .. ^ 84 | -GNinja ^ 85 | -DCMAKE_BUILD_TYPE=Release ^ 86 | -DCMAKE_PREFIX_PATH="%CONDA_PREFIX%\Library" ^ 87 | -DCMAKE_INSTALL_PREFIX="%CONDA_PREFIX%" 88 | working-directory: build 89 | 90 | - name: Build 91 | shell: cmd /C call {0} 92 | run: | 93 | set CL=/MP 94 | ninja 95 | working-directory: build 96 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille and Sylvain Corlay, and Wolf Vollprecht 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/index_example.html 9 | 10 | .. image:: xleaflet.svg 11 | 12 | The C++ backend for ipyleaflet. 13 | 14 | .. raw:: html 15 | 16 | 23 | 24 | Introduction 25 | ------------ 26 | 27 | ``xleaflet`` is a C++ backend for the ipyleaflet_ maps visualization library. 28 | 29 | ``xleaflet`` and its dependencies require a modern C++ compiler supporting C++14. The following C++ compilers are supported: 30 | 31 | - On Windows platforms, Visual C++ 2015 Update 2, or more recent 32 | - On Unix platforms, gcc 4.9 or a recent version of Clang 33 | 34 | Licensing 35 | --------- 36 | 37 | We use a shared copyright model that enables all contributors to maintain the 38 | copyright on their contributions. 39 | 40 | This software is licensed under the BSD-3-Clause license. See the LICENSE file for details. 41 | 42 | .. toctree:: 43 | :caption: Installation 44 | :maxdepth: 2 45 | 46 | installation 47 | 48 | .. toctree:: 49 | :caption: Usage 50 | :maxdepth: 2 51 | 52 | usage 53 | 54 | .. toctree:: 55 | :caption: Api Reference 56 | :maxdepth: 2 57 | 58 | api_reference/map 59 | api_reference/tile_layer 60 | api_reference/marker 61 | api_reference/icon 62 | api_reference/popup 63 | api_reference/wms_layer 64 | api_reference/image_video_overlay 65 | api_reference/polygon 66 | api_reference/rectangle 67 | api_reference/circle 68 | api_reference/circle_marker 69 | api_reference/marker_cluster 70 | api_reference/heatmap 71 | api_reference/velocity 72 | api_reference/layer_group 73 | api_reference/geo_json 74 | api_reference/fullscreen_control 75 | api_reference/layers_control 76 | api_reference/split_map_control 77 | api_reference/measure_control 78 | api_reference/widget_control 79 | api_reference/draw_control 80 | 81 | .. toctree:: 82 | :caption: Developer Zone 83 | 84 | releasing 85 | 86 | .. _ipyleaflet: https://github.com/jupyter-widgets/ipyleaflet.git 87 | -------------------------------------------------------------------------------- /docs/source/api_reference/geo_json.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | GeoJSON 8 | ======= 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include 16 | 17 | #include "xleaflet/xmap.hpp" 18 | #include "xleaflet/xbasemaps.hpp" 19 | #include "xleaflet/xgeo_json.hpp" 20 | 21 | auto black_and_white = xlf::basemap({"OpenStreetMap", "BlackAndWhite"}); 22 | 23 | auto map = xlf::map::initialize() 24 | .layers({black_and_white}) 25 | .center({34.6252978589571, -77.34580993652344}) 26 | .zoom(10) 27 | .finalize(); 28 | 29 | // Load a local file 30 | std::ifstream file("geo.json"); 31 | xeus::xjson geo_data; 32 | file >> geo_data; 33 | 34 | auto geo_json = xlf::geo_json::initialize() 35 | .data(geo_data) 36 | .finalize(); 37 | map.add_layer(geo_json); 38 | 39 | map 40 | 41 | Attributes 42 | ---------- 43 | 44 | ===================== ======================================== ================ === 45 | Attribute Type Default Value Doc 46 | ===================== ======================================== ================ === 47 | data ``xeus::xjson`` Data dictionary 48 | style ``xeus::xjson`` Style dictionary 49 | hover_style ``xeus::xjson`` Hover style dictionary 50 | ===================== ======================================== ================ === 51 | 52 | Methods 53 | ------- 54 | 55 | ===================== =========== ===================================== === 56 | Method Return type Arguments Doc 57 | ===================== =========== ===================================== === 58 | on_click ``void`` ``std::function`` Adds a callback on click event 59 | on_hover ``void`` ``std::function`` Adds a callback on hover event 60 | ===================== =========== ===================================== === 61 | -------------------------------------------------------------------------------- /notebooks/Velocity.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Heatmap

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xvelocity.hpp\"" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "auto map = xlf::map::initialize()\n", 41 | " .center({37.58, 261.65})\n", 42 | " .zoom(5)\n", 43 | " .finalize();\n", 44 | "\n", 45 | "auto base_layer = xlf::basemap({\"CartoDB\", \"DarkMatter\"});\n", 46 | "map.add_layer(base_layer);\n", 47 | "\n", 48 | "map" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "#include \"nlohmann/json.hpp\"\n", 58 | "#include \n", 59 | "\n", 60 | "std::ifstream file(\"velocity_data.json\");\n", 61 | "nlohmann::json data;\n", 62 | "file >> data;\n", 63 | "\n", 64 | "auto velocity = xlf::velocity::initialize()\n", 65 | " .data(data)\n", 66 | " .velocity_scale(0.01)\n", 67 | " .max_velocity(20)\n", 68 | " .display_options(R\"({\n", 69 | " \"velocityType\": \"Global Wind\",\n", 70 | " \"displayPosition\": \"bottomleft\",\n", 71 | " \"displayEmptyString\": \"No wind data\"\n", 72 | " })\")\n", 73 | " .finalize();\n", 74 | "\n", 75 | "map.add_layer(velocity);" 76 | ] 77 | } 78 | ], 79 | "metadata": { 80 | "kernelspec": { 81 | "display_name": "C++14", 82 | "language": "C++14", 83 | "name": "xcpp14" 84 | }, 85 | "language_info": { 86 | "codemirror_mode": "text/x-c++src", 87 | "file_extension": ".cpp", 88 | "mimetype": "text/x-c++src", 89 | "name": "c++", 90 | "version": "-std=c++14" 91 | } 92 | }, 93 | "nbformat": 4, 94 | "nbformat_minor": 4 95 | } 96 | -------------------------------------------------------------------------------- /docs/source/api_reference/draw_control.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/draw_control.html 9 | 10 | Draw Control 11 | ============ 12 | 13 | The ``draw_control`` allows one to draw shapes on the map such as ``rectangle`` ``circle`` or lines. 14 | 15 | .. code:: 16 | 17 | #include "xleaflet/xmap.hpp" 18 | #include "xleaflet/xdraw_control.hpp" 19 | #include "xleaflet/xbasemaps.hpp" 20 | 21 | auto water_color = xlf::basemap({"Stamen", "Watercolor"}); 22 | 23 | auto map = xlf::map::initialize() 24 | .layers({water_color}) 25 | .center({50, 354}) 26 | .zoom(5) 27 | .finalize(); 28 | 29 | xeus::xjson polyline_options = { 30 | {"shapeOptions", { 31 | {"color", "#6bc2e5"}, 32 | {"weight", 8}, 33 | {"opacity", 1.0} 34 | }} 35 | }; 36 | 37 | // Set some options for draw control 38 | xeus::xjson polygon_options = { 39 | {"shapeOptions", { 40 | {"fillColor", "#6be5c3"}, 41 | {"color", "#6be5c3"}, 42 | {"fillOpacity", 1.0} 43 | }}, 44 | {"drawError", { 45 | {"color", "#dd253b"}, 46 | {"message", "Oups!"} 47 | }}, 48 | {"allowIntersection", false} 49 | }; 50 | 51 | xeus::xjson circle_options = { 52 | {"shapeOptions", { 53 | {"fillColor", "#efed69"}, 54 | {"fillOpacity", 1.0}, 55 | {"color", "#efed69"} 56 | }} 57 | }; 58 | 59 | xeus::xjson rectangle_options = { 60 | {"shapeOptions", { 61 | {"fillColor", "#fca45d"}, 62 | {"fillOpacity", 1.0}, 63 | {"color", "#fca45d"} 64 | }} 65 | }; 66 | 67 | auto draw_control = xlf::draw_control::initialize() 68 | .polyline(polyline_options) 69 | .polygon(polygon_options) 70 | .circle(circle_options) 71 | .rectangle(rectangle_options) 72 | .finalize(); 73 | map.add_control(draw_control); 74 | 75 | map 76 | 77 | .. raw:: html 78 | 79 | 86 | -------------------------------------------------------------------------------- /docs/source/api_reference/circle.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Circle 8 | ====== 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xbasemaps.hpp" 17 | #include "xleaflet/xcircle.hpp" 18 | 19 | auto terrain = xlf::basemap({"Stamen", "Watercolor"}); 20 | 21 | auto map = xlf::map::initialize() 22 | .layers({terrain}) 23 | .center({53, 354}) 24 | .zoom(5) 25 | .finalize(); 26 | 27 | auto circle = xlf::circle::initialize() 28 | .location({50, 354}) 29 | .radius(50000) 30 | .color("green") 31 | .fill_color("green") 32 | .finalize(); 33 | 34 | map.add_layer(circle); 35 | 36 | map 37 | 38 | Attributes 39 | ---------- 40 | 41 | ===================== ======================================== ================ === 42 | Attribute Type Default Value Doc 43 | ===================== ======================================== ================ === 44 | location ``std::array`` {0.0, 0.0} Location of the circle 45 | radius ``int`` 1000 Radius of the circle, in meters 46 | stroke ``bool`` true Set it to `false` to disable borders 47 | color ``std::string`` "#0033FF" Color of the stroke 48 | opacity ``float`` 1.0 Opacity of the stroke 49 | weight ``int`` 5 Width of the stroke in pixels 50 | fill ``bool`` true Whether to fill the circle or not 51 | fill_color ``std::string`` "#0033FF" 52 | fill_opacity ``float`` 0.2 53 | dash_array ``std::string`` 54 | line_cap ``std::string`` "round" 55 | line_join ``std::string`` "round" 56 | ===================== ======================================== ================ === 57 | -------------------------------------------------------------------------------- /docs/source/api_reference/circle_marker.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Circle Marker 8 | ============= 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xbasemaps.hpp" 17 | #include "xleaflet/xcircle_marker.hpp" 18 | 19 | auto terrain = xlf::basemap({"Stamen", "Watercolor"}); 20 | 21 | auto map = xlf::map::initialize() 22 | .layers({terrain}) 23 | .center({53, 354}) 24 | .zoom(5) 25 | .finalize(); 26 | 27 | auto circle_marker = xlf::circle_marker::initialize() 28 | .location({55, 360}) 29 | .radius(50) 30 | .color("red") 31 | .fill_color("red") 32 | .finalize(); 33 | 34 | map.add_layer(circle_marker); 35 | 36 | map 37 | 38 | Attributes 39 | ---------- 40 | 41 | ===================== ======================================== ================ === 42 | Attribute Type Default Value Doc 43 | ===================== ======================================== ================ === 44 | location ``std::array`` {0.0, 0.0} Location of the circle 45 | radius ``int`` 10 Radius of the circle, in pixels 46 | stroke ``bool`` true Set it to `false` to disable borders 47 | color ``std::string`` "#0033FF" Color of the stroke 48 | opacity ``float`` 1.0 Opacity of the stroke 49 | weight ``int`` 5 Width of the stroke in pixels 50 | fill ``bool`` true Whether to fill the circle or not 51 | fill_color ``std::string`` "#0033FF" 52 | fill_opacity ``float`` 0.2 53 | dash_array ``std::string`` 54 | line_cap ``std::string`` "round" 55 | line_join ``std::string`` "round" 56 | ===================== ======================================== ================ === 57 | -------------------------------------------------------------------------------- /docs/source/api_reference/widget_control.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/widget_control.html 9 | 10 | Widget control 11 | ============== 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xleaflet/xmap.hpp" 19 | #include "xleaflet/xbasemaps.hpp" 20 | #include "xwidgets/xslider.hpp" 21 | #include "xwidgets/xnumeral.hpp" 22 | #include "xwidgets/xlink.hpp" 23 | #include "xleaflet/xwidget_control.hpp" 24 | 25 | std::array center = {52.204793, 360.121558}; 26 | 27 | auto map = xlf::map::initialize() 28 | .center(center) 29 | .zoom(4) 30 | .close_popup_on_click(false) 31 | .finalize(); 32 | map.display(); 33 | 34 | auto button1 = xw::slider::initialize() 35 | .min(1.0) 36 | .max(9.0) 37 | .value(4.0) 38 | .orientation("horizontal") 39 | .finalize(); 40 | 41 | auto popup2 = xlf::widget_control::initialize() 42 | .widget(button1) 43 | .position("bottomright") 44 | .finalize(); 45 | map.add_control(popup2); 46 | 47 | xw::numeral numeral; 48 | auto popup4 = xlf::widget_control::initialize() 49 | .widget(numeral) 50 | .position("topright") 51 | .finalize(); 52 | map.add_control(popup4); 53 | 54 | 55 | auto l = xw::link(numeral, "value", map, "zoom"); 56 | auto m = xw::link(button1, "value", map, "zoom"); 57 |
58 | 59 | .. raw:: html 60 | 61 | 68 |
69 | 70 | Attributes 71 | ---------- 72 | 73 | ===================== ========================= ===================== === 74 | Attribute Type Default Value Doc 75 | ===================== ========================= ===================== === 76 | widget ``xwidget`` Content of the widget 77 | position ``string`` Position of the widget 78 | ===================== ========================= ===================== === 79 | -------------------------------------------------------------------------------- /docs/source/embed_widgets/index_example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "#include \"xwidgets/xhtml.hpp\"\n", 10 | "\n", 11 | "#include \"xleaflet/xmap.hpp\"\n", 12 | "#include \"xleaflet/xbasemaps.hpp\"\n", 13 | "#include \"xleaflet/xpopup.hpp\"\n", 14 | "#include \"xleaflet/xmarker.hpp\"\n", 15 | "#include \"xleaflet/xmarker_cluster.hpp\"\n", 16 | "\n", 17 | "auto map = xlf::map::initialize())\n", 18 | " .layers({xlf::basemap({\"NASAGIBS\", \"ModisTerraTrueColorCR\"}, \"2014-09-01\")})\n", 19 | " .center({49.8946, 351.563})\n", 20 | " .zoom(5)\n", 21 | " .close_popup_on_click(false)\n", 22 | " .finalize();\n", 23 | "\n", 24 | "auto marker1 = xlf::marker::initialize)\n", 25 | " .location({48.92, 362.26})\n", 26 | " .finalize();\n", 27 | "auto marker2 = xlf::marker::initialize()\n", 28 | " .location({52.23, 360.24})\n", 29 | " .finalize();\n", 30 | "auto marker3 = xlf::marker::initialize()\n", 31 | " .location({43.698, 361.34})\n", 32 | " .finalize();\n", 33 | "auto marker_cluster = xlf::marker_cluster::initialize()\n", 34 | " .markers({marker1, marker2, marker3})\n", 35 | " .finalize();\n", 36 | "\n", 37 | "map.add_layer(marker_cluster);\n", 38 | "\n", 39 | "xw::html image, message, message1, message2;\n", 40 | "\n", 41 | "image.value = \"xleaflet logo\";\n", 42 | "marker1.popup = image;\n", 43 | "\n", 44 | "message.value = \"Some HTML Hello!\";\n", 45 | "marker2.popup = message;\n", 46 | "\n", 47 | "message1.value = \"C++ backend for the jupyter leaflet widget\";\n", 48 | "marker3.popup = message1;\n", 49 | "\n", 50 | "message2.value = \"Try clicking on markers!\";\n", 51 | "auto popup = xlf::popup::initialize()\n", 52 | " .child(message2)\n", 53 | " .location({48.3416, 340.584})\n", 54 | " .finalize();\n", 55 | "map.add_layer(popup);\n", 56 | "\n", 57 | "map" 58 | ] 59 | } 60 | ], 61 | "metadata": { 62 | "kernelspec": { 63 | "display_name": "C++14", 64 | "language": "C++14", 65 | "name": "xeus-cling-cpp14" 66 | }, 67 | "language_info": { 68 | "codemirror_mode": "text/x-c++src", 69 | "file_extension": ".cpp", 70 | "mimetype": "text/x-c++src", 71 | "name": "c++", 72 | "version": "14" 73 | } 74 | }, 75 | "nbformat": 4, 76 | "nbformat_minor": 2 77 | } 78 | -------------------------------------------------------------------------------- /docs/source/api_reference/heatmap.rst: -------------------------------------------------------------------------------- 1 | Heatmap 2 | ======= 3 | 4 | Example 5 | ------- 6 | 7 | .. code:: 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "xleaflet/xmap.hpp" 14 | #include "xleaflet/xheatmap.hpp" 15 | 16 | auto map = xlf::map::initialize() 17 | .center({37.58, 261.65}) 18 | .zoom(5) 19 | .finalize(); 20 | 21 | std::random_device rd; 22 | std::mt19937 mt(rd()); 23 | std::uniform_real_distribution rd_latitude(34.0, 40.0); 24 | std::uniform_real_distribution rd_longitude(255.0, 265.0); 25 | std::uniform_real_distribution rd_intensity(0.0, 1000.0); 26 | 27 | std::vector> heatmap_points; 28 | 29 | for (std::size_t i = 0; i < 100; ++i) 30 | { 31 | heatmap_points.push_back({rd_latitude(mt), rd_longitude(mt), rd_intensity(mt)}); 32 | } 33 | 34 | auto heatmap = xlf::heatmap::initialize() 35 | .locations(heatmap_points) 36 | .finalize(); 37 | 38 | map.add_layer(heatmap); 39 | 40 | map 41 | 42 | .. raw:: html 43 | 44 | 51 | 52 | Attributes 53 | ---------- 54 | 55 | ============== =================================================================== ==== 56 | Attribute Default Value Doc 57 | ============== =================================================================== ==== 58 | locations [] List of center locations 59 | min_opacity 0.05 Minimum opacity the heat will start at 60 | max_zoom 18 Zoom level where max intensity is reached 61 | max 1.0 Maximum point intensity 62 | radius 25.0 Radius of each "point" of the heatmap 63 | blur 15.0 Amount of blur 64 | gradient {0.4: 'blue', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 1.0: 'red'} Color gradient config 65 | ============== =================================================================== ==== 66 | -------------------------------------------------------------------------------- /docs/source/api_reference/icon.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/icon.html 9 | 10 | Icon 11 | ==== 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include 19 | 20 | #include "xleaflet/xmap.hpp" 21 | #include "xleaflet/xmarker.hpp" 22 | #include "xleaflet/xicon.hpp" 23 | 24 | using size_type = std::array; 25 | 26 | std::array center({52.204793, 360.121558}); 27 | 28 | auto map = xlf::map::initialize() 29 | .center(center) 30 | .zoom(10) 31 | .finalize(); 32 | 33 | auto icon = xlf::icon::initialize() 34 | .icon_url("https://leafletjs.com/examples/custom-icons/leaf-red.png") 35 | .icon_size(size_type({38, 95})) 36 | .icon_anchor(size_type({22, 94})) 37 | .finalize(); 38 | 39 | auto marker = xlf::marker::initialize() 40 | .location(center) 41 | .icon(icon) 42 | .rotation_angle(0) 43 | .rotation_origin("22px 94px") 44 | .finalize(); 45 | 46 | map.add_layer(marker); 47 | 48 | map 49 | 50 | .. raw:: html 51 | 52 | 59 | 60 | Attributes 61 | ---------- 62 | 63 | ===================== ========================= ===================== === 64 | Attribute Type Default Value Doc 65 | ===================== ========================= ===================== === 66 | icon_url ``std::string`` "" url for icon image 67 | shadow_url ``std::string`` "" url for icon shadow image 68 | icon_size ``std::array`` {10, 10} size of the icon, in pixels 69 | shadow_size ``std::array`` {10, 10} size of the icon shadow, in pixels 70 | icon_anchor ``std::array`` {0, 0} anchor point for the icon 71 | shadow_anchor ``std::array`` {0, 0} anchor point for the icon shadow 72 | popup_anchor ``std::array`` {0, 0} anchor point for the popup 73 | ===================== ========================= ===================== === 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ![xleaflet](docs/source/xleaflet.svg) 2 | 3 | [![GithubActions](https://github.com/jupyter-xeus/xleaflet/actions/workflows/main.yml/badge.svg)](https://github.com/jupyter-xeus/xleaflet/actions/workflows/main.yml) 4 | [![Documentation](http://readthedocs.org/projects/xleaflet/badge/?version=latest)](https://xleaflet.readthedocs.io/en/latest/?badge=latest) 5 | [![Binder](https://img.shields.io/badge/launch-binder-brightgreen.svg)](https://mybinder.org/v2/gh/jupyter-xeus/xleaflet/stable?filepath=notebooks) 6 | [![Zulip](https://img.shields.io/badge/social_chat-zulip-blue.svg)](https://jupyter.zulipchat.com/#narrow/channel/539737-Jupyter-Kernels) 7 | 8 | C++ backend for the jupyter-leaflet map visualization library 9 | 10 | ## Usage 11 | 12 | Selecting a base layer for a map: 13 | 14 | ![Basemap Screencast](basemap.gif) 15 | 16 | Loading a geojson dataset: 17 | 18 | ![GeoJSON Screencast](geojson.gif) 19 | 20 | Using the splitmap control: 21 | 22 | ![Splitmap Screencast](splitmap.gif) 23 | 24 | Displaying velocity data on the top of a map: 25 | 26 | ![Velocity Screencast](velocity.gif) 27 | 28 | ## Installation 29 | 30 | We provide a package for the mamba (or conda) package manager. 31 | 32 | - Installing `xleaflet` and the C++ kernel 33 | 34 | ```bash 35 | mamba install xeus-cling xleaflet -c conda-forge 36 | ``` 37 | 38 | Then, the front-end extension must be installed for either the classic notebook or JupyterLab. 39 | 40 | - Installing the extensions for the classic notebook 41 | 42 | ``` 43 | mamba install widgetsnbextension -c conda-forge 44 | mamba install ipyleaflet -c conda-forge 45 | ``` 46 | 47 | - Installing the JupyterLab extension 48 | 49 | ``` 50 | jupyter labextension install @jupyter-widgets/jupyterlab-manager 51 | jupyter labextension install jupyter-leaflet 52 | ``` 53 | 54 | ## Installation from sources 55 | 56 | Or you can directly install it from the sources if you have all the dependencies already installed: 57 | 58 | ```bash 59 | cmake -D CMAKE_INSTALL_PREFIX=your_install_prefix 60 | make install 61 | ``` 62 | 63 | ## Trying it online 64 | 65 | To try out xleaflet interactively in your web browser, just click on the binder 66 | link: 67 | 68 | [![Binder](docs/source/binder-logo.svg)](https://mybinder.org/v2/gh/jupyter-xeus/xleaflet/stable?filepath=notebooks/) 69 | 70 | ## Documentation 71 | 72 | To get started with using `xleaflet`, check out the full documentation 73 | 74 | http://xleaflet.readthedocs.io/ 75 | 76 | ## License 77 | 78 | We use a shared copyright model that enables all contributors to maintain the 79 | copyright on their contributions. 80 | 81 | This software is licensed under the BSD-3-Clause license. See the [LICENSE](LICENSE) file for details. 82 | -------------------------------------------------------------------------------- /notebooks/FullScreenControl.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

FullScreen control

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xfullscreen_control.hpp\"" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 2, 37 | "metadata": {}, 38 | "outputs": [ 39 | { 40 | "data": { 41 | "application/vnd.jupyter.widget-view+json": { 42 | "model_id": "277fed8287684803a072aae75fa2c228", 43 | "version_major": 2, 44 | "version_minor": 0 45 | }, 46 | "text/plain": [ 47 | "A Jupyter widget" 48 | ] 49 | }, 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "auto map = xlf::map::initialize()\n", 57 | " .center({51.64, -76.52})\n", 58 | " .zoom(5)\n", 59 | " .finalize();\n", 60 | "\n", 61 | "map" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "## Add a ``fullscreen_control`` to the map" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 3, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "map.add_control(xlf::fullscreen_control());" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "## And remove it" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "map.clear_controls();" 94 | ] 95 | } 96 | ], 97 | "metadata": { 98 | "kernelspec": { 99 | "display_name": "C++14", 100 | "language": "C++14", 101 | "name": "xcpp14" 102 | }, 103 | "language_info": { 104 | "codemirror_mode": "text/x-c++src", 105 | "file_extension": ".cpp", 106 | "mimetype": "text/x-c++src", 107 | "name": "c++", 108 | "version": "-std=c++14" 109 | } 110 | }, 111 | "nbformat": 4, 112 | "nbformat_minor": 4 113 | } 114 | -------------------------------------------------------------------------------- /include/xleaflet/xui_layer.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | *******************************************************************************/ 8 | 9 | #ifndef XLEAFLET_UI_LAYER_HPP 10 | #define XLEAFLET_UI_LAYER_HPP 11 | 12 | #include "xwidgets/xmaterialize.hpp" 13 | 14 | #include "xlayer.hpp" 15 | 16 | namespace nl = nlohmann; 17 | 18 | namespace xlf 19 | { 20 | /************************ 21 | * ui_layer declaration * 22 | ************************/ 23 | 24 | template 25 | class xui_layer : public xlayer 26 | { 27 | public: 28 | 29 | using base_type = xlayer; 30 | using derived_type = D; 31 | 32 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 33 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 34 | 35 | protected: 36 | 37 | xui_layer(); 38 | using base_type::base_type; 39 | 40 | private: 41 | 42 | void set_defaults(); 43 | }; 44 | 45 | using ui_layer = xw::xmaterialize; 46 | 47 | /**************************** 48 | * xui_layer implementation * 49 | ****************************/ 50 | 51 | template 52 | inline void xui_layer::serialize_state(nl::json& state, 53 | xeus::buffer_sequence& buffers) const 54 | { 55 | base_type::serialize_state(state, buffers); 56 | } 57 | 58 | template 59 | inline void xui_layer::apply_patch(const nl::json& patch, 60 | const xeus::buffer_sequence& buffers) 61 | { 62 | base_type::apply_patch(patch, buffers); 63 | } 64 | 65 | template 66 | inline xui_layer::xui_layer() 67 | : base_type() 68 | { 69 | set_defaults(); 70 | } 71 | 72 | template 73 | inline void xui_layer::set_defaults() 74 | { 75 | this->_model_name() = "LeafletUILayerModel"; 76 | this->_view_name() = "LeafletUILayerView"; 77 | } 78 | } 79 | 80 | /********************* 81 | * precompiled types * 82 | *********************/ 83 | 84 | extern template class xw::xmaterialize; 85 | extern template class xw::xtransport>; 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /docs/source/api_reference/velocity.rst: -------------------------------------------------------------------------------- 1 | .. raw:: html 2 | :file: embed_widgets/velocity.html 3 | 4 | Velocity 5 | ======== 6 | 7 | Example 8 | ------- 9 | 10 | .. code:: 11 | 12 | #include 13 | 14 | #include "nlohmann/json.hpp" 15 | 16 | #include "xleaflet/xmap.hpp" 17 | #include "xleaflet/xvelocity.hpp" 18 | 19 | auto map = xlf::map::initialize() 20 | .center({0, 0}) 21 | .zoom(1) 22 | .finalize(); 23 | 24 | auto base_layer = xlf::basemap({"CartoDB", "DarkMatter"}); 25 | map.add_layer(base_layer); 26 | 27 | std::ifstream file("velocity_data.json"); 28 | nlohmann::json data; 29 | file >> data; 30 | 31 | auto velocity = xlf::velocity::initialize() 32 | .data(data) 33 | .velocity_scale(0.01) 34 | .max_velocity(20) 35 | .display_options(R"({ 36 | "velocityType": "Global Wind", 37 | "displayPosition": "bottomleft", 38 | "displayEmptyString": "No wind data" 39 | })") 40 | .finalize(); 41 | 42 | map.add_layer(velocity); 43 | 44 | map 45 | 46 | .. raw:: html 47 | 48 | 55 | 56 | Attributes 57 | ---------- 58 | 59 | 60 | ====================== =================================================================== ==== 61 | Attribute Default Value Doc 62 | ====================== =================================================================== ==== 63 | data Null JSON objectdataset Underlying dataset 64 | units None Units 65 | display_values True Display velocity data on mouse hover 66 | display_options {} Display options 67 | min_velocity 0.0 Used to align color scale 68 | max_velocity 10.0 Used to align color scale 69 | velocity_scale 0.005 Modifier for particle animations 70 | color_scale Empty std::vector of html colors Array of hex/rgb colors for user-specified color scale. 71 | ====================== =================================================================== ==== 72 | -------------------------------------------------------------------------------- /include/xleaflet/xpolygon.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_POLYGON_HPP 11 | #define XLEAFLET_POLYGON_HPP 12 | 13 | #include "xwidgets/xmaterialize.hpp" 14 | #include "xwidgets/xwidget.hpp" 15 | 16 | #include "xpolyline.hpp" 17 | 18 | namespace nl = nlohmann; 19 | 20 | namespace xlf 21 | { 22 | /*********************** 23 | * polygon declaration * 24 | ***********************/ 25 | 26 | template 27 | class xpolygon : public xpolyline 28 | { 29 | public: 30 | 31 | using base_type = xpolyline; 32 | using derived_type = D; 33 | 34 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 35 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 36 | 37 | protected: 38 | 39 | xpolygon(); 40 | using base_type::base_type; 41 | 42 | private: 43 | 44 | void set_defaults(); 45 | }; 46 | 47 | using polygon = xw::xmaterialize; 48 | 49 | /*************************** 50 | * xpolygon implementation * 51 | ***************************/ 52 | 53 | template 54 | inline void xpolygon::serialize_state(nl::json& state, 55 | xeus::buffer_sequence& buffers) const 56 | { 57 | base_type::serialize_state(state, buffers); 58 | } 59 | 60 | template 61 | inline void xpolygon::apply_patch(const nl::json& patch, 62 | const xeus::buffer_sequence& buffers) 63 | { 64 | base_type::apply_patch(patch, buffers); 65 | } 66 | 67 | template 68 | inline xpolygon::xpolygon() 69 | : base_type() 70 | { 71 | set_defaults(); 72 | } 73 | 74 | template 75 | inline void xpolygon::set_defaults() 76 | { 77 | this->_model_name() = "LeafletPolygonModel"; 78 | this->_view_name() = "LeafletPolygonView"; 79 | } 80 | } 81 | 82 | /********************* 83 | * precompiled types * 84 | *********************/ 85 | 86 | extern template class xw::xmaterialize; 87 | extern template class xw::xtransport>; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /docs/source/api_reference/tile_layer.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/tile_layer.html 9 | 10 | Tile layer 11 | ========== 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xleaflet/xmap.hpp" 19 | #include "xleaflet/xbasemaps.hpp" 20 | 21 | auto map = xlf::map::initialize() 22 | .center({52.204793, 360.121558}) 23 | .zoom(9) 24 | .finalize(); 25 | 26 | auto dark_matter_layer = xlf::basemap({"CartoDB", "DarkMatter"}); 27 | map.add_layer(dark_matter_layer); 28 | map 29 | 30 | .. raw:: html 31 | 32 | 39 | 40 | Usage 41 | ----- 42 | 43 | Creating a ``tile_layer`` is straightforward, a list of basic tile layers is provided. 44 | This list of layers can be accessed using the ``basemaps`` function: 45 | 46 | .. code:: 47 | 48 | #include 49 | 50 | #include "xleaflet/xbasemaps.hpp" 51 | 52 | std::cout << xlf::basemaps().dump(6) << std::endl; 53 | 54 | A ``tile_layer`` instance can be created using the ``basemap`` function, specifying the wanted map 55 | (e.g. ``{"CartoDB", "DarkMatter"}``, ``{"Strava", "Winter"}``, ``{"NASAGIBS", "ModisTerraTrueColorCR"}``, ...). 56 | 57 | Sometimes one could want to specify the date of the given images, for instance with NASA images: 58 | 59 | .. code:: 60 | 61 | auto nasa_layer = xlf::basemap({"NASAGIBS", "ModisTerraTrueColorCR"}, "2018-04-08"); 62 | map.add_layer(nasa_layer); 63 | 64 | Attributes 65 | ---------- 66 | 67 | ===================== =============== =================================================================================== 68 | Attribute Type Default Value 69 | ===================== =============== =================================================================================== 70 | url ``std::string`` "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" 71 | min_zoom ``int`` 0 72 | max_zoom ``int`` 18 73 | tile_size ``int`` 256 74 | attribution ``std::string`` "Map data (c) OpenStreetMap contributors" 75 | detect_retina ``bool`` false 76 | opacity ``float`` 1.0 77 | visible ``bool`` true 78 | ===================== =============== =================================================================================== 79 | -------------------------------------------------------------------------------- /docs/source/api_reference/layer_group.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Layer Group 8 | =========== 9 | 10 | Example 11 | ------- 12 | 13 | .. code:: 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xbasemaps.hpp" 17 | #include "xleaflet/xlayer_group.hpp" 18 | #include "xleaflet/xcircle.hpp" 19 | #include "xleaflet/xmarker.hpp" 20 | #include "xleaflet/xrectangle.hpp" 21 | 22 | auto toner = xlf::basemap({"Stamen", "Toner"}); 23 | 24 | auto map = xlf::map::initialize() 25 | .layers({toner}) 26 | .center({50, 354}) 27 | .zoom(5) 28 | .finalize(); 29 | 30 | // Create some layers 31 | auto marker = xlf::marker::initialize() 32 | .location({50, 354}) 33 | .finalize(); 34 | auto circle = xlf::circle::initialize() 35 | .location({50, 370}) 36 | .radius(50000) 37 | .color("yellow") 38 | .fill_color("yellow") 39 | .finalize(); 40 | auto rectangle = xlf::rectangle::initialize() 41 | .bounds({{{54, 354}, {55, 360}}}) 42 | .color("orange") 43 | .fill_color("orange") 44 | .finalize(); 45 | 46 | // Create layer group 47 | auto layer_group = xlf::layer_group::initialize() 48 | .layers({marker, circle}) 49 | .finalize(); 50 | 51 | map.add_layer(layer_group); 52 | 53 | layer_group.add_layer(rectangle); 54 | 55 | layer_group.remove_layer(circle); 56 | 57 | map 58 | 59 | Attributes 60 | ---------- 61 | 62 | ===================== ======================================== ================ === 63 | Attribute Type Default Value Doc 64 | ===================== ======================================== ================ === 65 | layers ``std::vector`` {} Array of layers 66 | ===================== ======================================== ================ === 67 | 68 | Methods 69 | ------- 70 | 71 | ===================== =========== ===================================== === 72 | Method Return type Arguments Doc 73 | ===================== =========== ===================================== === 74 | add_layer ``void`` ``xlf::layer`` Add a new layer to the group 75 | remove_layer ``void`` ``xlf::layer`` Remove a layer from the group 76 | clear_layers ``void`` Remove all layers from the group 77 | ===================== =========== ===================================== === 78 | -------------------------------------------------------------------------------- /include/xleaflet/xvector_layer.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_VECTOR_LAYER_HPP 11 | #define XLEAFLET_VECTOR_LAYER_HPP 12 | 13 | #include "xwidgets/xmaterialize.hpp" 14 | #include "xwidgets/xwidget.hpp" 15 | 16 | #include "xlayer.hpp" 17 | 18 | namespace nl = nlohmann; 19 | 20 | namespace xlf 21 | { 22 | /**************************** 23 | * vector_layer declaration * 24 | ****************************/ 25 | 26 | template 27 | class xvector_layer : public xlayer 28 | { 29 | public: 30 | 31 | using base_type = xlayer; 32 | using derived_type = D; 33 | 34 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 35 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 36 | 37 | protected: 38 | 39 | xvector_layer(); 40 | using base_type::base_type; 41 | 42 | private: 43 | 44 | void set_defaults(); 45 | }; 46 | 47 | using vector_layer = xw::xmaterialize; 48 | 49 | /******************************** 50 | * xvector_layer implementation * 51 | ********************************/ 52 | 53 | template 54 | inline void xvector_layer::serialize_state(nl::json& state, 55 | xeus::buffer_sequence& buffers) const 56 | { 57 | base_type::serialize_state(state, buffers); 58 | } 59 | 60 | template 61 | inline void xvector_layer::apply_patch(const nl::json& patch, 62 | const xeus::buffer_sequence& buffers) 63 | { 64 | base_type::apply_patch(patch, buffers); 65 | } 66 | 67 | template 68 | inline xvector_layer::xvector_layer() 69 | : base_type() 70 | { 71 | set_defaults(); 72 | } 73 | 74 | template 75 | inline void xvector_layer::set_defaults() 76 | { 77 | this->_model_name() = "LeafletVectorLayerModel"; 78 | this->_view_name() = "LeafletVectorLayerView"; 79 | } 80 | } 81 | 82 | /********************* 83 | * precompiled types * 84 | *********************/ 85 | 86 | extern template class xw::xmaterialize; 87 | extern template class xw::xtransport>; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /notebooks/LayersControl.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Layers control

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xbasemaps.hpp\"\n", 32 | "#include \"xleaflet/xtile_layer.hpp\"\n", 33 | "#include \"xleaflet/xwms_layer.hpp\"\n", 34 | "#include \"xleaflet/xlayers_control.hpp\"" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "auto map = xlf::map::initialize()\n", 44 | " .center({50, 354})\n", 45 | " .zoom(4)\n", 46 | " .finalize();\n", 47 | "\n", 48 | "map" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "auto nasa_layer = xlf::basemap({\"NASAGIBS\", \"ModisTerraTrueColorCR\"}, \"2018-03-30\");\n", 58 | "map.add_layer(nasa_layer);\n", 59 | "\n", 60 | "auto wms = xlf::wms_layer::initialize()\n", 61 | " .url(\"https://demo.boundlessgeo.com/geoserver/ows?\")\n", 62 | " .layers(\"nasa:bluemarble\")\n", 63 | " .name(\"nasa:bluemarble\")\n", 64 | " .finalize();\n", 65 | "map.add_layer(wms);" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "## Add a ``layers_control`` to the map" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "map.add_control(xlf::layers_control());" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "## And remove it" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "map.clear_controls();" 98 | ] 99 | } 100 | ], 101 | "metadata": { 102 | "kernelspec": { 103 | "display_name": "C++14", 104 | "language": "C++14", 105 | "name": "xcpp14" 106 | }, 107 | "language_info": { 108 | "codemirror_mode": "text/x-c++src", 109 | "file_extension": ".cpp", 110 | "mimetype": "text/x-c++src", 111 | "name": "c++", 112 | "version": "-std=c++14" 113 | } 114 | }, 115 | "nbformat": 4, 116 | "nbformat_minor": 4 117 | } 118 | -------------------------------------------------------------------------------- /docs/source/binder-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 12 | 14 | 16 | 19 | 23 | 26 | 27 | 28 | 29 | 30 | 32 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/source/api_reference/measure_control.rst: -------------------------------------------------------------------------------- 1 | .. raw:: html 2 | :file: embed_widgets/measure_control.html 3 | 4 | Measure Control 5 | =============== 6 | 7 | Example 8 | ------- 9 | 10 | .. code:: 11 | 12 | #include 13 | #include 14 | 15 | #include "xleaflet/xmap.hpp" 16 | #include "xleaflet/xmeasure_control.hpp" 17 | #include "xleaflet/xbasemaps.hpp" 18 | 19 | auto water_color = xlf::basemap({"Stamen", "Watercolor"}); 20 | 21 | auto map = xlf::map::initialize() 22 | .layers({water_color}) 23 | .center({50, 354}) 24 | .zoom(5) 25 | .finalize(); 26 | 27 | auto measure_control = xlf::measure_control::initialize() 28 | .finalize(); 29 | 30 | map.add_control(measure_control); 31 | 32 | map 33 | 34 | .. raw:: html 35 | 36 | 43 | 44 | Attributes 45 | ---------- 46 | 47 | ===================== ========================================================================== === 48 | Attribute Default Value Doc 49 | ===================== ========================================================================== === 50 | position "topright" Position of the control on the Map, possible values are topleft, topright, bottomleft or bottomright 51 | primary_length_unit "feet" Primary length unit, possible values are feet, meters, miles, kilometers or any user defined length unit 52 | secondary_length_unit None Secondary length unit, possible values are None, feet, meters, miles, kilometers or any user defined length unit 53 | primary_area_unit "acres" Primary area unit, possible values are acres, hectares, sqfeet, sqmeters, sqmiles or any user defined area unit 54 | secondary_area_unit None Secondary area unit, possible values are None, acres, hectares, sqfeet, sqmeters, sqmiles or any user defined area unit 55 | active_color "#ABE67E" Color of the currently drawn area 56 | completed_color "#C8F2BE" Color of the completed areas 57 | popup_options {"className": "leaflet-measure-resultpopup", "autoPanPadding": [10, 10]} 58 | capture_z_index 10000 Z-index of the marker used to capture measure clicks. Set this value higher than the z-index of all other map layers to disable click events on other layers while a measurement is active. 59 | ===================== ========================================================================== === 60 | -------------------------------------------------------------------------------- /include/xleaflet/xrectangle.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_RECTANGLE_HPP 11 | #define XLEAFLET_RECTANGLE_HPP 12 | 13 | #include 14 | 15 | #include "xwidgets/xmaterialize.hpp" 16 | #include "xwidgets/xwidget.hpp" 17 | 18 | #include "xpolygon.hpp" 19 | 20 | namespace nl = nlohmann; 21 | 22 | namespace xlf 23 | { 24 | /************************* 25 | * rectangle declaration * 26 | *************************/ 27 | 28 | template 29 | class xrectangle : public xpolygon 30 | { 31 | public: 32 | 33 | using point_type = std::array; 34 | using bounds_type = std::array; 35 | 36 | using base_type = xpolygon; 37 | using derived_type = D; 38 | 39 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 40 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 41 | 42 | XPROPERTY(bounds_type, derived_type, bounds); 43 | 44 | protected: 45 | 46 | xrectangle(); 47 | using base_type::base_type; 48 | 49 | private: 50 | 51 | void set_defaults(); 52 | }; 53 | 54 | using rectangle = xw::xmaterialize; 55 | 56 | /***************************** 57 | * xrectangle implementation * 58 | *****************************/ 59 | 60 | template 61 | inline void xrectangle::serialize_state(nl::json& state, 62 | xeus::buffer_sequence& buffers) const 63 | { 64 | base_type::serialize_state(state, buffers); 65 | 66 | using xw::xwidgets_serialize; 67 | 68 | xwidgets_serialize(bounds(), state["bounds"], buffers); 69 | } 70 | 71 | template 72 | inline void xrectangle::apply_patch(const nl::json& patch, 73 | const xeus::buffer_sequence& buffers) 74 | { 75 | base_type::apply_patch(patch, buffers); 76 | 77 | using xw::set_property_from_patch; 78 | 79 | set_property_from_patch(bounds, patch, buffers); 80 | } 81 | 82 | template 83 | inline xrectangle::xrectangle() 84 | : base_type() 85 | { 86 | set_defaults(); 87 | } 88 | 89 | template 90 | inline void xrectangle::set_defaults() 91 | { 92 | this->_model_name() = "LeafletRectangleModel"; 93 | this->_view_name() = "LeafletRectangleView"; 94 | } 95 | } 96 | 97 | /********************* 98 | * precompiled types * 99 | *********************/ 100 | 101 | extern template class xw::xmaterialize; 102 | extern template class xw::xtransport>; 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /notebooks/GeoJSON.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

GeoJSON

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \n", 31 | "#include \n", 32 | "#include \n", 33 | "\n", 34 | "#include \"xleaflet/xmap.hpp\"\n", 35 | "#include \"xleaflet/xbasemaps.hpp\"\n", 36 | "#include \"xleaflet/xgeo_json.hpp\"" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "auto black_and_white = xlf::basemap({\"OpenStreetMap\", \"BlackAndWhite\"});\n", 46 | "\n", 47 | "auto map = xlf::map::initialize()\n", 48 | " .layers({black_and_white})\n", 49 | " .center({34.6252978589571, -77.34580993652344})\n", 50 | " .zoom(10)\n", 51 | " .finalize();\n", 52 | "\n", 53 | "map" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "## Load a local json file" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "std::ifstream file(\"geo.json\");\n", 70 | "nl::json geo_data;\n", 71 | "file >> geo_data;" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": null, 77 | "metadata": {}, 78 | "outputs": [], 79 | "source": [ 80 | "for (auto& feature: geo_data[\"features\"])\n", 81 | "{\n", 82 | " feature[\"properties\"][\"style\"] = {\n", 83 | " {\"weight\", 1},\n", 84 | " {\"fillOpacity\", 0.5}\n", 85 | " };\n", 86 | "}" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "void print_event_callback(nl::json event)\n", 96 | "{\n", 97 | " std::cout << event.dump(4);\n", 98 | "}" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": null, 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "auto geo_json = xlf::geo_json::initialize()\n", 108 | " .data(geo_data)\n", 109 | " .finalize();\n", 110 | "// geo_json.on_hover(print_event_callback);\n", 111 | "// geo_json.on_click(print_event_callback);\n", 112 | "map.add_layer(geo_json);" 113 | ] 114 | } 115 | ], 116 | "metadata": { 117 | "kernelspec": { 118 | "display_name": "C++14", 119 | "language": "C++14", 120 | "name": "xcpp14" 121 | }, 122 | "language_info": { 123 | "codemirror_mode": "text/x-c++src", 124 | "file_extension": ".cpp", 125 | "mimetype": "text/x-c++src", 126 | "name": "c++", 127 | "version": "14" 128 | } 129 | }, 130 | "nbformat": 4, 131 | "nbformat_minor": 4 132 | } 133 | -------------------------------------------------------------------------------- /docs/source/api_reference/marker.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/marker.html 9 | 10 | Marker 11 | ====== 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xleaflet/xmap.hpp" 19 | #include "xleaflet/xmarker.hpp" 20 | 21 | std::array center = {52.204793, 360.121558}; 22 | 23 | auto map = xlf::map::initialize() 24 | .center(center) 25 | .zoom(15) 26 | .finalize(); 27 | 28 | auto marker = xlf::marker::initialize() 29 | .location(center) 30 | .draggable(false) 31 | .finalize(); 32 | map.add_layer(marker); 33 | 34 | map 35 | 36 | .. raw:: html 37 | 38 | 45 | 46 | Attributes 47 | ---------- 48 | 49 | ===================== ========================= ===================== === 50 | Attribute Type Default Value Doc 51 | ===================== ========================= ===================== === 52 | location ``std::array`` {0.0, 0.0} 53 | z_index_offset ``int`` 0 54 | draggable ``bool`` true Whether the marker is draggable with mouse/touch or not 55 | keyboard ``bool`` true Whether the marker can be tabbed to with a keyboard and clicked by pressing enter 56 | title ``std::string`` "" Text for the browser tooltip that appear on marker hover (no tooltip by default) 57 | alt ``std::string`` "" Text for the `alt` attribute of the icon image (useful for accessibility) 58 | rise_on_hover ``bool`` false The z-index offset used for the `rise_on_hover` feature 59 | opacity ``float`` 1.0 60 | visible ``bool`` true 61 | icon ``xlf::icon`` The icon for the marker 62 | rotation_angle ``int`` 0 The rotation angle of the marker in degrees 63 | rotation_origin ``std::string`` "" The rotation origin of the marker 64 | rise_offset ``int`` 250 The z-index offset used for the `rise_on_hover` feature 65 | ===================== ========================= ===================== === 66 | 67 | Methods 68 | ------- 69 | 70 | ===================== =========== ===================================== === 71 | Method Return type Arguments Doc 72 | ===================== =========== ===================================== === 73 | on_move ``void`` ``std::function`` Adds a callback on move event 74 | ===================== =========== ===================================== === 75 | -------------------------------------------------------------------------------- /docs/source/api_reference/wms_layer.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/wms_layer.html 9 | 10 | WMS layer 11 | ========= 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xleaflet/xmap.hpp" 19 | #include "xleaflet/xwms_layer.hpp" 20 | 21 | auto wms = xlf::wms_layer::initialize() 22 | .url("https://demo.boundlessgeo.com/geoserver/ows?") 23 | .layers("nasa:bluemarble") 24 | .finalize(); 25 | 26 | auto map = xlf::map::initialize() 27 | .layers({wms}) 28 | .center({42.5531, -48.6914}) 29 | .zoom(3) 30 | .finalize(); 31 | 32 | map 33 | 34 | .. raw:: html 35 | 36 | 43 | 44 | Attributes 45 | ---------- 46 | 47 | ===================== ========================= =================================================================================== === 48 | Attribute Type Default Value Doc 49 | ===================== ========================= =================================================================================== === 50 | url ``std::string`` "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" 51 | min_zoom ``int`` 0 52 | max_zoom ``int`` 18 53 | tile_size ``int`` 256 54 | attribution ``std::string`` "Map data (c) OpenStreetMap contributors" 55 | detect_retina ``bool`` false 56 | opacity ``float`` 1.0 57 | visible ``bool`` true 58 | service ``std::string`` "WMS" 59 | request ``std::string`` "GetMap" 60 | layers ``std::string`` "" Comma-separated list of WMS layers to show 61 | styles ``std::string`` "" Comma-separated list of WMS styles 62 | format ``std::string`` "image/jpeg" WMS image format (use `'image/png'` for layers with transparency) 63 | transparent ``bool`` false If `true`, the WMS service will return images with transparency 64 | version ``std::string`` "1.1.1" Version of the WMS service to use 65 | crs ``std::string`` "" 66 | ===================== ========================= =================================================================================== === 67 | -------------------------------------------------------------------------------- /include/xleaflet/xcircle_marker.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_CIRCLE_MARKER_HPP 11 | #define XLEAFLET_CIRCLE_MARKER_HPP 12 | 13 | #include "nlohmann/json.hpp" 14 | 15 | #include "xwidgets/xmaterialize.hpp" 16 | #include "xwidgets/xwidget.hpp" 17 | 18 | #include "xcircle.hpp" 19 | 20 | namespace nl = nlohmann; 21 | 22 | namespace xlf 23 | { 24 | /***************************** 25 | * circle_marker declaration * 26 | *****************************/ 27 | 28 | template 29 | class xcircle_marker : public xcircle 30 | { 31 | public: 32 | 33 | using base_type = xcircle; 34 | using derived_type = D; 35 | 36 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 37 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 38 | 39 | XPROPERTY(int, derived_type, radius, 10); 40 | 41 | protected: 42 | 43 | xcircle_marker(); 44 | using base_type::base_type; 45 | 46 | private: 47 | 48 | void set_defaults(); 49 | }; 50 | 51 | using circle_marker = xw::xmaterialize; 52 | 53 | /********************************* 54 | * xcircle_marker implementation * 55 | *********************************/ 56 | 57 | template 58 | inline void xcircle_marker::serialize_state(nl::json& state, 59 | xeus::buffer_sequence& buffers) const 60 | { 61 | base_type::serialize_state(state, buffers); 62 | 63 | using xw::xwidgets_serialize; 64 | 65 | xwidgets_serialize(radius(), state["radius"], buffers); 66 | } 67 | 68 | template 69 | inline void xcircle_marker::apply_patch(const nl::json& patch, 70 | const xeus::buffer_sequence& buffers) 71 | { 72 | base_type::apply_patch(patch, buffers); 73 | 74 | using xw::set_property_from_patch; 75 | 76 | set_property_from_patch(radius, patch, buffers); 77 | } 78 | 79 | template 80 | inline xcircle_marker::xcircle_marker() 81 | : base_type() 82 | { 83 | set_defaults(); 84 | } 85 | 86 | template 87 | inline void xcircle_marker::set_defaults() 88 | { 89 | this->_model_name() = "LeafletCircleMarkerModel"; 90 | this->_view_name() = "LeafletCircleMarkerView"; 91 | 92 | this->options().insert( 93 | this->options().end(), 94 | { 95 | "radius" 96 | } 97 | ); 98 | } 99 | } 100 | 101 | /********************* 102 | * precompiled types * 103 | *********************/ 104 | 105 | extern template class xw::xmaterialize; 106 | extern template class xw::xtransport>; 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /include/xleaflet/xmarker_cluster.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_MARKER_CLUSTER_HPP 11 | #define XLEAFLET_MARKER_CLUSTER_HPP 12 | 13 | #include 14 | 15 | #include "xwidgets/xholder.hpp" 16 | #include "xwidgets/xmaterialize.hpp" 17 | #include "xwidgets/xwidget.hpp" 18 | 19 | #include "xlayer.hpp" 20 | #include "xleaflet_config.hpp" 21 | #include "xmarker.hpp" 22 | 23 | namespace nl = nlohmann; 24 | 25 | namespace xlf 26 | { 27 | /****************************** 28 | * marker_cluster declaration * 29 | ******************************/ 30 | 31 | template 32 | class xmarker_cluster : public xlayer 33 | { 34 | public: 35 | 36 | using base_type = xlayer; 37 | using derived_type = D; 38 | 39 | using marker_list_type = std::vector; 40 | 41 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 42 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 43 | 44 | XPROPERTY(std::vector, derived_type, markers); 45 | 46 | protected: 47 | 48 | xmarker_cluster(); 49 | using base_type::base_type; 50 | 51 | private: 52 | 53 | void set_defaults(); 54 | }; 55 | 56 | using marker_cluster = xw::xmaterialize; 57 | 58 | /********************************** 59 | * xmarker_cluster implementation * 60 | **********************************/ 61 | 62 | template 63 | inline void xmarker_cluster::serialize_state(nl::json& state, 64 | xeus::buffer_sequence& buffers) const 65 | { 66 | base_type::serialize_state(state, buffers); 67 | 68 | using xw::xwidgets_serialize; 69 | 70 | xwidgets_serialize(markers(), state["markers"], buffers); 71 | } 72 | 73 | template 74 | inline void xmarker_cluster::apply_patch(const nl::json& patch, 75 | const xeus::buffer_sequence& buffers) 76 | { 77 | base_type::apply_patch(patch, buffers); 78 | 79 | using xw::set_property_from_patch; 80 | 81 | set_property_from_patch(markers, patch, buffers); 82 | } 83 | 84 | template 85 | inline xmarker_cluster::xmarker_cluster() 86 | : base_type() 87 | { 88 | set_defaults(); 89 | } 90 | 91 | template 92 | inline void xmarker_cluster::set_defaults() 93 | { 94 | this->_model_name() = "LeafletMarkerClusterModel"; 95 | this->_view_name() = "LeafletMarkerClusterView"; 96 | } 97 | } 98 | 99 | /********************* 100 | * precompiled types * 101 | *********************/ 102 | 103 | extern template class xw::xmaterialize; 104 | extern template class xw::xtransport>; 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /include/xleaflet/xbasemaps.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_BASEMAPS_HPP 11 | #define XLEAFLET_BASEMAPS_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "nlohmann/json.hpp" 19 | 20 | #include "xget_basemaps_path.hpp" 21 | #include "xtile_layer.hpp" 22 | 23 | namespace nl = nlohmann; 24 | 25 | namespace detail 26 | { 27 | inline nl::json load_basemaps() 28 | { 29 | std::ifstream maps_json(xlf::get_basemaps_path()); 30 | 31 | nl::json maps; 32 | maps_json >> maps; 33 | 34 | return maps; 35 | } 36 | } 37 | 38 | namespace xlf 39 | { 40 | inline const nl::json& basemaps() 41 | { 42 | static nl::json maps = detail::load_basemaps(); 43 | 44 | return maps; 45 | } 46 | 47 | inline tile_layer basemap(const std::vector& path, 48 | const std::string& day = "2018-01-01") 49 | { 50 | const nl::json& maps = basemaps(); 51 | 52 | const nl::json* node = &maps; 53 | try 54 | { 55 | for (const auto& level : path) 56 | { 57 | node = &((*node)[level]); 58 | } 59 | } 60 | catch (const std::exception&) 61 | { 62 | std::cerr << "Invalid map spec" << std::endl; 63 | return tile_layer(); 64 | } 65 | 66 | const nl::json& mapspec = *node; 67 | if (mapspec.find("url") == mapspec.end()) 68 | { 69 | std::cerr << "Invalid map spec" << std::endl; 70 | return tile_layer(); 71 | } 72 | 73 | std::string url = mapspec["url"].get(); 74 | std::string attribution = ""; 75 | std::string name = ""; 76 | int max_zoom = 19; 77 | int min_zoom = 1; 78 | 79 | std::size_t date = url.find("%s"); 80 | if (date != std::string::npos) 81 | { 82 | url.replace(date, 2, day); 83 | } 84 | 85 | if (mapspec.find("attribution") != mapspec.end()) 86 | { 87 | attribution = mapspec["attribution"].get(); 88 | } 89 | 90 | if (mapspec.find("name") != mapspec.end()) 91 | { 92 | name = mapspec["name"].get(); 93 | } 94 | 95 | if (mapspec.find("max_zoom") != mapspec.end()) 96 | { 97 | max_zoom = mapspec["max_zoom"].get(); 98 | } 99 | 100 | if (mapspec.find("min_zoom") != mapspec.end()) 101 | { 102 | min_zoom = mapspec["min_zoom"].get(); 103 | } 104 | 105 | return tile_layer::initialize() 106 | .url(url) 107 | .attribution(attribution) 108 | .name(name) 109 | .max_zoom(max_zoom) 110 | .min_zoom(min_zoom) 111 | .finalize(); 112 | } 113 | } 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /docs/source/api_reference/popup.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2018, Johan Mabille, Sylvain Corlay, Wolf Vollprecht and Martin Renou 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | .. raw:: html 8 | :file: embed_widgets/popup.html 9 | 10 | Popup 11 | ===== 12 | 13 | Example 14 | ------- 15 | 16 | .. code:: 17 | 18 | #include "xwidgets/xhtml.hpp" 19 | 20 | #include "xleaflet/xmap.hpp" 21 | #include "xleaflet/xbasemaps.hpp" 22 | #include "xleaflet/xmarker.hpp" 23 | #include "xleaflet/xpopup.hpp" 24 | 25 | std::array center = {52.204793, 360.121558}; 26 | 27 | auto map = xlf::map::initialize() 28 | .center(center) 29 | .zoom(9) 30 | .close_popup_on_click(false) 31 | .finalize(); 32 | map.display(); 33 | 34 | auto marker = xlf::marker::initialize() 35 | .location({52.1, 359.9}) 36 | .finalize(); 37 | map.add_layer(marker); 38 | 39 | xw::html message1, message2; 40 | message1.value = "Try clicking the marker!"; 41 | message2.value = "Hello World"; 42 | message2.placeholder = "Some HTML"; 43 | message2.description = "Some HTML"; 44 | 45 | // Popup with a given location on the map: 46 | auto popup = xlf::popup::initialize() 47 | .location(center) 48 | .child(message1) 49 | .close_button(false) 50 | .auto_close(false) 51 | .close_on_escape_key(false) 52 | .finalize(); 53 | map.add_layer(popup); 54 | 55 | // Popup associated to a layer 56 | marker.popup = message2; 57 | 58 | .. raw:: html 59 | 60 | 67 | 68 | Attributes 69 | ---------- 70 | 71 | ===================== ========================= ===================== === 72 | Attribute Type Default Value Doc 73 | ===================== ========================= ===================== === 74 | location ``std::array`` {0.0, 0.0} 75 | child ``xwidget`` Content of the popup 76 | max_width ``int`` 300 Max width of the popup, in pixels 77 | min_width ``int`` 50 Min width of the popup, in pixels 78 | max_height ``int`` If set, creates a scrollable container of the given height inside a popup if its content exceeds it 79 | auto_pan ``bool`` true Set it to `false` if you don't want the map to do panning animation to fit the opened popup 80 | auto_pan_padding ``std::array`` {5, 5} 81 | keep_in_view ``bool`` false Set it to `true` if you want to prevent users from panning the popup off of the screen while it is open 82 | close_button ``bool`` true Controls the presence of a close button in the popup 83 | close_on_escape_key ``bool`` true Set it to `false` if you want to override the default behavior of the ESC key for closing of the popup 84 | class_name ``std::string`` "" A custom CSS class name to assign to the popup 85 | ===================== ========================= ===================== === 86 | -------------------------------------------------------------------------------- /include/xleaflet/xcircle.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_CIRCLE_HPP 11 | #define XLEAFLET_CIRCLE_HPP 12 | 13 | #include 14 | 15 | #include "nlohmann/json.hpp" 16 | 17 | #include "xwidgets/xmaterialize.hpp" 18 | #include "xwidgets/xwidget.hpp" 19 | 20 | #include "xpath.hpp" 21 | 22 | namespace nl = nlohmann; 23 | 24 | namespace xlf 25 | { 26 | /********************** 27 | * circle declaration * 28 | **********************/ 29 | 30 | template 31 | class xcircle : public xpath 32 | { 33 | public: 34 | 35 | using point_type = std::array; 36 | 37 | using base_type = xpath; 38 | using derived_type = D; 39 | 40 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 41 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 42 | 43 | XPROPERTY(point_type, derived_type, location); 44 | XPROPERTY(int, derived_type, radius, 1000); 45 | 46 | protected: 47 | 48 | xcircle(); 49 | using base_type::base_type; 50 | 51 | private: 52 | 53 | void set_defaults(); 54 | }; 55 | 56 | using circle = xw::xmaterialize; 57 | 58 | /************************** 59 | * xcircle implementation * 60 | **************************/ 61 | 62 | template 63 | inline void xcircle::serialize_state(nl::json& state, 64 | xeus::buffer_sequence& buffers) const 65 | { 66 | base_type::serialize_state(state, buffers); 67 | 68 | using xw::xwidgets_serialize; 69 | 70 | xwidgets_serialize(location(), state["location"], buffers); 71 | xwidgets_serialize(radius(), state["radius"], buffers); 72 | } 73 | 74 | template 75 | inline void xcircle::apply_patch(const nl::json& patch, 76 | const xeus::buffer_sequence& buffers) 77 | { 78 | base_type::apply_patch(patch, buffers); 79 | 80 | using xw::set_property_from_patch; 81 | 82 | set_property_from_patch(location, patch, buffers); 83 | set_property_from_patch(radius, patch, buffers); 84 | } 85 | 86 | template 87 | inline xcircle::xcircle() 88 | : base_type() 89 | { 90 | set_defaults(); 91 | } 92 | 93 | template 94 | inline void xcircle::set_defaults() 95 | { 96 | this->_model_name() = "LeafletCircleModel"; 97 | this->_view_name() = "LeafletCircleView"; 98 | 99 | this->options().insert( 100 | this->options().end(), 101 | { 102 | "radius" 103 | } 104 | ); 105 | } 106 | } 107 | 108 | /********************* 109 | * precompiled types * 110 | *********************/ 111 | 112 | extern template class xw::xmaterialize; 113 | extern template class xw::xtransport>; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /notebooks/Geometry.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Geometry

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xtensor/xarray.hpp\"\n", 31 | "#include \"xtensor/xio.hpp\"\n", 32 | "\n", 33 | "#include \"xleaflet/xmap.hpp\"\n", 34 | "#include \"xleaflet/xbasemaps.hpp\"\n", 35 | "#include \"xleaflet/xcircle.hpp\"\n", 36 | "#include \"xleaflet/xcircle_marker.hpp\"\n", 37 | "#include \"xleaflet/xpolygon.hpp\"" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": null, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "auto terrain = xlf::basemap({\"Stamen\", \"Terrain\"});\n", 47 | "\n", 48 | "auto map = xlf::map::initialize()\n", 49 | " .layers({terrain})\n", 50 | " .center({53, 354})\n", 51 | " .zoom(5)\n", 52 | " .finalize();\n", 53 | "\n", 54 | "map" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "## Create a ``circle`` with a radius in meters" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "auto circle = xlf::circle::initialize()\n", 71 | " .location({50, 354})\n", 72 | " .radius(50000)\n", 73 | " .color(\"green\")\n", 74 | " .fill_color(\"green\")\n", 75 | " .finalize();\n", 76 | "\n", 77 | "map.add_layer(circle);" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "## Create a ``circle_marker`` with a radius in pixels" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "auto circle_marker = xlf::circle_marker::initialize()\n", 94 | " .location({55, 360})\n", 95 | " .radius(50)\n", 96 | " .color(\"red\")\n", 97 | " .fill_color(\"red\")\n", 98 | " .finalize();\n", 99 | "\n", 100 | "map.add_layer(circle_marker);" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [ 109 | "circle_marker.radius = 100;" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "## Create a ``polygon`` using ``xtensor``" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": {}, 123 | "outputs": [], 124 | "source": [ 125 | "xt::xarray locations = {{55, 360}, {50, 354}, {53, 354}};\n", 126 | "auto polygon = xlf::polygon();\n", 127 | "polygon.locations = locations;\n", 128 | "\n", 129 | "map.add_layer(polygon);" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "C++14", 136 | "language": "C++14", 137 | "name": "xcpp14" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": "text/x-c++src", 141 | "file_extension": ".cpp", 142 | "mimetype": "text/x-c++src", 143 | "name": "c++", 144 | "version": "-std=c++14" 145 | } 146 | }, 147 | "nbformat": 4, 148 | "nbformat_minor": 4 149 | } 150 | -------------------------------------------------------------------------------- /include/xleaflet/xraster_layer.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | *******************************************************************************/ 8 | 9 | #ifndef XLEAFLET_RASTER_LAYER_HPP 10 | #define XLEAFLET_RASTER_LAYER_HPP 11 | 12 | #include "xwidgets/xmaterialize.hpp" 13 | #include "xwidgets/xwidget.hpp" 14 | 15 | #include "xlayer.hpp" 16 | #include "xleaflet_config.hpp" 17 | 18 | namespace nl = nlohmann; 19 | 20 | namespace xlf 21 | { 22 | /**************************** 23 | * raster_layer declaration * 24 | ****************************/ 25 | 26 | template 27 | class xraster_layer : public xlayer 28 | { 29 | public: 30 | 31 | using base_type = xlayer; 32 | using derived_type = D; 33 | 34 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 35 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 36 | 37 | XPROPERTY(double, derived_type, opacity, 1.0); 38 | XPROPERTY(bool, derived_type, visible, true); 39 | 40 | protected: 41 | 42 | xraster_layer(); 43 | using base_type::base_type; 44 | 45 | private: 46 | 47 | void set_defaults(); 48 | 49 | void setup_properties(); 50 | }; 51 | 52 | using raster_layer = xw::xmaterialize; 53 | 54 | /******************************** 55 | * xraster_layer implementation * 56 | ********************************/ 57 | 58 | template 59 | inline void xraster_layer::serialize_state(nl::json& state, 60 | xeus::buffer_sequence& buffers) const 61 | { 62 | base_type::serialize_state(state, buffers); 63 | 64 | using xw::xwidgets_serialize; 65 | 66 | xwidgets_serialize(opacity(), state["opacity"], buffers); 67 | xwidgets_serialize(visible(), state["visible"], buffers); 68 | } 69 | 70 | template 71 | inline void xraster_layer::apply_patch(const nl::json& patch, 72 | const xeus::buffer_sequence& buffers) 73 | { 74 | base_type::apply_patch(patch, buffers); 75 | 76 | using xw::set_property_from_patch; 77 | 78 | set_property_from_patch(opacity, patch, buffers); 79 | set_property_from_patch(visible, patch, buffers); 80 | } 81 | 82 | template 83 | inline xraster_layer::xraster_layer() 84 | : base_type() 85 | { 86 | set_defaults(); 87 | 88 | this->setup_properties(); 89 | } 90 | 91 | template 92 | inline void xraster_layer::setup_properties() 93 | { 94 | // TODO: Create a class (in xproperty?) for bounded integer/float/double 95 | // instead of having a validator when needed 96 | 97 | // Opacity should be bounded between 0.0 and 1.0 98 | } 99 | 100 | template 101 | inline void xraster_layer::set_defaults() 102 | { 103 | this->_model_name() = "LeafletRasterLayerModel"; 104 | this->_view_name() = "LeafletRasterLayerView"; 105 | } 106 | } 107 | 108 | /********************* 109 | * precompiled types * 110 | *********************/ 111 | 112 | extern template class xw::xmaterialize; 113 | extern template class xw::xtransport>; 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /include/xleaflet/xcontrol.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_CONTROL_HPP 11 | #define XLEAFLET_CONTROL_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "nlohmann/json.hpp" 17 | 18 | #include "xwidgets/xmaterialize.hpp" 19 | #include "xwidgets/xobject.hpp" 20 | #include "xwidgets/xeither.hpp" 21 | #include "xleaflet_config.hpp" 22 | 23 | namespace nl = nlohmann; 24 | 25 | namespace xlf 26 | { 27 | /********************* 28 | * control declaration * 29 | *********************/ 30 | 31 | template 32 | class xcontrol : public xw::xobject 33 | { 34 | public: 35 | 36 | using base_type = xw::xobject; 37 | using derived_type = D; 38 | 39 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 40 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 41 | 42 | XPROPERTY(std::vector, derived_type, options); 43 | XPROPERTY(std::string, derived_type, position, "topleft", XEITHER("topright", "topleft", "bottomright", "bottomleft")); 44 | 45 | protected: 46 | 47 | xcontrol(); 48 | using base_type::base_type; 49 | 50 | private: 51 | 52 | void set_defaults(); 53 | }; 54 | 55 | using control = xw::xmaterialize; 56 | 57 | /*************************** 58 | * xcontrol implementation * 59 | ***************************/ 60 | 61 | template 62 | inline void xcontrol::serialize_state(nl::json& state, 63 | xeus::buffer_sequence& buffers) const 64 | { 65 | base_type::serialize_state(state, buffers); 66 | 67 | using xw::xwidgets_serialize; 68 | 69 | xwidgets_serialize(options(), state["options"], buffers); 70 | xwidgets_serialize(position(), state["position"], buffers); 71 | } 72 | 73 | template 74 | inline void xcontrol::apply_patch(const nl::json& patch, 75 | const xeus::buffer_sequence& buffers) 76 | { 77 | base_type::apply_patch(patch, buffers); 78 | 79 | using xw::set_property_from_patch; 80 | 81 | set_property_from_patch(options, patch, buffers); 82 | set_property_from_patch(position, patch, buffers); 83 | } 84 | 85 | template 86 | inline xcontrol::xcontrol() 87 | : base_type() 88 | { 89 | set_defaults(); 90 | } 91 | 92 | template 93 | inline void xcontrol::set_defaults() 94 | { 95 | this->_model_module() = "jupyter-leaflet"; 96 | this->_view_module() = "jupyter-leaflet"; 97 | this->_model_name() = "LeafletControlModel"; 98 | this->_view_name() = "LeafletControlView"; 99 | this->_model_module_version() = jupyter_leaflet_semver(); 100 | this->_view_module_version() = jupyter_leaflet_semver(); 101 | this->options() = {"position"}; 102 | } 103 | 104 | } 105 | 106 | /********************* 107 | * precompiled types * 108 | *********************/ 109 | 110 | extern template class xw::xmaterialize; 111 | extern template class xw::xtransport>; 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /include/xleaflet/xsplit_map_control.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_SPLIT_MAP_CONTROL_HPP 11 | #define XLEAFLET_SPLIT_MAP_CONTROL_HPP 12 | 13 | #include "xwidgets/xholder.hpp" 14 | #include "xwidgets/xmaterialize.hpp" 15 | #include "xwidgets/xwidget.hpp" 16 | 17 | #include "xcontrol.hpp" 18 | #include "xleaflet_config.hpp" 19 | #include "xtile_layer.hpp" 20 | 21 | namespace nl = nlohmann; 22 | 23 | namespace xlf 24 | { 25 | /********************************* 26 | * split_map_control declaration * 27 | *********************************/ 28 | 29 | template 30 | class xsplit_map_control : public xcontrol 31 | { 32 | public: 33 | 34 | using base_type = xcontrol; 35 | using derived_type = D; 36 | 37 | using tile_layer_type = xw::xholder; 38 | 39 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 40 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 41 | 42 | XPROPERTY(tile_layer_type, derived_type, left_layer); 43 | XPROPERTY(tile_layer_type, derived_type, right_layer); 44 | 45 | protected: 46 | 47 | xsplit_map_control(); 48 | using base_type::base_type; 49 | 50 | private: 51 | 52 | void set_defaults(); 53 | }; 54 | 55 | using split_map_control = xw::xmaterialize; 56 | 57 | /************************************* 58 | * xsplit_map_control implementation * 59 | *************************************/ 60 | 61 | template 62 | inline void xsplit_map_control::serialize_state(nl::json& state, 63 | xeus::buffer_sequence& buffers) const 64 | { 65 | base_type::serialize_state(state, buffers); 66 | 67 | using xw::xwidgets_serialize; 68 | 69 | xwidgets_serialize(left_layer(), state["left_layer"], buffers); 70 | xwidgets_serialize(right_layer(), state["right_layer"], buffers); 71 | } 72 | 73 | template 74 | inline void xsplit_map_control::apply_patch(const nl::json& patch, 75 | const xeus::buffer_sequence& buffers) 76 | { 77 | base_type::apply_patch(patch, buffers); 78 | 79 | using xw::set_property_from_patch; 80 | 81 | set_property_from_patch(left_layer, patch, buffers); 82 | set_property_from_patch(right_layer, patch, buffers); 83 | } 84 | 85 | template 86 | inline xsplit_map_control::xsplit_map_control() 87 | : base_type() 88 | { 89 | set_defaults(); 90 | } 91 | 92 | template 93 | inline void xsplit_map_control::set_defaults() 94 | { 95 | this->_model_name() = "LeafletSplitMapControlModel"; 96 | this->_view_name() = "LeafletSplitMapControlView"; 97 | 98 | this->left_layer() = tile_layer(); 99 | this->right_layer() = tile_layer(); 100 | } 101 | 102 | } 103 | 104 | /********************* 105 | * precompiled types * 106 | *********************/ 107 | 108 | extern template class xw::xmaterialize; 109 | extern template class xw::xtransport>; 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /notebooks/Popup.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Popup

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xwidgets/xbutton.hpp\"\n", 31 | "#include \"xwidgets/xhtml.hpp\"\n", 32 | "\n", 33 | "#include \"xleaflet/xmap.hpp\"\n", 34 | "#include \"xleaflet/xbasemaps.hpp\"\n", 35 | "#include \"xleaflet/xmarker.hpp\"\n", 36 | "#include \"xleaflet/xpopup.hpp\"" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "std::array center = {52.204793, 360.121558};\n", 46 | "\n", 47 | "auto map = xlf::map::initialize()\n", 48 | " .center(center)\n", 49 | " .zoom(9)\n", 50 | " .close_popup_on_click(false)\n", 51 | " .finalize();\n", 52 | "map.display();\n", 53 | "\n", 54 | "auto marker = xlf::marker::initialize()\n", 55 | " .location({52.1, 359.9})\n", 56 | " .finalize();\n", 57 | "map.add_layer(marker);" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "auto hidden_layer = xlf::basemap({\"Esri\", \"WorldStreetMap\"});\n", 67 | "hidden_layer.visible = false;\n", 68 | "map.add_layer(hidden_layer);" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "void layer_visibility()\n", 78 | "{\n", 79 | " hidden_layer.visible = !hidden_layer.visible;\n", 80 | "}\n", 81 | "\n", 82 | "xw::button button;\n", 83 | "button.description = \"Click me!\";\n", 84 | "button.button_style = \"success\";\n", 85 | "button.on_click(layer_visibility);\n", 86 | "\n", 87 | "xw::html html;\n", 88 | "html.value = \"Hello World\";\n", 89 | "html.placeholder = \"Some HTML\";\n", 90 | "html.description = \"Some HTML\";" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "## Popup with a given location on the map" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "auto popup = xlf::popup::initialize()\n", 107 | " .location(center)\n", 108 | " .child(button)\n", 109 | " .close_button(false)\n", 110 | " .auto_close(false)\n", 111 | " .close_on_escape_key(false)\n", 112 | " .finalize();\n", 113 | "map.add_layer(popup);" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "## Popup associated to a layer" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "marker.popup = html;" 130 | ] 131 | } 132 | ], 133 | "metadata": { 134 | "kernelspec": { 135 | "display_name": "C++14", 136 | "language": "C++14", 137 | "name": "xcpp14" 138 | }, 139 | "language_info": { 140 | "codemirror_mode": "text/x-c++src", 141 | "file_extension": ".cpp", 142 | "mimetype": "text/x-c++src", 143 | "name": "c++", 144 | "version": "-std=c++14" 145 | } 146 | }, 147 | "nbformat": 4, 148 | "nbformat_minor": 4 149 | } 150 | -------------------------------------------------------------------------------- /include/xleaflet/xpolyline.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_POLYLINE_HPP 11 | #define XLEAFLET_POLYLINE_HPP 12 | 13 | #include "xtensor/misc/xexpression_holder.hpp" 14 | 15 | #include "xwidgets/xmaterialize.hpp" 16 | #include "xwidgets/xwidget.hpp" 17 | 18 | #include "xpath.hpp" 19 | 20 | namespace nl = nlohmann; 21 | 22 | namespace xlf 23 | { 24 | /************************ 25 | * polyline declaration * 26 | ************************/ 27 | 28 | template 29 | class xpolyline : public xpath 30 | { 31 | public: 32 | 33 | using locations_type = xt::xexpression_holder; 34 | 35 | using base_type = xpath; 36 | using derived_type = D; 37 | 38 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 39 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 40 | 41 | XPROPERTY(locations_type, derived_type, locations); 42 | XPROPERTY(double, derived_type, smooth_factor, 1.0); 43 | XPROPERTY(bool, derived_type, no_clip, false); 44 | 45 | protected: 46 | 47 | xpolyline(); 48 | using base_type::base_type; 49 | 50 | private: 51 | 52 | void set_defaults(); 53 | }; 54 | 55 | using polyline = xw::xmaterialize; 56 | 57 | /**************************** 58 | * xpolyline implementation * 59 | ****************************/ 60 | 61 | template 62 | inline void xpolyline::serialize_state(nl::json& state, 63 | xeus::buffer_sequence& buffers) const 64 | { 65 | base_type::serialize_state(state, buffers); 66 | 67 | using xw::xwidgets_serialize; 68 | 69 | xwidgets_serialize(locations(), state["locations"], buffers); 70 | xwidgets_serialize(smooth_factor(), state["smooth_factor"], buffers); 71 | xwidgets_serialize(no_clip(), state["no_clip"], buffers); 72 | } 73 | 74 | template 75 | inline void xpolyline::apply_patch(const nl::json& patch, 76 | const xeus::buffer_sequence& buffers) 77 | { 78 | base_type::apply_patch(patch, buffers); 79 | 80 | using xw::set_property_from_patch; 81 | 82 | set_property_from_patch(locations, patch, buffers); 83 | set_property_from_patch(smooth_factor, patch, buffers); 84 | set_property_from_patch(no_clip, patch, buffers); 85 | } 86 | 87 | template 88 | inline xpolyline::xpolyline() 89 | : base_type() 90 | { 91 | set_defaults(); 92 | } 93 | 94 | template 95 | inline void xpolyline::set_defaults() 96 | { 97 | this->_model_name() = "LeafletPolylineModel"; 98 | this->_view_name() = "LeafletPolylineView"; 99 | 100 | this->locations() = xt::xexpression_holder(); 101 | 102 | this->options().insert( 103 | this->options().end(), 104 | { 105 | "smooth_factor", 106 | "no_clip" 107 | } 108 | ); 109 | } 110 | } 111 | 112 | /********************* 113 | * precompiled types * 114 | *********************/ 115 | 116 | extern template class xw::xmaterialize; 117 | extern template class xw::xtransport>; 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /notebooks/LayerGroup.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Layer Group

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \"xleaflet/xmap.hpp\"\n", 31 | "#include \"xleaflet/xbasemaps.hpp\"\n", 32 | "#include \"xleaflet/xlayer_group.hpp\"\n", 33 | "#include \"xleaflet/xcircle.hpp\"\n", 34 | "#include \"xleaflet/xmarker.hpp\"\n", 35 | "#include \"xleaflet/xrectangle.hpp\"" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "auto toner = xlf::basemap({\"Stamen\", \"Toner\"});\n", 45 | "\n", 46 | "auto map = xlf::map::initialize()\n", 47 | " .layers({toner})\n", 48 | " .center({50, 354})\n", 49 | " .zoom(5)\n", 50 | " .finalize();\n", 51 | "\n", 52 | "map" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "## Create some layers" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": null, 65 | "metadata": {}, 66 | "outputs": [], 67 | "source": [ 68 | "auto marker = xlf::marker::initialize()\n", 69 | " .location({50, 354})\n", 70 | " .finalize();\n", 71 | "auto circle = xlf::circle::initialize()\n", 72 | " .location({50, 370})\n", 73 | " .radius(50000)\n", 74 | " .color(\"yellow\")\n", 75 | " .fill_color(\"yellow\")\n", 76 | " .finalize();\n", 77 | "auto rectangle = xlf::rectangle::initialize()\n", 78 | " .bounds({{{54, 354}, {55, 360}}})\n", 79 | " .color(\"orange\")\n", 80 | " .fill_color(\"orange\")\n", 81 | " .finalize();" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "## Create ``layer_group``" 89 | ] 90 | }, 91 | { 92 | "cell_type": "code", 93 | "execution_count": null, 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "auto layer_group = xlf::layer_group::initialize()\n", 98 | " .layers({marker, circle})\n", 99 | " .finalize();\n", 100 | "\n", 101 | "map.add_layer(layer_group);" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": {}, 107 | "source": [ 108 | "## Add a new layer to the ``layer_group``" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "execution_count": null, 114 | "metadata": {}, 115 | "outputs": [], 116 | "source": [ 117 | "layer_group.add_layer(rectangle);" 118 | ] 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "metadata": {}, 123 | "source": [ 124 | "## Remove a layer from the ``layer_group``" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": null, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "layer_group.remove_layer(circle)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [ 142 | "layer_group.clear_layers();" 143 | ] 144 | } 145 | ], 146 | "metadata": { 147 | "kernelspec": { 148 | "display_name": "C++14", 149 | "language": "C++14", 150 | "name": "xcpp14" 151 | }, 152 | "language_info": { 153 | "codemirror_mode": "text/x-c++src", 154 | "file_extension": ".cpp", 155 | "mimetype": "text/x-c++src", 156 | "name": "c++", 157 | "version": "-std=c++14" 158 | } 159 | }, 160 | "nbformat": 4, 161 | "nbformat_minor": 4 162 | } 163 | -------------------------------------------------------------------------------- /include/xleaflet/ximage_overlay.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_IMAGE_OVERLAY_HPP 11 | #define XLEAFLET_IMAGE_OVERLAY_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "xwidgets/xmaterialize.hpp" 17 | #include "xwidgets/xwidget.hpp" 18 | 19 | #include "xleaflet_config.hpp" 20 | #include "xraster_layer.hpp" 21 | 22 | namespace nl = nlohmann; 23 | 24 | namespace xlf 25 | { 26 | /***************************** 27 | * image_overlay declaration * 28 | *****************************/ 29 | 30 | template 31 | class ximage_overlay : public xraster_layer 32 | { 33 | public: 34 | 35 | using point_type = std::array; 36 | using bounds_type = std::array; 37 | 38 | using base_type = xraster_layer; 39 | using derived_type = D; 40 | 41 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 42 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 43 | 44 | XPROPERTY(std::string, derived_type, url, ""); 45 | XPROPERTY(bounds_type, derived_type, bounds); 46 | XPROPERTY(std::string, derived_type, attribution, ""); 47 | 48 | protected: 49 | 50 | ximage_overlay(); 51 | using base_type::base_type; 52 | 53 | private: 54 | 55 | void set_defaults(); 56 | }; 57 | 58 | using image_overlay = xw::xmaterialize; 59 | 60 | /******************************** 61 | * image_overlay implementation * 62 | ********************************/ 63 | 64 | template 65 | inline void ximage_overlay::serialize_state(nl::json& state, 66 | xeus::buffer_sequence& buffers) const 67 | { 68 | base_type::serialize_state(state, buffers); 69 | 70 | using xw::xwidgets_serialize; 71 | 72 | xwidgets_serialize(url(), state["url"], buffers); 73 | xwidgets_serialize(bounds(), state["bounds"], buffers); 74 | xwidgets_serialize(attribution(), state["attribution"], buffers); 75 | } 76 | 77 | template 78 | inline void ximage_overlay::apply_patch(const nl::json& patch, 79 | const xeus::buffer_sequence& buffers) 80 | { 81 | base_type::apply_patch(patch, buffers); 82 | 83 | using xw::set_property_from_patch; 84 | 85 | set_property_from_patch(url, patch, buffers); 86 | set_property_from_patch(bounds, patch, buffers); 87 | set_property_from_patch(attribution, patch, buffers); 88 | } 89 | 90 | template 91 | inline ximage_overlay::ximage_overlay() 92 | : base_type() 93 | { 94 | set_defaults(); 95 | } 96 | 97 | template 98 | inline void ximage_overlay::set_defaults() 99 | { 100 | this->_model_name() = "LeafletImageOverlayModel"; 101 | this->_view_name() = "LeafletImageOverlayView"; 102 | 103 | this->bounds() = {{{0, 0}, {0, 0}}}; 104 | 105 | this->options().insert( 106 | this->options().end(), 107 | { 108 | "attribution" 109 | } 110 | ); 111 | } 112 | } 113 | 114 | /********************* 115 | * precompiled types * 116 | *********************/ 117 | 118 | extern template class xw::xmaterialize; 119 | extern template class xw::xtransport>; 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /include/xleaflet/xvideo_overlay.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_VIDEO_OVERLAY_HPP 11 | #define XLEAFLET_VIDEO_OVERLAY_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "xwidgets/xmaterialize.hpp" 17 | #include "xwidgets/xwidget.hpp" 18 | 19 | #include "xleaflet_config.hpp" 20 | #include "xraster_layer.hpp" 21 | 22 | namespace nl = nlohmann; 23 | 24 | namespace xlf 25 | { 26 | /***************************** 27 | * video_overlay declaration * 28 | *****************************/ 29 | 30 | template 31 | class xvideo_overlay : public xraster_layer 32 | { 33 | public: 34 | 35 | using point_type = std::array; 36 | using bounds_type = std::array; 37 | 38 | using base_type = xraster_layer; 39 | using derived_type = D; 40 | 41 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 42 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 43 | 44 | XPROPERTY(std::string, derived_type, url, ""); 45 | XPROPERTY(bounds_type, derived_type, bounds); 46 | XPROPERTY(std::string, derived_type, attribution, ""); 47 | 48 | protected: 49 | 50 | xvideo_overlay(); 51 | using base_type::base_type; 52 | 53 | private: 54 | 55 | void set_defaults(); 56 | }; 57 | 58 | using video_overlay = xw::xmaterialize; 59 | 60 | /******************************** 61 | * video_overlay implementation * 62 | ********************************/ 63 | 64 | template 65 | inline void xvideo_overlay::serialize_state(nl::json& state, 66 | xeus::buffer_sequence& buffers) const 67 | { 68 | base_type::serialize_state(state, buffers); 69 | 70 | using xw::xwidgets_serialize; 71 | 72 | xwidgets_serialize(url(), state["url"], buffers); 73 | xwidgets_serialize(bounds(), state["bounds"], buffers); 74 | xwidgets_serialize(attribution(), state["attribution"], buffers); 75 | } 76 | 77 | template 78 | inline void xvideo_overlay::apply_patch(const nl::json& patch, 79 | const xeus::buffer_sequence& buffers) 80 | { 81 | base_type::apply_patch(patch, buffers); 82 | 83 | using xw::set_property_from_patch; 84 | 85 | set_property_from_patch(url, patch, buffers); 86 | set_property_from_patch(bounds, patch, buffers); 87 | set_property_from_patch(attribution, patch, buffers); 88 | } 89 | 90 | template 91 | inline xvideo_overlay::xvideo_overlay() 92 | : base_type() 93 | { 94 | set_defaults(); 95 | } 96 | 97 | template 98 | inline void xvideo_overlay::set_defaults() 99 | { 100 | this->_model_name() = "LeafletVideoOverlayModel"; 101 | this->_view_name() = "LeafletVideoOverlayView"; 102 | 103 | this->bounds() = {{{0, 0}, {0, 0}}}; 104 | 105 | this->options().insert( 106 | this->options().end(), 107 | { 108 | "attribution" 109 | } 110 | ); 111 | } 112 | } 113 | 114 | /********************* 115 | * precompiled types * 116 | *********************/ 117 | 118 | extern template class xw::xmaterialize; 119 | extern template class xw::xtransport>; 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /include/xleaflet/xzoom_control.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_ZOOM_CONTROL_HPP 11 | #define XLEAFLET_ZOOM_CONTROL_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "xwidgets/xcolor.hpp" 17 | #include "xwidgets/xmaterialize.hpp" 18 | #include "xwidgets/xwidget.hpp" 19 | 20 | #include "xcontrol.hpp" 21 | #include "xfeature_group.hpp" 22 | #include "xleaflet_config.hpp" 23 | 24 | namespace nl = nlohmann; 25 | 26 | namespace xlf 27 | { 28 | /******************************* 29 | * zoom_control declaration * 30 | *******************************/ 31 | 32 | template 33 | class xzoom_control : public xcontrol 34 | { 35 | public: 36 | 37 | using base_type = xcontrol; 38 | using derived_type = D; 39 | 40 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 41 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 42 | 43 | XPROPERTY(std::string, derived_type, zoom_in_text, "+"); 44 | XPROPERTY(std::string, derived_type, zoom_in_title, "Zoom in"); 45 | XPROPERTY(std::optional, derived_type, zoom_out_text, "-"); 46 | XPROPERTY(std::string, derived_type, zoom_out_title, "Zoom out"); 47 | 48 | protected: 49 | 50 | xzoom_control(); 51 | using base_type::base_type; 52 | 53 | private: 54 | 55 | void set_defaults(); 56 | }; 57 | 58 | using zoom_control = xw::xmaterialize; 59 | 60 | /******************************** 61 | * xzoom_control implementation * 62 | ********************************/ 63 | 64 | template 65 | inline void xzoom_control::serialize_state(nl::json& state, 66 | xeus::buffer_sequence& buffers) const 67 | { 68 | base_type::serialize_state(state, buffers); 69 | 70 | using xw::xwidgets_serialize; 71 | 72 | xwidgets_serialize(zoom_in_text(), state["zoom_in_text"], buffers); 73 | xwidgets_serialize(zoom_in_title(), state["zoom_in_title"], buffers); 74 | xwidgets_serialize(zoom_out_text(), state["zoom_out_text"], buffers); 75 | xwidgets_serialize(zoom_out_title(), state["zoom_out_title"], buffers); 76 | } 77 | 78 | template 79 | inline void xzoom_control::apply_patch(const nl::json& patch, 80 | const xeus::buffer_sequence& buffers) 81 | { 82 | base_type::apply_patch(patch, buffers); 83 | 84 | using xw::set_property_from_patch; 85 | 86 | set_property_from_patch(zoom_in_text, patch, buffers); 87 | set_property_from_patch(zoom_in_title, patch, buffers); 88 | set_property_from_patch(zoom_out_text, patch, buffers); 89 | set_property_from_patch(zoom_out_title, patch, buffers); 90 | } 91 | 92 | template 93 | inline xzoom_control::xzoom_control() 94 | : base_type() 95 | { 96 | set_defaults(); 97 | } 98 | 99 | template 100 | inline void xzoom_control::set_defaults() 101 | { 102 | this->_model_name() = "LeafletZoomControlModel"; 103 | this->_view_name() = "LeafletZoomControlView"; 104 | } 105 | } 106 | 107 | /********************* 108 | * precompiled types * 109 | *********************/ 110 | 111 | extern template class xw::xmaterialize; 112 | extern template class xw::xtransport>; 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /include/xleaflet/xlayer.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, and Wolf Vollprecht * 3 | * * 4 | * Distributed under the terms of the BSD 3-Clause License. * 5 | * * 6 | * The full license is in the file LICENSE, distributed with this software. * 7 | *******************************************************************************/ 8 | 9 | #ifndef XLEAFLET_LAYER_HPP 10 | #define XLEAFLET_LAYER_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "xwidgets/xmaterialize.hpp" 17 | #include "xwidgets/xobject.hpp" 18 | 19 | #include "xleaflet_config.hpp" 20 | 21 | namespace nl = nlohmann; 22 | 23 | namespace xlf 24 | { 25 | /********************* 26 | * layer declaration * 27 | *********************/ 28 | 29 | template 30 | class xlayer : public xw::xobject 31 | { 32 | public: 33 | 34 | using base_type = xw::xobject; 35 | using derived_type = D; 36 | 37 | using widget_type = xw::xholder; 38 | 39 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 40 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 41 | 42 | XPROPERTY(std::string, derived_type, name, ""); 43 | XPROPERTY(bool, derived_type, base, true); 44 | XPROPERTY(bool, derived_type, bottom, true); 45 | XPROPERTY(std::optional, derived_type, popup); 46 | XPROPERTY(std::vector, derived_type, options); 47 | 48 | protected: 49 | 50 | xlayer(); 51 | using base_type::base_type; 52 | 53 | private: 54 | 55 | void set_defaults(); 56 | }; 57 | 58 | using layer = xw::xmaterialize; 59 | 60 | /************************* 61 | * xlayer implementation * 62 | *************************/ 63 | 64 | template 65 | inline void xlayer::serialize_state(nl::json& state, 66 | xeus::buffer_sequence& buffers) const 67 | { 68 | base_type::serialize_state(state, buffers); 69 | 70 | using xw::xwidgets_serialize; 71 | 72 | xwidgets_serialize(name(), state["name"], buffers); 73 | xwidgets_serialize(base(), state["base"], buffers); 74 | xwidgets_serialize(bottom(), state["bottom"], buffers); 75 | xwidgets_serialize(popup(), state["popup"], buffers); 76 | xwidgets_serialize(options(), state["options"], buffers); 77 | } 78 | 79 | template 80 | inline void xlayer::apply_patch(const nl::json& patch, 81 | const xeus::buffer_sequence& buffers) 82 | { 83 | base_type::apply_patch(patch, buffers); 84 | 85 | using xw::set_property_from_patch; 86 | 87 | set_property_from_patch(name, patch, buffers); 88 | set_property_from_patch(base, patch, buffers); 89 | set_property_from_patch(bottom, patch, buffers); 90 | set_property_from_patch(popup, patch, buffers); 91 | set_property_from_patch(options, patch, buffers); 92 | } 93 | 94 | template 95 | inline xlayer::xlayer() 96 | : base_type() 97 | { 98 | set_defaults(); 99 | } 100 | 101 | template 102 | inline void xlayer::set_defaults() 103 | { 104 | this->_model_module() = "jupyter-leaflet"; 105 | this->_view_module() = "jupyter-leaflet"; 106 | this->_model_name() = "LeafletLayerModel"; 107 | this->_view_name() = "LeafletLayerView"; 108 | this->_model_module_version() = jupyter_leaflet_semver(); 109 | this->_view_module_version() = jupyter_leaflet_semver(); 110 | 111 | this->options() = std::vector(); 112 | } 113 | 114 | } 115 | 116 | /********************* 117 | * precompiled types * 118 | *********************/ 119 | 120 | extern template class xw::xmaterialize; 121 | extern template class xw::xtransport>; 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /docs/source/api_reference/embed_widgets/fullscreen_control.html: -------------------------------------------------------------------------------- 1 | 111 | -------------------------------------------------------------------------------- /docs/source/api_reference/embed_widgets/wms_layer.html: -------------------------------------------------------------------------------- 1 | 126 | -------------------------------------------------------------------------------- /include/xleaflet/xwidget_control.hpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2018, Sylvain Corlay and Johan Mabille, Wolf Vollprecht and * 3 | * Martin Renou * 4 | * * 5 | * Distributed under the terms of the BSD 3-Clause License. * 6 | * * 7 | * The full license is in the file LICENSE, distributed with this software. * 8 | *******************************************************************************/ 9 | 10 | #ifndef XLEAFLET_WIDGET_CONTROL_HPP 11 | #define XLEAFLET_WIDGET_CONTROL_HPP 12 | 13 | #include 14 | #include 15 | 16 | #include "xwidgets/xholder.hpp" 17 | #include "xwidgets/xmaterialize.hpp" 18 | #include "xwidgets/xwidget.hpp" 19 | 20 | #include "xcontrol.hpp" 21 | 22 | namespace nl = nlohmann; 23 | 24 | namespace xlf 25 | { 26 | /****************************** 27 | * widget_control declaration * 28 | ******************************/ 29 | 30 | template 31 | class xwidget_control : public xcontrol 32 | { 33 | public: 34 | 35 | using base_type = xcontrol; 36 | using derived_type = D; 37 | 38 | using widget_type = xw::xholder; 39 | 40 | void serialize_state(nl::json&, xeus::buffer_sequence&) const; 41 | void apply_patch(const nl::json&, const xeus::buffer_sequence&); 42 | 43 | XPROPERTY(widget_type, derived_type, widget); 44 | XPROPERTY(std::optional, derived_type, max_width); 45 | XPROPERTY(std::optional, derived_type, min_width); 46 | XPROPERTY(std::optional, derived_type, max_height); 47 | XPROPERTY(std::optional, derived_type, min_height); 48 | 49 | protected: 50 | 51 | xwidget_control(); 52 | using base_type::base_type; 53 | 54 | private: 55 | 56 | void set_defaults(); 57 | }; 58 | 59 | using widget_control = xw::xmaterialize; 60 | 61 | /********************************** 62 | * xwidget_control implementation * 63 | **********************************/ 64 | 65 | template 66 | inline void xwidget_control::serialize_state(nl::json& state, 67 | xeus::buffer_sequence& buffers) const 68 | { 69 | base_type::serialize_state(state, buffers); 70 | 71 | using xw::xwidgets_serialize; 72 | 73 | xwidgets_serialize(widget(), state["widget"], buffers); 74 | xwidgets_serialize(max_width(), state["max_width"], buffers); 75 | xwidgets_serialize(min_width(), state["min_width"], buffers); 76 | xwidgets_serialize(max_height(), state["max_height"], buffers); 77 | xwidgets_serialize(min_height(), state["min_height"], buffers); 78 | } 79 | 80 | template 81 | inline void xwidget_control::apply_patch(const nl::json& patch, 82 | const xeus::buffer_sequence& buffers) 83 | { 84 | base_type::apply_patch(patch, buffers); 85 | 86 | using xw::set_property_from_patch; 87 | 88 | set_property_from_patch(widget, patch, buffers); 89 | set_property_from_patch(max_width, patch, buffers); 90 | set_property_from_patch(min_width, patch, buffers); 91 | set_property_from_patch(max_height, patch, buffers); 92 | set_property_from_patch(min_height, patch, buffers); 93 | } 94 | 95 | template 96 | inline xwidget_control::xwidget_control() 97 | : base_type() 98 | { 99 | set_defaults(); 100 | } 101 | 102 | template 103 | inline void xwidget_control::set_defaults() 104 | { 105 | this->_model_name() = "LeafletWidgetControlModel"; 106 | this->_view_name() = "LeafletWidgetControlView"; 107 | 108 | this->options().insert( 109 | this->options().end(), 110 | { 111 | "max_width", 112 | "min_width", 113 | "max_height", 114 | "min_height" 115 | } 116 | ); 117 | } 118 | } 119 | 120 | /********************* 121 | * precompiled types * 122 | *********************/ 123 | 124 | extern template class xw::xmaterialize; 125 | extern template class xw::xtransport>; 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /docs/source/usage.rst: -------------------------------------------------------------------------------- 1 | .. Copyright (c) 2017, Johan Mabille and Sylvain Corlay 2 | 3 | Distributed under the terms of the BSD 3-Clause License. 4 | 5 | The full license is in the file LICENSE, distributed with this software. 6 | 7 | Introduction 8 | ============ 9 | 10 | ``xleaflet`` is the C++ backend for the leaflet_ maps visualization library. The 11 | Python reference implementation is available in the ipyleaflet_ project. 12 | 13 | ``xleaflet`` depends on xwidgets_, each object that you can create in ``xleaflet`` 14 | is an xwidget instance which is synchronized with one or more views on the frontend. 15 | See the ``xwidgets`` documentation_ for the usage of widgets. 16 | 17 | Basic usage 18 | =========== 19 | 20 | Default map 21 | ----------- 22 | 23 | The default map can be displayed using Jupyter's display framework. 24 | 25 | .. code:: 26 | 27 | xlf::map map; 28 | map.display(); 29 | 30 | Changing widget attributes can be done from the model: 31 | 32 | .. code:: 33 | 34 | map.zoom = 15; 35 | 36 | // latitude 52.204793, longitude 360.121558 37 | map.center = std::array({52.204793, 360.121558}); 38 | 39 | Or by interacting directly with the view. 40 | 41 | The map widget works with a list of layers. Layers are instances of ``tile_layer``, ``marker``, ``popup``, ``wms_layer``, ``image_overlay``, 42 | ``video_overlay``, ``polygon``, ``rectangle``, ``circle_marker``, ``circle``, ``marker_cluster``, ``layer_group`` or ``geo_json``. 43 | 44 | .. code:: 45 | 46 | #include "xleaflet/xmap.hpp" 47 | 48 | xlf::map map; 49 | 50 | map.add_layer(marker); 51 | map.add_layer(circle); 52 | map.add_layer(layer_group); 53 | 54 | map.remove_layer(circle); 55 | 56 | map.clear_layers(); 57 | 58 | It is also possible to have a list of controls on the map. Controls are instances of ``layers_control``, ``split_map_control`` or ``draw_control``. 59 | 60 | .. code:: 61 | 62 | #include "xleaflet/xmap.hpp" 63 | 64 | xlf::map map; 65 | 66 | map.add_control(control1); 67 | map.add_control(control2); 68 | 69 | map.remove_control(control1); 70 | 71 | map.clear_controls(); 72 | 73 | Generator classes 74 | ================= 75 | 76 | Widgets such as ``map`` may have a large number of attributes that can be set by the user, such as ``center``, ``zoom``, ``min_zoom``, ``max_zoom``, ``scroll_wheel_zoom``, ``bounce_at_zoom_limits``, ``inertia``. 77 | 78 | Providing a constructor for ``map`` with a large number of such attributes would make the use of ``xleaflet`` very cumbersome, because users would need to know all the positional arguments to modify only one value. Instead, we mimick a keyword argument initialization with a method-chaining mechanism. 79 | 80 | .. code:: 81 | 82 | #include "xleaflet/xmap.hpp" 83 | 84 | auto map = xlf::map::initialize() 85 | .center({52.204793, 360.121558}) 86 | .zoom(15) 87 | .scroll_wheel_zoom(true) 88 | .inertia(false) 89 | .finalize(); 90 | 91 | Special Events 92 | ============== 93 | 94 | One could want to react on special map events like ``mousemove``, this can be achieved by using the ``on_interaction`` method of map: 95 | 96 | .. code:: 97 | 98 | #include 99 | 100 | #include "xleaflet/xmap.hpp" 101 | 102 | void print_mouse_position(xeus::xjson event) 103 | { 104 | if (event["type"] == "mousemove") 105 | { 106 | std::cout << "Mouse position: " << event["coordinates"].dump() << std::endl; 107 | } 108 | 109 | if (event["type"] == "mouseout") 110 | { 111 | std::cout << "Mouse out" << std::endl;; 112 | } 113 | } 114 | 115 | xlf::map map; 116 | 117 | map.on_interaction(print_mouse_position); 118 | map.display(); 119 | 120 | XProperty Events 121 | ================ 122 | 123 | ``xleaflet`` relies on the xproperty_ library, so that one could use the ``XOBSERVE`` function to react on model changes: 124 | 125 | .. code:: 126 | 127 | #include 128 | 129 | #include "xleaflet/xmap.hpp" 130 | 131 | void print_lat_lng(xlf::map& map) 132 | { 133 | std::string lat = std::to_string(map.center().front()); 134 | std::string lng = std::to_string(map.center().back()); 135 | 136 | std::cout << "latitude: " << lat << ", longitude: " << lng << std::endl; 137 | } 138 | 139 | xlf::map map; 140 | 141 | XOBSERVE(map, center, print_lat_lng); 142 | map.display(); 143 | 144 | 145 | .. _xproperty: https://github.com/jupyter-xeus/xproperty 146 | .. _documentation: https://github.com/jupyter-xeus/xwidgets/blob/master/docs/source/usage.rst 147 | .. _xwidgets: https://github.com/jupyter-xeus/xwidgets 148 | .. _leaflet: http://leafletjs.com/ 149 | .. _ipyleaflet: https://github.com/jupyter-widgets/ipyleaflet.git 150 | -------------------------------------------------------------------------------- /notebooks/Heatmap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "![xleaflet](images/xleaflet.png)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "

C++ backend for the jupyter-leaflet map visualization library

" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "

Heatmap

" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "#include \n", 31 | "#include \n", 32 | "#include \n", 33 | "#include \n", 34 | "#include \n", 35 | "\n", 36 | "#include \"xtensor/xarray.hpp\"\n", 37 | "#include \"xtensor/xview.hpp\"\n", 38 | "#include \"xtensor/xio.hpp\"\n", 39 | "\n", 40 | "#include \"xleaflet/xmap.hpp\"\n", 41 | "#include \"xleaflet/xheatmap.hpp\"" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "auto map = xlf::map::initialize()\n", 51 | " .center({37.58, 261.65})\n", 52 | " .zoom(5)\n", 53 | " .finalize();\n", 54 | "map" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "std::random_device rd;\n", 64 | "std::mt19937 mt(rd());\n", 65 | "std::uniform_real_distribution rd_latitude(34.0, 40.0);\n", 66 | "std::uniform_real_distribution rd_longitude(255.0, 265.0);\n", 67 | "std::uniform_real_distribution rd_intensity(0.0, 1000.0);" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "xt::xtensor locations({100, 3});" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": null, 82 | "metadata": {}, 83 | "outputs": [], 84 | "source": [ 85 | "auto lats = xt::view(locations, xt::all(), 0);\n", 86 | "auto lngs = xt::view(locations, xt::all(), 1);\n", 87 | "auto ints = xt::view(locations, xt::all(), 2);" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": null, 93 | "metadata": {}, 94 | "outputs": [], 95 | "source": [ 96 | "auto lats_it = lats.begin();\n", 97 | "auto lngs_it = lngs.begin();\n", 98 | "auto ints_it = ints.begin();\n", 99 | "\n", 100 | "for (; lats_it != lats.end(); ++lats_it, ++lngs_it, ++ints_it)\n", 101 | "{\n", 102 | " *lats_it = rd_latitude(mt);\n", 103 | " *lngs_it = rd_longitude(mt);\n", 104 | " *ints_it = rd_intensity(mt);\n", 105 | "}" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [ 114 | "xt::view(locations, 0)" 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "auto heatmap = xlf::heatmap::initialize()\n", 124 | " .locations(locations)\n", 125 | " .finalize();" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": null, 131 | "metadata": {}, 132 | "outputs": [], 133 | "source": [ 134 | "map.add_layer(heatmap);" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "for(std::size_t i = 0; i < 15; ++i)\n", 144 | "{\n", 145 | " ints -= 100;\n", 146 | " heatmap.locations = locations;\n", 147 | " std::this_thread::sleep_for(std::chrono::seconds(1));\n", 148 | "}" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "metadata": {}, 155 | "outputs": [], 156 | "source": [ 157 | "heatmap.radius = 20;" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "xt::view(locations, 0)" 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "kernelspec": { 172 | "display_name": "C++14", 173 | "language": "C++14", 174 | "name": "xcpp14" 175 | }, 176 | "language_info": { 177 | "codemirror_mode": "text/x-c++src", 178 | "file_extension": ".cpp", 179 | "mimetype": "text/x-c++src", 180 | "name": "c++", 181 | "version": "-std=c++14" 182 | } 183 | }, 184 | "nbformat": 4, 185 | "nbformat_minor": 4 186 | } 187 | --------------------------------------------------------------------------------