Skip to content

Commit

Permalink
Merge pull request #8 from Algunenano/carto_metrics
Browse files Browse the repository at this point in the history
Carto metrics
  • Loading branch information
Rafa de la Torre authored Jan 5, 2018
2 parents 3f22928 + 5f35237 commit ac45042
Show file tree
Hide file tree
Showing 15 changed files with 415 additions and 278 deletions.
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ test
benchmark
configure
Makefile
scripts
.travis.yml
appveyor.yml
examples
Expand Down
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ default: release
deps/geometry/include/mapbox/geometry.hpp:
git submodule update --init

mason_packages/.link/bin/mapnik-config: deps/geometry/include/mapbox/geometry.hpp
node_modules:
npm install --ignore-scripts --clang

mason_packages/.link/bin/mapnik-config:
./install_mason.sh

node_modules: mason_packages/.link/bin/mapnik-config
# install deps but for now ignore our own install script
# so that we can run it directly in either debug or release
npm install --ignore-scripts --clang
pre_build_check:
mapnik-config -v |>/dev/null

release: node_modules
PATH="./mason_packages/.link/bin/:${PATH}" && V=1 ./node_modules/.bin/node-pre-gyp configure build --loglevel=error --clang
release_base: pre_build_check deps/geometry/include/mapbox/geometry.hpp node_modules
V=1 ./node_modules/.bin/node-pre-gyp configure build --loglevel=error --clang
@echo "run 'make clean' for full rebuild"

debug: node_modules
PATH="./mason_packages/.link/bin/:${PATH}" && V=1 ./node_modules/.bin/node-pre-gyp configure build --loglevel=error --debug --clang
debug_base: pre_build_check deps/geometry/include/mapbox/geometry.hpp node_modules
V=1 ./node_modules/.bin/node-pre-gyp configure build --loglevel=error --debug --clang
@echo "run 'make clean' for full rebuild"

release: mason_packages/.link/bin/mapnik-config
PATH="./mason_packages/.link/bin/:${PATH}" $(MAKE) release_base

debug: mason_packages/.link/bin/mapnik-config
PATH="./mason_packages/.link/bin/:${PATH}" $(MAKE) debug_base

coverage:
./scripts/coverage.sh

Expand Down Expand Up @@ -49,6 +56,7 @@ docs:

test:
npm test
check: test

