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


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

#include "xleaflet/xmap.hpp"
#include "xleaflet/xtile_layer.hpp"
#include "xleaflet/xmarker.hpp"
#include "xleaflet/xmarker_cluster.hpp"
#include "xleaflet/xbasemaps.hpp"

#include "xwidgets/xbox.hpp"
#include "xwidgets/xtext.hpp"
#include "xwidgets/xlabel.hpp"

In [ ]:
auto map = xlf::map_generator()
    .center({50, 354})
    .zoom(5)
    .finalize();

xw::vbox vbox;
xw::hbox hbox1, hbox2;
xw::label label1, label2;
xw::text center, mouse_position;

center.disabled = true;
mouse_position.disabled = true;

vbox.add(map);
vbox.add(hbox1);
vbox.add(hbox2);

label1.value = "Center:";
center.value = "[50.0, 354.0]";
hbox1.add(label1);
hbox1.add(center);

label2.value = "Mouse position:";
mouse_position.value = "Mouse out";
hbox2.add(label2);
hbox2.add(mouse_position);

vbox

In [ ]:
void update_center(xlf::map& map)
{
    std::string lat = std::to_string(map.center().front());
    std::string lng = std::to_string(map.center().back());
    
    center.value = "[" + lat + ", " + lng + "]";
}

XOBSERVE(map, center, update_center);

In [ ]:
void update_mouse_position(xeus::xjson event)
{
    if (event["type"] == "mousemove")
    {
        mouse_position.value = event["coordinates"].dump();
    }
    
    if (event["type"] == "mouseout")
    {
        mouse_position.value = "Mouse out";
    }
}

map.on_interaction(update_mouse_position);

In [ ]:
// xlf::basemaps().dump(6)