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

GeoJSON


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

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

In [ ]:
auto black_and_white = xlf::basemap({"OpenStreetMap", "BlackAndWhite"});

auto map = xlf::map_generator()
    .layers({black_and_white})
    .center({34.6252978589571, -77.34580993652344})
    .zoom(10)
    .finalize();

map

 Load a local json file


In [ ]:
std::ifstream file("geo.json");
xeus::xjson geo_data;
file >> geo_data;

In [ ]:
for (auto& feature: geo_data["features"])
{
    feature["properties"]["style"] = {
        {"weight", 1},
        {"fillOpacity", 0.5}
    };
}

In [ ]:
void print_event_callback(xeus::xjson event)
{
    std::cout << event.dump(4);
}

In [ ]:
auto geo_json = xlf::geo_json_generator()
    .data(geo_data)
    .finalize();
// geo_json.on_hover(print_event_callback);
// geo_json.on_click(print_event_callback);
map.add_layer(geo_json);