Пример #1
0
Handle<Value> MSMap::New(const Arguments &args) {
  HandleScope scope;
  mapObj *map;
  MSMap *obj;

  if (!args.IsConstructCall())
    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

  if (args[0]->IsExternal()) {
    Local<External> ext = Local<External>::Cast(args[0]);
    void *ptr = ext->Value();
    MSMap *f =  static_cast<MSMap *>(ptr);
    f->Wrap(args.This());
    return args.This();
  }

  if (args.Length() == 2) {
    REQ_STR_ARG(0, mapfile);
    REQ_STR_ARG(1, mappath);
    map = msLoadMap(*mapfile, *mappath);
  } else if (args.Length() == 1) {
    REQ_STR_ARG(0, mapfile);
    map = msLoadMap(*mapfile, NULL);
  } else {
    map = msNewMapObj();
  }

  if (map == NULL) {
    THROW_ERROR(Error, "Unable to load requested map.");
  }

  obj = new MSMap(map);
  obj->Wrap(args.This());
  return args.This();
}
Пример #2
0
Handle<Value> MSMap::Save(const Arguments &args) {
  HandleScope scope;
  int result;
  MSMap *map = ObjectWrap::Unwrap<MSMap>(args.This());
  REQ_STR_ARG(0, outputfile);

  result = msSaveMap(map->this_, *outputfile);
  return scope.Close(Number::New(result));
}
Пример #3
0
Handle<Value> MSMap::SelectOutputFormat (const Arguments& args) {
  HandleScope scope;
  MSMap *map = ObjectWrap::Unwrap<MSMap>(args.This());
  REQ_STR_ARG(0, imagetype);
  outputFormatObj * format = msSelectOutputFormat(map->this_, *imagetype);
  if ( format == NULL) {
    THROW_ERROR(Error, "Output format not supported.");
  }
  msApplyOutputFormat(&(map->this_->outputformat), format, MS_NOOVERRIDE,
      MS_NOOVERRIDE, MS_NOOVERRIDE );
  return Undefined();
}
Handle<Value> MSOutputFormat::New(const Arguments &args) {
  HandleScope scope;
  MSOutputFormat *obj;
  
  if (!args.IsConstructCall()) {
    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));
  }

  if (args[0]->IsExternal()) {
    Local<External> ext = Local<External>::Cast(args[0]);
    void* ptr = ext->Value();
    obj = static_cast<MSOutputFormat*>(ptr);
    obj->Wrap(args.This());
    return args.This();
  }
  
  REQ_STR_ARG(0, driver);
  REQ_STR_ARG(1, name);
  
  outputFormatObj *format = msCreateDefaultOutputFormat(NULL, *driver, *name);

  /* in the case of unsupported formats, msCreateDefaultOutputFormat
     should return NULL */
  if (!format) {
    msSetError(MS_MISCERR, "Unsupported format driver: %s",
               "outputFormatObj()", *driver);
    return args.This();
  }

  msInitializeRendererVTable(format);

  /* Else, continue */
  format->refcount++;
  format->inmapfile = MS_TRUE;
  
  obj = new MSOutputFormat(format);
  obj->Wrap(args.This());
  return args.This();
}
Пример #5
0
Handle<Value> MSMap::SetSymbolSet(const Arguments &args) {
  HandleScope scope;
  int result;
  MSMap *map = ObjectWrap::Unwrap<MSMap>(args.This());
  REQ_STR_ARG(0, symbolfile);

  msFreeSymbolSet(&(map->this_->symbolset));
  msInitSymbolSet(&(map->this_->symbolset));

  // Set symbolset filename
  map->this_->symbolset.filename = strdup(*symbolfile);

  // Symbolset shares same fontset as main mapfile
  map->this_->symbolset.fontset = &(map->this_->fontset);

  result = msLoadSymbolSet(&(map->this_->symbolset), map->this_);
  return scope.Close(Number::New(result));
}
Пример #6
0
    // db, statement, callback
    static v8::Handle<Value> ExecuteStatement(const Arguments& args) {
      v8::HandleScope scope;
      REQ_DBCONN_ARG(0);
      REQ_STR_ARG(1, stmt);
      REQ_FUN_ARG(2, cb);

      v8::String::Utf8Value statement(stmt);

      if(dbcmd(dbconn, *statement) == FAIL){
        return v8::ThrowException(v8::Exception::Error(v8::String::New("FreeTDS could allocate enough memory for the statement")));
      }

      data_callback_t *callbackData = new data_callback_t();
      callbackData->dbconn = dbconn;
      callbackData->callback = Persistent<Function>::New(cb);

      if(dbsqlsend(dbconn) == FAIL){
        return v8::ThrowException(v8::Exception::Error(v8::String::New("FreeTDS could not send the statement")));
      }
      
      eio_custom(waitForDataResponse, EIO_PRI_DEFAULT, onDataResponse, callbackData);
      return v8::Undefined();
    }
Пример #7
0
/**
 * @details This is an asynchronous factory method creating a new `Map`
 * instance from a mapserver mapfile.
 *
 * `args` should contain the following parameters:
 *
 * @param mapfile A string representing the mapfile path.
 *
 * @param callback A function that is called on error or when the map has been
 * created. It should have the signature `callback(err, map)`.
 */
Handle<Value> Map::FromFileAsync(const Arguments& args) {
  HandleScope scope;

  if (args.Length() != 2) {
    THROW_CSTR_ERROR(Error, "usage: Map.FromFile(mapfile, callback)");
  }
  REQ_STR_ARG(0, mapfile);
  REQ_FUN_ARG(1, callback);

  MapfileBaton *baton = new MapfileBaton();

  baton->request.data = baton;
  baton->map = NULL;
  baton->callback = Persistent<Function>::New(callback);
  baton->error = NULL;
  baton->mapfile = *mapfile;

  uv_queue_work(uv_default_loop(),
                &baton->request,
                FromFileWork,
                (uv_after_work_cb) FromFileAfter);

  return Undefined();
}