-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move on to Mapnik 3.x #9
base: master
Are you sure you want to change the base?
Changes from 7 commits
4b5b5fd
6448021
c89b672
6beda64
0cea398
528aa0f
d733725
e22edfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ libmapnik-jni.jnilib: $(SOURCE_DEPENDS) | |
$(JAVA_CFLAGS) \ | ||
mapnikjni.cpp \ | ||
$(LDFLAGS) \ | ||
$(MAPNIK_LIBS) -framework JavaVM | ||
$(JAVA_LDFLAGS) \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
$(MAPNIK_LIBS) | ||
|
||
clean: | ||
rm libmapnik-jni.jnilib | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,30 @@ JNIEXPORT jobject JNICALL Java_mapnik_Datasource_getParameters | |
|
||
for (mapnik::param_map::const_iterator iter=params.begin(); iter!=params.end(); iter++) { | ||
jstring key=env->NewStringUTF(iter->first.c_str()); | ||
boost::apply_visitor(translate_parameter_visitor(env, paramobject, key), iter->second); | ||
translate_parameter_visitor visitor(env, paramobject, key); | ||
// TODO - The call to visit() does not compile on MSVC 2015 (error C2783). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't compile on OS X, either. I'm not sure if I am even supposed to call |
||
// The compiler cannot deduce the __formal type(?) in: | ||
// const T &mapnik::util::variant<mapnik::value_null, | ||
// mapnik::value_integer, | ||
// mapnik::value_double, | ||
// std::string, | ||
// mapnik::value_bool>::get(void) const | ||
// (ditto for the non-const version) | ||
// mapnik::value_type::visit(iter->second, visitor); | ||
// So, the variant<> types are temporarily unrolled here... | ||
if (iter->second.is<mapnik::value_integer>()) { | ||
visitor(iter->second.get<mapnik::value_integer>()); | ||
} | ||
else if (iter->second.is<mapnik::value_double>()) { | ||
visitor(iter->second.get<mapnik::value_double>()); | ||
} | ||
else if (iter->second.is<std::string>()) { | ||
visitor(iter->second.get<std::string>()); | ||
} | ||
else if (iter->second.is<mapnik::value_bool>()) { | ||
visitor(iter->second.get<mapnik::value_bool>()); | ||
} | ||
// else: value_null or unexpected value - ignore | ||
} | ||
|
||
return paramobject; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,12 @@ JNIEXPORT jobjectArray JNICALL Java_mapnik_FeatureSet__1loadGeometries | |
return 0; | ||
} | ||
|
||
unsigned count=(*fp)->num_geometries(); | ||
// Mapnik 3.x only holds one geometry<> per feature_impl. | ||
// (In Mapnik 2.x this used to be a variable-length vector of geometries.) | ||
unsigned count=1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm not misunderstanding things here, the JNI interface should be refactored to match the new C++ interface – but I didn't want to expand the scope of this PR for something that I'm not really sure about (I only want to render maps 😅). |
||
jobjectArray ret=env->NewObjectArray(count, CLASS_GEOMETRY, (jobject)0); | ||
for (unsigned index=0; index<count; index++) { | ||
mapnik::geometry_type &g((*fp)->get_geometry(index)); | ||
mapnik::geometry::geometry<double> const &g((*fp)->get_geometry()); | ||
jobject gobject=env->NewObject(CLASS_GEOMETRY, CTOR_NATIVEOBJECT); | ||
env->SetLongField(gobject, FIELD_PTR, FROM_POINTER(&g)); | ||
env->SetObjectArrayElement(ret, index, gobject); | ||
|
@@ -128,50 +130,43 @@ JNIEXPORT jobject JNICALL Java_mapnik_FeatureSet_getPropertyNames | |
mapnik::feature_impl::iterator end = (*fp)->end(); | ||
for ( ;itr!=end; ++itr) | ||
{ | ||
std::string const& name(boost::get<0>(*itr)); | ||
std::string const& name(std::get<0>(*itr)); | ||
env->CallBooleanMethod(ret, METHOD_HASHSET_ADD, env->NewStringUTF(name.c_str())); | ||
} | ||
|
||
return ret; | ||
TRAILER(0); | ||
} | ||
|
||
// http://en.wikipedia.org/wiki/Java_Native_Interface#Mapping_types | ||
#if MAPNIK_VERSION >= 200200 | ||
typedef mapnik::value_integer value_integer; | ||
#else | ||
typedef int value_integer; | ||
#endif | ||
|
||
class value_to_java: public boost::static_visitor<jobject> { | ||
JNIEnv* env; | ||
public: | ||
value_to_java(JNIEnv* aenv): env(aenv) { | ||
} | ||
|
||
|
||
jobject operator()(value_integer value) const { | ||
jobject operator()(mapnik::value_integer value) const { | ||
#ifdef BIGINT | ||
return env->CallStaticObjectMethod(CLASS_LONG, METHOD_LONG_VALUEOF, value); | ||
#else | ||
return env->CallStaticObjectMethod(CLASS_INTEGER, METHOD_INTEGER_VALUEOF, value); | ||
#endif | ||
} | ||
|
||
jobject operator()(bool value) const { | ||
jobject operator()(mapnik::value_bool value) const { | ||
return env->CallStaticObjectMethod(CLASS_BOOLEAN, METHOD_BOOLEAN_VALUEOF, value); | ||
} | ||
|
||
jobject operator()(double value) const { | ||
jobject operator()(mapnik::value_double value) const { | ||
return env->CallStaticObjectMethod(CLASS_DOUBLE, METHOD_DOUBLE_VALUEOF, value); | ||
} | ||
|
||
jobject operator()(std::string const& value) const { | ||
return env->NewStringUTF(value.c_str()); | ||
} | ||
|
||
jobject operator()(icu::UnicodeString const& value) const { | ||
return env->NewString(value.getBuffer(), value.length()); | ||
jobject operator()(mapnik::value_unicode_string const& value) const { | ||
return env->NewString(reinterpret_cast<const jchar*>(value.getBuffer()), value.length()); | ||
} | ||
|
||
jobject operator()(mapnik::value_null const& value) const { | ||
|
@@ -198,7 +193,7 @@ JNIEXPORT jobject JNICALL Java_mapnik_FeatureSet_getProperty | |
|
||
// Convert the value | ||
mapnik::value_type const& value= (*fp)->get(name.stringz); | ||
return boost::apply_visitor(value_to_java(env), value.base()); | ||
return mapnik::value_type::visit(value, value_to_java(env)); | ||
TRAILER(0); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,27 @@ JNIEXPORT jint JNICALL Java_mapnik_Geometry_getType | |
(JNIEnv *env, jobject gobj) | ||
{ | ||
PREAMBLE; | ||
mapnik::geometry_type* g=LOAD_GEOMETRY_POINTER(gobj); | ||
return g->type(); | ||
mapnik::geometry::geometry<double>* g=LOAD_GEOMETRY_POINTER(gobj); | ||
return mapnik::geometry::geometry_type(*g); | ||
TRAILER(0); | ||
} | ||
|
||
|
||
struct VertexCollector | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I'm trying to do here is to collect all the vertices in an arbitrary |
||
{ | ||
std::vector<std::tuple<unsigned, double, double>> vertices; | ||
|
||
template<typename T> | ||
void operator()(const T &vertex_adapter) | ||
{ | ||
unsigned command; | ||
double x, y; | ||
while ((command = vertex_adapter.vertex(&x, &y)) != mapnik::SEG_END) | ||
vertices.push_back(std::make_tuple(command, x, y)); | ||
} | ||
}; | ||
|
||
|
||
/* | ||
* Class: mapnik_Geometry | ||
* Method: getNumPoints | ||
|
@@ -22,12 +38,13 @@ JNIEXPORT jint JNICALL Java_mapnik_Geometry_getNumPoints | |
(JNIEnv *env, jobject gobj) | ||
{ | ||
PREAMBLE; | ||
mapnik::geometry_type* g=LOAD_GEOMETRY_POINTER(gobj); | ||
#if MAPNIK_VERSION >= 200100 | ||
return g->size(); | ||
#else | ||
return g->num_points(); | ||
#endif | ||
mapnik::geometry::geometry<double>* g = LOAD_GEOMETRY_POINTER(gobj); | ||
|
||
VertexCollector vertex_collector; | ||
mapnik::geometry::vertex_processor<VertexCollector> processor(vertex_collector); | ||
processor(*g); | ||
|
||
return vertex_collector.vertices.size(); | ||
TRAILER(0); | ||
} | ||
|
||
|
@@ -40,20 +57,19 @@ JNIEXPORT jint JNICALL Java_mapnik_Geometry_getVertex | |
(JNIEnv *env, jobject gobj, jint pos, jobject coord) | ||
{ | ||
PREAMBLE; | ||
mapnik::geometry_type* g=LOAD_GEOMETRY_POINTER(gobj); | ||
double x=0, y=0; | ||
#if MAPNIK_VERSION >= 200100 | ||
unsigned ret=g->vertex(pos, &x, &y); | ||
#else | ||
unsigned ret=g->get_vertex(pos, &x, &y); | ||
#endif | ||
mapnik::geometry::geometry<double>* g=LOAD_GEOMETRY_POINTER(gobj); | ||
|
||
VertexCollector vertex_collector; | ||
mapnik::geometry::vertex_processor<VertexCollector> processor(vertex_collector); | ||
processor(*g); | ||
const std::tuple<unsigned, double, double> &command_and_coords = vertex_collector.vertices.at(pos); | ||
|
||
if (coord) { | ||
env->SetDoubleField(coord, FIELD_COORD_X, x); | ||
env->SetDoubleField(coord, FIELD_COORD_Y, y); | ||
env->SetDoubleField(coord, FIELD_COORD_X, std::get<1>(command_and_coords)); | ||
env->SetDoubleField(coord, FIELD_COORD_Y, std::get<2>(command_and_coords)); | ||
} | ||
|
||
return ret; | ||
return std::get<0>(command_and_coords); | ||
TRAILER(0); | ||
} | ||
|
||
|
@@ -66,8 +82,8 @@ JNIEXPORT jobject JNICALL Java_mapnik_Geometry_getEnvelope | |
(JNIEnv *env, jobject gobj) | ||
{ | ||
PREAMBLE; | ||
mapnik::geometry_type* g=LOAD_GEOMETRY_POINTER(gobj); | ||
return box2dFromNative(env, g->envelope()); | ||
mapnik::geometry::geometry<double>* g=LOAD_GEOMETRY_POINTER(gobj); | ||
return box2dFromNative(env, mapnik::geometry::envelope(*g)); | ||
TRAILER(0); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only actually tested this with Oracle's Java 8 VM on both OS X and Windows, which complained about
source="1.5"
(warnings). Maybe it would be better to update this to 1.8 or drop thesource
parameter altogether? I am not an Ant or JVM expert.