27 #include "../../../../geometry/LinearRing.h" 28 #include "../../../../geometry/Polygon.h" 29 #include "../../common/Utils.h" 36 if(args.Holder().IsEmpty())
37 return ::v8::ThrowException(::v8::String::New(
"In order to use getExteriorRing method you must use object notation: \"ring = poly.getExteriorRing();\""));
39 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
42 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getExteriorRing method!"));
48 return hs.Close(jsgeom);
55 if(args.Holder().IsEmpty())
56 return ::v8::ThrowException(::v8::String::New(
"In order to use getNumInteriorRings method you must use object notation: \"n = poly.getNumInteriorRings();\""));
58 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
61 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getNumInteriorRings method!"));
65 ::v8::Local<::v8::Integer> jn = ::v8::Integer::New(static_cast<int>(n));
74 if(args.Holder().IsEmpty())
75 return ::v8::ThrowException(::v8::String::New(
"In order to use getNumRings method you must use object notation: \"n = poly.getNumRings();\""));
77 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
80 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getNumRings method!"));
84 ::v8::Handle<::v8::Integer> jn = ::v8::Integer::New(static_cast<int>(n));
93 if(args.Holder().IsEmpty())
94 return ::v8::ThrowException(::v8::String::New(
"In order to use setNumRings method you must use object notation: \"poly.setNumRings(n);\""));
96 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
99 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setNumRings method!"));
101 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
102 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setNumRings!"));
104 int n = args[0]->ToInt32()->Value();
108 return hs.Close(::v8::Undefined());
113 ::v8::HandleScope hs;
115 if(args.Holder().IsEmpty())
116 return ::v8::ThrowException(::v8::String::New(
"In order to use getInteriorRingN method you must use object notation: \"r = poly.getInteriorRingN(i);\""));
118 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
121 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getInteriorRingN method!"));
123 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
124 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getInteriorRingN!"));
126 int n = args[0]->ToInt32()->Value();
132 return hs.Close(jsgeom);
137 ::v8::HandleScope hs;
139 if(args.Holder().IsEmpty())
140 return ::v8::ThrowException(::v8::String::New(
"In order to use getRingN method you must use object notation: \"r = poly.getRingN(i);\""));
142 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
145 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getRingN method!"));
147 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
148 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for getRingN!"));
150 int n = args[0]->ToInt32()->Value();
156 return hs.Close(jsgeom);
161 ::v8::HandleScope hs;
163 if(args.Holder().IsEmpty())
164 return ::v8::ThrowException(::v8::String::New(
"In order to use setRingN method you must use object notation: \"poly.setRingN(n, ring);\""));
166 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
169 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in setRingN method!"));
171 if(args.Length() != 2 || args[0].IsEmpty() || !args[0]->IsInt32() || args[1].IsEmpty() || !args[1]->IsObject())
172 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for setNumRings!"));
174 int n = args[0]->ToInt32()->Value();
176 std::auto_ptr<te::gm::LinearRing> ring(te::v8::common::UnwrapAndLooseOwnership<te::gm::LinearRing>(args[1]->ToObject()));
182 return hs.Close(::v8::Undefined());
187 ::v8::HandleScope hs;
189 if(args.Holder().IsEmpty())
190 return ::v8::ThrowException(::v8::String::New(
"In order to use removeRingN method you must use object notation: \"poly.removeRingN(i);\""));
192 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
195 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in removeRingN method!"));
197 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsInt32())
198 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for removeRingN!"));
200 int n = args[0]->ToInt32()->Value();
204 return hs.Close(::v8::Undefined());
207 ::v8::Handle<::v8::Value>
Polygon_Add(const ::v8::Arguments& args)
209 ::v8::HandleScope hs;
211 if(args.Holder().IsEmpty())
212 return ::v8::ThrowException(::v8::String::New(
"In order to use add method you must use object notation: \"poly.add(ring);\""));
214 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
217 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in add method!"));
219 if(args.Length() != 1 || args[0].IsEmpty() || !args[0]->IsObject())
220 return ::v8::ThrowException(::v8::String::New(
"Invalid parameter for add!"));
222 std::auto_ptr<te::gm::LinearRing> ring(te::v8::common::UnwrapAndLooseOwnership<te::gm::LinearRing>(args[0]->ToObject()));
228 return hs.Close(::v8::Undefined());
233 ::v8::HandleScope hs;
235 if(args.Holder().IsEmpty())
236 return ::v8::ThrowException(::v8::String::New(
"In order to use clear method you must use object notation: \"poly.clear();\""));
238 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
241 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getNumRings method!"));
245 return hs.Close(::v8::Undefined());
250 ::v8::HandleScope hs;
252 if(args.Holder().IsEmpty())
253 return ::v8::ThrowException(::v8::String::New(
"In order to use getRings method you must use object notation: \"rings = poly.getRings();\""));
255 te::gm::Polygon* g = te::v8::common::Unwrap<te::gm::Polygon>(args.Holder());
258 return ::v8::ThrowException(::v8::String::New(
"Invalid geometry in getRings method!"));
260 const std::vector<te::gm::LinearRing*>& rings = g->
getRings();
262 int len =
static_cast<int>(rings.size());
264 ::v8::Handle<::v8::Array> jrings = ::v8::Array::New(len);
266 for(
int i = 0; i < len; ++i)
269 return hs.Close(jrings);
274 ::v8::HandleScope hs;
276 if(!args.IsConstructCall())
277 return ::v8::ThrowException(::v8::String::New(
"In order to create a Polygon you need to call its constructor like: var mygc = new TePolygon(3, TE_OGC_POLYGON, 4326)."));
279 if(args.Holder().IsEmpty())
280 return ::v8::ThrowException(::v8::String::New(
"Polygon constructor must use object notation!"));
282 if((args.Length() != 3) ||
283 args[0].IsEmpty() || !args[0]->IsInt32() ||
284 args[1].IsEmpty() || !args[1]->IsInt32() ||
285 args[2].IsEmpty() || !args[2]->IsInt32())
286 return ::v8::ThrowException(::v8::String::New(
"Missing parameter or wrong parameter type in Polygon constructor method!!"));
289 int nrings = args[0]->Int32Value();
290 int geomType = args[1]->Int32Value();
291 int srid = args[2]->ToInt32()->Int32Value();
293 std::auto_ptr<te::gm::Polygon> g(
new te::gm::Polygon(nrings, static_cast<te::gm::GeomType>(geomType), srid));
304 ::v8::HandleScope hs;
306 ::v8::Local<::v8::FunctionTemplate> jsgc = ::v8::FunctionTemplate::New(
Polygon_Constructor);
308 global->Set(::v8::String::New(
"TePolygon"), jsgc->GetFunction());
318 ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
319 result->Inherit(surfaceTpl);
321 ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
323 prototype->Set(::v8::String::NewSymbol(
"getExteriorRing"), ::v8::FunctionTemplate::New(
Polygon_GetExteriorRing));
325 prototype->Set(::v8::String::NewSymbol(
"getNumRings"), ::v8::FunctionTemplate::New(
Polygon_GetNumRings));
326 prototype->Set(::v8::String::NewSymbol(
"setNumRings"), ::v8::FunctionTemplate::New(
Polygon_SetNumRings));
328 prototype->Set(::v8::String::NewSymbol(
"getRingN"), ::v8::FunctionTemplate::New(
Polygon_GetRingN));
329 prototype->Set(::v8::String::NewSymbol(
"setRingN"), ::v8::FunctionTemplate::New(
Polygon_SetRingN));
330 prototype->Set(::v8::String::NewSymbol(
"removeRingN"), ::v8::FunctionTemplate::New(
Polygon_RemoveRingN));
331 prototype->Set(::v8::String::NewSymbol(
"add"), ::v8::FunctionTemplate::New(
Polygon_Add));
332 prototype->Set(::v8::String::NewSymbol(
"push_back"), ::v8::FunctionTemplate::New(
Polygon_Add));
333 prototype->Set(::v8::String::NewSymbol(
"clear"), ::v8::FunctionTemplate::New(
Polygon_Clear));
334 prototype->Set(::v8::String::NewSymbol(
"getRings"), ::v8::FunctionTemplate::New(
Polygon_GetRings));
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
Curve * getInteriorRingN(std::size_t i) const
It returns the n-th interior ring for this curve polygon as a curve.
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
void add(Curve *ring)
It adds the ring to the curve polygon.
std::vector< Curve * > & getRings()
It returns the polygon rings.
::v8::Persistent<::v8::FunctionTemplate > & GetLinearRingTemplate()
It returns a reference to the persistent template of a LinearRing object.
static::v8::Persistent<::v8::FunctionTemplate > sg_polygon_template
::v8::Handle<::v8::Value > Polygon_GetNumRings(const ::v8::Arguments &args)
std::size_t getNumInteriorRings() const
It returns the number of interior rings in this CurvePolygon.
Curve * getExteriorRing() const
It returns the exterior ring of this CurvePolygon.
void removeRingN(std::size_t i)
It removes the n-th ring in this CurvePolygon.
::v8::Handle<::v8::Value > Polygon_GetRings(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Polygon_GetExteriorRing(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Polygon_Constructor(const ::v8::Arguments &args)
void setNumRings(std::size_t size)
It sets the number of rings in this curve polygon.
A LinearRing is a LineString that is both closed and simple.
::v8::Handle<::v8::Value > Polygon_Clear(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Polygon_SetRingN(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetPolygonTemplate()
It returns a reference to the persistent template of a Polygon object.
void RegisterPolygon(::v8::Local<::v8::Object > &global)
It register the Polygon class.
::v8::Handle<::v8::Value > Polygon_Add(const ::v8::Arguments &args)
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
::v8::Handle<::v8::Value > Polygon_GetInteriorRingN(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Polygon_GetRingN(const ::v8::Arguments &args)
void clear()
It deletes all the rings of the CurvePolygon and clear it.
::v8::Persistent<::v8::FunctionTemplate > & GetSurfaceTemplate()
It returns a reference to the persistent template of a Surface object.
::v8::Handle<::v8::Value > Polygon_GetNumInteriorRings(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Polygon_SetNumRings(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Polygon_RemoveRingN(const ::v8::Arguments &args)
Curve * getRingN(std::size_t i) const
It returns the n-th ring for this curve polygon as a curve.
void setRingN(std::size_t i, Curve *r)
It sets the informed position ring to the new one.