27 #include "../../../../geometry/GeometryCollection.h" 28 #include "../../common/Utils.h" 32 #include <boost/cstdint.hpp> 38 if(args.Holder().IsEmpty())
39 return ::v8::ThrowException(::v8::String::New(
"In order to use getNumGeometries method you must use object notation: \"ng = obj.getNumGeometries();\""));
44 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getNumGeometries method!"));
48 ::v8::Handle<::v8::Integer> jn = ::v8::Integer::New(static_cast<boost::int32_t>(n));
57 if(args.Holder().IsEmpty())
58 return ::v8::ThrowException(::v8::String::New(
"In order to use setNumGeometries method you must use object notation: \"obj.setNumGeometries(2);\""));
60 if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsInt32())
61 return ::v8::ThrowException(::v8::String::New(
"In order to use setNumGeometries method you must use object notation: \"obj.setNumGeometries(2);\""));
66 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setNumGeometries method!"));
68 int n = args[0]->ToInt32()->Value();
72 return hs.Close(::v8::Undefined());
79 if(args.Holder().IsEmpty())
80 return ::v8::ThrowException(::v8::String::New(
"In order to use getGeometryN method you must use object notation: \"gn = obj.getGeometryN(2);\""));
82 if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsInt32())
83 return ::v8::ThrowException(::v8::String::New(
"In order to use getGeometryN method you must use object notation: \"gn = obj.getGeometryN(2);\""));
88 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getGeometryN method!"));
90 int i = args[0]->ToInt32()->Value();
101 ::v8::HandleScope hs;
103 if(args.Holder().IsEmpty())
104 return ::v8::ThrowException(::v8::String::New(
"In order to use setGeometryN method you must use object notation: \"obj.setGeometryN(i, new_geom);\""));
106 if((args.Length() != 2) || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsObject())
107 return ::v8::ThrowException(::v8::String::New(
"Missing parameter or wrong parameter type in setGeometryN method!"));
112 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setGeometryN method!"));
114 int i = args[0]->ToInt32()->Value();
115 te::gm::Geometry* rhsGeom = te::v8::common::UnwrapAndLooseOwnership<te::gm::Geometry>(args[1]->ToObject());
118 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setGeometryN method!"));
122 return hs.Close(::v8::Undefined());
127 ::v8::HandleScope hs;
129 if(args.Holder().IsEmpty())
130 return ::v8::ThrowException(::v8::String::New(
"In order to use removeGeometryN method you must use object notation: \"obj.removeGeometryN(2);\""));
132 if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsInt32())
133 return ::v8::ThrowException(::v8::String::New(
"In order to use removeGeometryN method you must use object notation: \"obj.removeGeometryN(2);\""));
138 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in removeGeometryN method!"));
140 int n = args[0]->ToInt32()->Value();
144 return hs.Close(::v8::Undefined());
149 ::v8::HandleScope hs;
151 if(args.Holder().IsEmpty())
152 return ::v8::ThrowException(::v8::String::New(
"In order to use add method you must use object notation: \"obj.add(new_geom);\""));
154 if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsObject())
155 return ::v8::ThrowException(::v8::String::New(
"Missing parameter or wrong parameter type in add method!"));
160 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in add method!"));
162 te::gm::Geometry* rhsGeom = te::v8::common::UnwrapAndLooseOwnership<te::gm::Geometry>(args[0]->ToObject());
165 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in add method!"));
167 thisGeom->
add(rhsGeom);
169 return hs.Close(::v8::Undefined());
174 ::v8::HandleScope hs;
176 if(args.Holder().IsEmpty())
177 return ::v8::ThrowException(::v8::String::New(
"In order to use clear method you must use object notation: \"obj.clear();\""));
182 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in clear method!"));
186 return hs.Close(::v8::Undefined());
191 ::v8::HandleScope hs;
193 if(!args.IsConstructCall())
194 return ::v8::ThrowException(::v8::String::New(
"In order to create a GeometryCollection you need to call its constructor like: var mygc = new TeGeometryCollection(2, TE_OGC_GEOMETRYCOLLECTION, 4326)."));
196 if(args.Holder().IsEmpty())
197 return ::v8::ThrowException(::v8::String::New(
"GeometryCollection constructor must use object notation!"));
199 if((args.Length() != 3) ||
200 args[0].IsEmpty() || !args[0]->IsInt32() ||
201 args[1].IsEmpty() || !args[1]->IsInt32() ||
202 args[2].IsEmpty() || !args[2]->IsInt32())
203 return ::v8::ThrowException(::v8::String::New(
"Missing parameter or wrong parameter type in GeometryCollection constructor method!!"));
205 int ngeom = args[0]->Int32Value();
206 int geomType = args[1]->Int32Value();
207 int srid = args[2]->ToInt32()->Int32Value();
209 std::auto_ptr<te::gm::GeometryCollection> g(
new te::gm::GeometryCollection(ngeom, static_cast<te::gm::GeomType>(geomType), srid));
220 ::v8::HandleScope hs;
224 global->Set(::v8::String::New(
"TeGeometryCollection"), jsgc->GetFunction());
234 ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
235 result->Inherit(gTpl);
237 ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
247 sg_gc_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
::v8::Handle<::v8::Value > GeometryCollection_GetNumGeometries(const ::v8::Arguments &args)
static::v8::Persistent<::v8::FunctionTemplate > sg_gc_template
::v8::Handle<::v8::Value > GeometryCollection_Constructor(const ::v8::Arguments &args)
void setNumGeometries(std::size_t size)
It sets the number of geometries in this GeometryCollection.
void removeGeometryN(std::size_t i)
It removes the n-th geometry in this geometry collection.
::v8::Handle<::v8::Value > GeometryCollection_GetGeometryN(const ::v8::Arguments &args)
void clear()
It deletes all the elements of the collection.
::v8::Handle<::v8::Value > GeometryCollection_Clear(const ::v8::Arguments &args)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
::v8::Handle<::v8::Value > GeometryCollection_RemoveGeometryN(const ::v8::Arguments &args)
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
::v8::Persistent<::v8::FunctionTemplate > & GetGeometryTemplate()
It returns a reference to the persistent template of a Geometry object.
void add(Geometry *g)
It adds the geometry into the collection.
::v8::Local<::v8::Object > Geometry_Make(te::gm::Geometry *g, const bool isOwner)
Given a C++ geometry this function creates a new JavaScript geometry cast to the right geometry subty...
void setGeometryN(std::size_t i, Geometry *g)
It sets the n-th geometry in this geometry collection.
::v8::Handle<::v8::Value > GeometryCollection_SetGeometryN(const ::v8::Arguments &args)
It is a collection of other geometric objects.
::v8::Handle<::v8::Value > GeometryCollection_SetNumGeometries(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > GeometryCollection_Add(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetGeometryCollectionTemplate()
It returns a reference to the persistent template of a GeometryCollection object. ...
void RegisterGeometryCollection(::v8::Local<::v8::Object > &global)
It register the GeometryCollection class.