diff --git a/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp b/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp
index ac738d0..4aafcfe 100644
--- a/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp
+++ b/hoot-js/src/main/cpp/hoot/js/elements/OsmMapJs.cpp
@@ -30,7 +30,7 @@
// hoot
#include <hoot/core/ops/RemoveElementByEid.h>
-#include <hoot/core/elements/OsmUtils.h>
+#include <hoot/core/elements/RelationMemberUtils.h>
#include <hoot/js/JsRegistrar.h>
#include <hoot/js/SystemNodeJs.h>
#include <hoot/js/elements/ElementIdJs.h>
@@ -39,6 +39,9 @@
#include <hoot/js/io/StreamUtilsJs.h>
#include <hoot/js/visitors/ElementVisitorJs.h>
#include <hoot/js/visitors/JsFunctionVisitor.h>
+#include <hoot/core/conflate/merging/CollectionRelationMerger.h>
+#include <hoot/core/elements/RelationMemberNodeCounter.h>
+#include <hoot/core/elements/ConnectedRelationMemberFinder.h>
using namespace v8;
@@ -96,6 +99,15 @@ void OsmMapJs::Init(Handle<Object> target)
tpl->PrototypeTemplate()->Set(
String::NewFromUtf8(current, "isMemberOfRelationWithTagKey"),
FunctionTemplate::New(current, isMemberOfRelationWithTagKey));
+ tpl->PrototypeTemplate()->Set(
+ String::NewFromUtf8(current, "mergeCollectionRelations"),
+ FunctionTemplate::New(current, mergeCollectionRelations));
+ tpl->PrototypeTemplate()->Set(
+ String::NewFromUtf8(current, "getNumRelationMemberNodes"),
+ FunctionTemplate::New(current, getNumRelationMemberNodes));
+ tpl->PrototypeTemplate()->Set(
+ String::NewFromUtf8(current, "relationsHaveConnectedWayMembers"),
+ FunctionTemplate::New(current, relationsHaveConnectedWayMembers));
tpl->PrototypeTemplate()->Set(PopulateConsumersJs::baseClass(),
String::NewFromUtf8(current, OsmMap::className().data()));
@@ -121,9 +133,7 @@ void OsmMapJs::setIdGenerator(const FunctionCallbackInfo<Value>& args)
HandleScope scope(current);
OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());
-
std::shared_ptr<IdGenerator> idGen = toCpp<std::shared_ptr<IdGenerator>>(args[0]);
-
if (obj->getMap())
{
obj->getMap()->setIdGenerator(idGen);
@@ -193,7 +203,6 @@ void OsmMapJs::getElement(const FunctionCallbackInfo<Value>& args)
OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());
ElementId eid = toCpp<ElementId>(args[0]);
-
if (obj->isConst())
{
args.GetReturnValue().Set(toV8(obj->getConstMap()->getElement(eid)));
@@ -227,7 +236,6 @@ void OsmMapJs::getParents(const FunctionCallbackInfo<Value>& args)
try
{
OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());
-
ElementId eid = toCpp<ElementId>(args[0]->ToObject());
args.GetReturnValue().Set(toV8(obj->getConstMap()->getParents(eid)));
@@ -244,7 +252,6 @@ void OsmMapJs::removeElement(const FunctionCallbackInfo<Value>& args)
HandleScope scope(current);
OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());
-
ElementId eid = toCpp<ElementId>(args[0]);
RemoveElementByEid::removeElement(obj->getMap(), eid);
@@ -273,7 +280,7 @@ void OsmMapJs::visit(const FunctionCallbackInfo<Value>& args)
else
{
std::shared_ptr<ElementVisitor> v =
- ObjectWrap::Unwrap<ElementVisitorJs>(args[0]->ToObject())->getVisitor();
+ ObjectWrap::Unwrap<ElementVisitorJs>(args[0]->ToObject())->getVisitor();
map->getMap()->visitRw(*v);
}
@@ -281,7 +288,7 @@ void OsmMapJs::visit(const FunctionCallbackInfo<Value>& args)
}
catch (const HootException& err)
{
- LOG_VAR(err.getWhat());
+ LOG_VARE(err.getWhat());
args.GetReturnValue().Set(current->ThrowException(HootExceptionJs::create(err)));
}
}
@@ -296,7 +303,7 @@ void OsmMapJs::isMemberOfRelationType(const FunctionCallbackInfo<Value>& args)
QString relationType = toCpp<QString>(args[1]);
const bool inRelationOfSpecifiedType =
- OsmUtils::isMemberOfRelationType(mapJs->getConstMap(), childId, relationType);
+ RelationMemberUtils::isMemberOfRelationType(mapJs->getConstMap(), childId, relationType);
args.GetReturnValue().Set(Boolean::New(current, inRelationOfSpecifiedType));
}
@@ -311,7 +318,8 @@ void OsmMapJs::isMemberOfRelationInCategory(const FunctionCallbackInfo<Value>& a
QString schemaCategory = toCpp<QString>(args[1]);
const bool inRelationOfSpecifiedCategory =
- OsmUtils::isMemberOfRelationInCategory(mapJs->getConstMap(), childId, schemaCategory);
+ RelationMemberUtils::isMemberOfRelationInCategory(
+ mapJs->getConstMap(), childId, schemaCategory);
args.GetReturnValue().Set(Boolean::New(current, inRelationOfSpecifiedCategory));
}
@@ -326,9 +334,77 @@ void OsmMapJs::isMemberOfRelationWithTagKey(const FunctionCallbackInfo<Value>& a
QString tagKey = toCpp<QString>(args[1]);
const bool inRelationWithSpecifiedTagKey =
- OsmUtils::isMemberOfRelationWithTagKey(mapJs->getConstMap(), childId, tagKey);
+ RelationMemberUtils::isMemberOfRelationWithTagKey(mapJs->getConstMap(), childId, tagKey);
args.GetReturnValue().Set(Boolean::New(current, inRelationWithSpecifiedTagKey));
}
+void OsmMapJs::mergeCollectionRelations(const FunctionCallbackInfo<Value>& args)
+{
+ Isolate* current = args.GetIsolate();
+ HandleScope scope(current);
+
+ OsmMapJs* mapJs = ObjectWrap::Unwrap<OsmMapJs>(args.This());
+ ElementId elementId1 = toCpp<ElementId>(args[0]);
+ ElementId elementId2 = toCpp<ElementId>(args[1]);
+
+ CollectionRelationMerger merger;
+ merger.setOsmMap(mapJs->getMap().get());
+ try
+ {
+ merger.merge(elementId1, elementId2);
+
+ args.GetReturnValue().SetUndefined();
+ }
+ catch (const HootException& err)
+ {
+ LOG_VARE(err.getWhat());
+ args.GetReturnValue().Set(current->ThrowException(HootExceptionJs::create(err)));
+ }
+}
+
+void OsmMapJs::getNumRelationMemberNodes(const FunctionCallbackInfo<Value>& args)
+{
+ Isolate* current = args.GetIsolate();
+ HandleScope scope(current);
+
+ OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());
+ ConstOsmMapPtr map = obj->getConstMap();
+ ElementId relationId = toCpp<ElementId>(args[0]);
+ ConstRelationPtr relation = map->getRelation(relationId.getId());
+ int numNodes = -1;
+ if (relation)
+ {
+ RelationMemberNodeCounter counter;
+ counter.setOsmMap(map.get());
+ numNodes = counter.numNodes(relation);
+ }
+ args.GetReturnValue().Set(Number::New(current, numNodes));
+}
+
+void OsmMapJs::relationsHaveConnectedWayMembers(const FunctionCallbackInfo<Value>& args)
+{
+ Isolate* current = args.GetIsolate();
+ HandleScope scope(current);
+
+ OsmMapJs* mapJs = ObjectWrap::Unwrap<OsmMapJs>(args.This());
+ ElementId relationId1 = toCpp<ElementId>(args[0]);
+ ElementId relationId2 = toCpp<ElementId>(args[1]);
+ if (relationId1.getType() != ElementType::Relation ||
+ relationId2.getType() != ElementType::Relation)
+ {
+ throw IllegalArgumentException(
+ "Passed non-relation ID to relationsHaveConnectedWayMembers.");
+ }
+ ConstOsmMapPtr map = mapJs->getConstMap();
+
+ ConnectedRelationMemberFinder finder;
+ finder.setOsmMap(map.get());
+ args.GetReturnValue().Set(
+ Boolean::New(
+ current,
+ finder.haveConnectedWayMembers(
+ map->getRelation(relationId1.getId()), map->getRelation(relationId2.getId()))));
+}
+
}