testpack:
rm -f ./*tgz
Expand Down
1 change: 0 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
'cflags_cc!': ['-fno-rtti', '-fno-exceptions'],
'cflags_cc' : [
'<!@(mapnik-config --cflags)',
'-D_GLIBCXX_USE_CXX11_ABI=0'
],
'libraries':[
'<!@(mapnik-config --libs)',
Expand Down
4 changes: 2 additions & 2 deletions gen_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def write_mapnik_settings(fonts='undefined',input_plugins='undefined'):
if ip:
settings_dict['input_plugins'] = ip
else:
settings_dict['input_plugins'] = '\'%s\'' % os.popen("./mason_packages/.link/bin/mapnik-config --input-plugins").readline().strip()
settings_dict['input_plugins'] = '\'%s\'' % os.popen("mapnik-config --input-plugins").readline().strip()

mf = os.environ.get('MAPNIK_FONTS')
if mf:
settings_dict['fonts'] = mf
else:
settings_dict['fonts'] = '\'%s\'' % os.popen("./mason_packages/.link/bin/mapnik-config --fonts").readline().strip()
settings_dict['fonts'] = '\'%s\'' % os.popen("mapnik-config --fonts").readline().strip()

write_mapnik_settings(**settings_dict)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"dependencies": {
"mapnik-vector-tile": "1.5.0",
"protozero": "1.5.1",
"nan": "~2.5.0",
"nan": "~2.7.0",
"node-pre-gyp": "~0.6.30"
},
"bundledDependencies": [
"node-pre-gyp"
"node-pre-gyp"
],
"bin": {
"mapnik-inspect.js": "./bin/mapnik-inspect.js",
Expand Down
19 changes: 19 additions & 0 deletions scripts/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ set -o pipefail
MODULE_PATH=./lib/binding
MAPNIK_SDK=./mason_packages/.link

# Check if we are using Mason's mapnik
if [[ ! "$(which mapnik-config)" -ef "$MAPNIK_SDK/bin/mapnik-config" ]]; then
echo "
var path = require('path');
module.exports.paths = {
'fonts': '$(mapnik-config --fonts)',
'input_plugins': '$(mapnik-config --input-plugins)',
'mapnik_index': '$(which mapnik-index)',
'shape_index': '$(which shapeindex)'
};
module.exports.env = {
'ICU_DATA': '$(mapnik-config --icu-data)',
'GDAL_DATA': '$(mapnik-config --gdal-data)',
'PROJ_LIB': '$(mapnik-config --proj-lib)'
};
" > ${MODULE_PATH}/mapnik_settings.js
exit 0;
fi

mkdir -p ${MODULE_PATH}/bin/

# the below switch is used since on osx the default cp
Expand Down
54 changes: 49 additions & 5 deletions src/mapnik_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Nan::Persistent<v8::FunctionTemplate> Grid::constructor;

/**
* **`mapnik.Grid`**
*
*
* Generator for [UTFGrid](https://www.mapbox.com/guides/an-open-platform)
* representations of data.
*
Expand Down Expand Up @@ -45,8 +45,11 @@ void Grid::Initialize(v8::Local<v8::Object> target) {
Nan::SetPrototypeMethod(lcons, "painted", painted);
Nan::SetPrototypeMethod(lcons, "clear", clear);
Nan::SetPrototypeMethod(lcons, "clearSync", clearSync);
Nan::SetPrototypeMethod(lcons, "get_metrics", get_metrics);

// properties
ATTR(lcons, "key", get_key, set_key);
ATTR(lcons, "metrics_enabled", get_metrics_enabled, set_metrics_enabled);

target->Set(Nan::New("Grid").ToLocalChecked(), lcons->GetFunction());
NODE_MAPNIK_DEFINE_64_BIT_CONSTANT(lcons->GetFunction(), "base_mask", mapnik::grid::base_mask);
Expand Down Expand Up @@ -186,7 +189,7 @@ void Grid::EIO_AfterClear(uv_work_t* req)
clear_grid_baton_t *closure = static_cast<clear_grid_baton_t *>(req->data);
if (closure->error)
{
// There seems to be no possible way for the exception to be thrown in the previous
// There seems to be no possible way for the exception to be thrown in the previous
// process and therefore not possible to have an error here so removing it from code
// coverage
/* LCOV_EXCL_START */
Expand Down Expand Up @@ -550,16 +553,16 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
encode_grid_baton_t *closure = static_cast<encode_grid_baton_t *>(req->data);


if (closure->error)
if (closure->error)
{
// There is no known ways to throw errors in the processing prior
// so simply removing the following from coverage
/* LCOV_EXCL_START */
v8::Local<v8::Value> argv[1] = { Nan::Error(closure->error_name.c_str()) };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv);
/* LCOV_EXCL_STOP */
}
else
}
else
{

// convert key order to proper javascript array
Expand Down Expand Up @@ -602,4 +605,45 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
delete closure;
}

NAN_GETTER(Grid::get_metrics_enabled)
{
#ifndef MAPNIK_METRICS
bool active = false;
#else
Grid* g = Nan::ObjectWrap::Unwrap<Grid>(info.Holder());
bool active = g->this_->metrics_.enabled_;
#endif
info.GetReturnValue().Set(Nan::New<v8::Boolean>(active));
}

NAN_SETTER(Grid::set_metrics_enabled)
{
#ifdef MAPNIK_METRICS
Grid* g = Nan::ObjectWrap::Unwrap<Grid>(info.Holder());
if (!value->IsBoolean())
{
Nan::ThrowError("Must provide a boolean");
}
else
{
bool val = value->BooleanValue();
g->this_->metrics_.enabled_ = val;
}
#endif
}

NAN_METHOD(Grid::get_metrics)
{
#ifdef MAPNIK_METRICS
Grid* g = Nan::ObjectWrap::Unwrap<Grid>(info.Holder());
auto result = node_mapnik::metrics_to_object(g->this_->metrics_);
if (!result.IsEmpty())
{
info.GetReturnValue().Set(result.ToLocalChecked());
return;
}
#endif
info.GetReturnValue().Set(Nan::New<v8::Object>());
}

#endif //Grid renderer
5 changes: 5 additions & 0 deletions src/mapnik_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class Grid: public Nan::ObjectWrap {

static NAN_GETTER(get_key);
static NAN_SETTER(set_key);

static NAN_GETTER(get_metrics_enabled); //false if MAPNIK_METRICS undefined
static NAN_SETTER(set_metrics_enabled);
static NAN_METHOD(get_metrics);

void _ref() { Ref(); }
void _unref() { Unref(); }

Expand Down
Loading

0 comments on commit ac45042

Please sign in to comment.