Ejemplo n.º 1
0
Handle<Value> OsmMapJs::getElement(const Arguments& args)
{
  HandleScope scope;

  try
  {
    OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());

    LOG_VAR(args[0]->ToObject());
    ElementId eid = toCpp<ElementId>(args[0]);

    if (obj->isConst())
    {
      return scope.Close(toV8(obj->getConstMap()->getElement(eid)));
    }
    else
    {
      return scope.Close(toV8(obj->getMap()->getElement(eid)));
    }
  }
  catch (const HootException& e)
  {
    return v8::ThrowException(HootExceptionJs::create(e));
  }
}
Ejemplo n.º 2
0
Handle<Value> OsmMapJs::getElementCount(const Arguments& args) {
  HandleScope scope;

  OsmMapJs* obj = ObjectWrap::Unwrap<OsmMapJs>(args.This());

  return scope.Close(Number::New(obj->getConstMap()->getElementCount()));
}
Ejemplo n.º 3
0
Handle<Value> FeatureExtractorJs::extract(const Arguments& args) {
  HandleScope scope;

  FeatureExtractorJs* feJs = ObjectWrap::Unwrap<FeatureExtractorJs>(args.This());

  if (args.Length() != 3)
  {
    throw IllegalArgumentException("Expected exactly three argument in extract (map, e1, e2)");
  }

  OsmMapJs* mapJs = ObjectWrap::Unwrap<OsmMapJs>(args[0]->ToObject());
  ElementJs* e1Js = ObjectWrap::Unwrap<ElementJs>(args[1]->ToObject());
  ElementJs* e2Js = ObjectWrap::Unwrap<ElementJs>(args[2]->ToObject());

  double result = feJs->getFeatureExtractor()->extract(
        *(mapJs->getConstMap()),
        e1Js->getConstElement(),
        e2Js->getConstElement());

  if (result == feJs->getFeatureExtractor()->nullValue())
  {
    return scope.Close(Null());
  }
  else
  {
    return scope.Close(Number::New(result));
  }
}
Handle<Value> SublineStringMatcherJs::findMatch(const Arguments& args)
{
    HandleScope scope;

    SublineStringMatcherJs* smJs = ObjectWrap::Unwrap<SublineStringMatcherJs>(args.This());

    if (args.Length() != 3)
    {
        throw IllegalArgumentException("Expected exactly three argument in findMatch (map, e1, e2)");
    }

    OsmMapJs* mapJs = ObjectWrap::Unwrap<OsmMapJs>(args[0]->ToObject());
    ElementJs* e1Js = ObjectWrap::Unwrap<ElementJs>(args[1]->ToObject());
    ElementJs* e2Js = ObjectWrap::Unwrap<ElementJs>(args[2]->ToObject());

    WaySublineMatchString match = smJs->getSublineStringMatcher()->findMatch(
                                      mapJs->getConstMap(),
                                      e1Js->getConstElement(),
                                      e2Js->getConstElement());

    WaySublineMatchStringPtr result(new WaySublineMatchString(match));

    return scope.Close(WaySublineMatchStringJs::New(result));
}
Handle<Value> SublineStringMatcherJs::extractMatchingSublines(const Arguments& args)
{
    HandleScope scope;

    SublineStringMatcherJs* smJs = ObjectWrap::Unwrap<SublineStringMatcherJs>(args.This());
    SublineStringMatcherPtr sm = smJs->getSublineStringMatcher();

    OsmMapJs* mapJs = ObjectWrap::Unwrap<OsmMapJs>(args[0]->ToObject());
    ElementJs* e1Js = ObjectWrap::Unwrap<ElementJs>(args[1]->ToObject());
    ElementJs* e2Js = ObjectWrap::Unwrap<ElementJs>(args[2]->ToObject());
    ConstOsmMapPtr m = mapJs->getConstMap();
    ConstElementPtr e1 = e1Js->getConstElement();
    ConstElementPtr e2 = e2Js->getConstElement();

    Handle<Value> result;

    try
    {
        WaySublineMatchString match = sm->findMatch(m, e1, e2);

        if (match.isEmpty())
        {
            return Undefined();
        }

        // convert match into elements in a new map.
        set<ElementId> eids;
        eids.insert(e1->getElementId());
        eids.insert(e2->getElementId());
        OsmMapPtr copiedMap(new OsmMap(m->getProjection()));
        CopySubsetOp(m, eids).apply(copiedMap);
        WaySublineMatchString copiedMatch(match, copiedMap);

        // split the shared line based on the matching subline
        ElementPtr match1, scraps1;
        ElementPtr match2, scraps2;
        WaySublineString string1 = copiedMatch.getSublineString1();
        WaySublineString string2 = copiedMatch.getSublineString2();

        try
        {
            MultiLineStringSplitter().split(copiedMap, string1, copiedMatch.getReverseVector1(), match1,
                                            scraps1);
            MultiLineStringSplitter().split(copiedMap, string2, copiedMatch.getReverseVector2(), match2,
                                            scraps2);
        }
        catch (const IllegalArgumentException& e)
        {
            // this is unusual print out some information useful to debugging.
            MapReprojector::reprojectToWgs84(copiedMap);
            LOG_WARN(OsmWriter::toString(copiedMap));
            throw e;
        }

        if (!match1 || !match2)
        {
            result = Undefined();
        }
        else
        {
            Handle<Object> obj = Object::New();
            obj->Set(String::NewSymbol("map"), OsmMapJs::create(copiedMap));
            obj->Set(String::NewSymbol("match1"), ElementJs::New(match1));
            obj->Set(String::NewSymbol("match2"), ElementJs::New(match2));
            result = obj;
        }
    }
    catch (const HootException& e)
    {
        return v8::ThrowException(HootExceptionJs::create(e));
    }

    return scope.Close(result);
}