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

Draw control


In [ ]:
#include <iostream>
#include <string>

#include "xleaflet/xmap.hpp"
#include "xleaflet/xdraw_control.hpp"
#include "xleaflet/xbasemaps.hpp"

In [ ]:
auto water_color = xlf::basemap({"Stamen", "Watercolor"});

auto map = xlf::map_generator()
    .layers({water_color})
    .center({50, 354})
    .zoom(5)
    .finalize();

map

Set some options for draw control


In [ ]:
xeus::xjson polyline_options = {
    {"shapeOptions", {
        {"color", "#6bc2e5"},
        {"weight", 8},
        {"opacity", 1.0}
    }}
};

xeus::xjson polygon_options = {
    {"shapeOptions", {
        {"fillColor", "#6be5c3"},
        {"color", "#6be5c3"},
        {"fillOpacity", 1.0}
    }},
    {"drawError", {
        {"color", "#dd253b"},
        {"message", "Oups!"}
    }},
    {"allowIntersection", false}
};

xeus::xjson circle_options = {
    {"shapeOptions", {
        {"fillColor", "#efed69"},
        {"fillOpacity", 1.0},
        {"color", "#efed69"}
    }}
};

xeus::xjson rectangle_options = {
    {"shapeOptions", {
        {"fillColor", "#fca45d"},
        {"fillOpacity", 1.0},
        {"color", "#fca45d"}
    }}
};

In [ ]:
void print_event(std::string action, xeus::xjson geo_json)
{
    std::cout << action << " a " 
        << geo_json["geometry"]["type"]
        << std::endl;
}

Create the draw_control with the options


In [ ]:
auto draw_control = xlf::draw_control_generator()
    .polyline(polyline_options)
    .polygon(polygon_options)
    .circle(circle_options)
    .rectangle(rectangle_options)
    .finalize();

draw_control.on_draw(print_event);
map.add_control(draw_control);

In [ ]:
std::cout << draw_control.last_action() << std::endl;

In [ ]:
std::cout << draw_control.last_draw() << std::endl;