Beispiel #1
0
static void describe_datasource(Local<Object> description, mapnik::datasource_ptr ds)
{
    NanScope();
    try
    {
        // type
        if (ds->type() == mapnik::datasource::Raster)
        {
            description->Set(NanNew("type"), NanNew<String>("raster"));
        }
        else
        {
            description->Set(NanNew("type"), NanNew<String>("vector"));
        }

        mapnik::layer_descriptor ld = ds->get_descriptor();

        // encoding
        description->Set(NanNew("encoding"), NanNew<String>(ld.get_encoding().c_str()));

        // field names and types
        Local<Object> fields = NanNew<Object>();
        std::vector<mapnik::attribute_descriptor> const& desc = ld.get_descriptors();
        std::vector<mapnik::attribute_descriptor>::const_iterator itr = desc.begin();
        std::vector<mapnik::attribute_descriptor>::const_iterator end = desc.end();
        while (itr != end)
        {
            unsigned field_type = itr->get_type();
            std::string type("");
            if (field_type == mapnik::Integer) type = "Number";
            else if (field_type == mapnik::Float) type = "Number";
            else if (field_type == mapnik::Double) type = "Number";
            else if (field_type == mapnik::String) type = "String";
            else if (field_type == mapnik::Boolean) type = "Boolean";
            else if (field_type == mapnik::Geometry) type = "Geometry";
            else if (field_type == mapnik::Object) type = "Object";
            else type = "Unknown";
            fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str()));
            fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str()));
            ++itr;
        }
        description->Set(NanNew("fields"), fields);

        Local<String> js_type = NanNew<String>("unknown");
        if (ds->type() == mapnik::datasource::Raster)
        {
            js_type = NanNew<String>("raster");
        }
        else
        {
            boost::optional<mapnik::datasource::geometry_t> geom_type = ds->get_geometry_type();
            if (geom_type)
            {
                mapnik::datasource::geometry_t g_type = *geom_type;
                switch (g_type)
                {
                case mapnik::datasource::Point:
                {
                    js_type = NanNew<String>("point");
                    break;
                }
                case mapnik::datasource::LineString:
                {
                    js_type = NanNew<String>("linestring");
                    break;
                }
                case mapnik::datasource::Polygon:
                {
                    js_type = NanNew<String>("polygon");
                    break;
                }
                case mapnik::datasource::Collection:
                {
                    js_type = NanNew<String>("collection");
                    break;
                }
                default:
                {
                    break;
                }
                }
            }
        }
        description->Set(NanNew("geometry_type"), js_type);
    }
    catch (std::exception const& ex)
    {
        NanThrowError(ex.what());
    }
    catch (...)
    {
        NanThrowError("unknown exception happened when calling describe_datasource, please file bug");
    }
}
Beispiel #2
0
static void describe_datasource(v8::Local<v8::Object> description, mapnik::datasource_ptr ds)
{
    Nan::HandleScope scope;
    
    // type
    if (ds->type() == mapnik::datasource::Raster)
    {
        description->Set(Nan::New("type").ToLocalChecked(), Nan::New<v8::String>("raster").ToLocalChecked());
    }
    else
    {
        description->Set(Nan::New("type").ToLocalChecked(), Nan::New<v8::String>("vector").ToLocalChecked());
    }

    mapnik::layer_descriptor ld = ds->get_descriptor();

    // encoding
    description->Set(Nan::New("encoding").ToLocalChecked(), Nan::New<v8::String>(ld.get_encoding().c_str()).ToLocalChecked());

    // field names and types
    v8::Local<v8::Object> fields = Nan::New<v8::Object>();
    node_mapnik::get_fields(fields, ds);
    description->Set(Nan::New("fields").ToLocalChecked(), fields);

    v8::Local<v8::String> js_type = Nan::New<v8::String>("unknown").ToLocalChecked();
    if (ds->type() == mapnik::datasource::Raster)
    {
        js_type = Nan::New<v8::String>("raster").ToLocalChecked();
    }
    else
    {
        boost::optional<mapnik::datasource_geometry_t> geom_type = ds->get_geometry_type();
        if (geom_type)
        {
            mapnik::datasource_geometry_t g_type = *geom_type;
            switch (g_type)
            {
            case mapnik::datasource_geometry_t::Point:
            {
                js_type = Nan::New<v8::String>("point").ToLocalChecked();
                break;
            }
            case mapnik::datasource_geometry_t::LineString:
            {
                js_type = Nan::New<v8::String>("linestring").ToLocalChecked();
                break;
            }
            case mapnik::datasource_geometry_t::Polygon:
            {
                js_type = Nan::New<v8::String>("polygon").ToLocalChecked();
                break;
            }
            case mapnik::datasource_geometry_t::Collection:
            {
                js_type = Nan::New<v8::String>("collection").ToLocalChecked();
                break;
            }
            default:
            {
                break;
            }
            }
        }
    }
    description->Set(Nan::New("geometry_type").ToLocalChecked(), js_type);
    for (auto const& param : ld.get_extra_parameters()) 
    {
        node_mapnik::params_to_object(description,param.first, param.second);
    }
}