OpenLayersのGeometry subclassについて[Chapter 42]

OpenLayersを使ってみる。[Chapter 42]

OpenLayersのGeometryとFeature classについて[Chapter 41] に引き続き、OpenLayersのGeometryのsubclassについて基本を学んでいきます。


  • どのようにvector layerを描いているか?
  • Vector Classとは?
  • GeometryとFeature classについて → 今回もここ
  • Strategy,Protocol,Format classの使い方


OpenLayers 2.10 Beginner's Guideなる書籍の章立てにあわせて、OpenLayersの使い方を学んでいきます。

Geometry subclass



Geometry.Point: Contains properties x and y. To instantiate, pass in an x and y.
code example:
var my_point = new OpenLayers.Geometry.Point(-50, 42);


Geometry.Collection: This is a class that contains a collection (an {Array}) of geometry objects. Many other geometry classes, such as LineString, inherit from this class. To instantiate, pass in an array of geometry objects. For example, to create a geometry collection object you would pass in an array of geometry objects (assuming you have a geom_point_object and a geom_line_object):
var geom_collection_object = new OpenLayers.Geometry.Collection([geom_point_object, geom_line_object ]);


Geometry.MultiPoint: This is a collection ({Array}) of geometry point objects. Other classes, such as LineString, inherit from this class. To instantiate, pass in an array of Point objects:
var geom_multipoint = new OpenLayers.Geometry.MultiPoint([ geom_point_1, geom_point_2 ]);


Geometry.Curve: This class is similar to MultiPoint (it also inherits from it) but it assumes that the point objects are connected. To instantiate, pass in an array of Point objects:
var geom_curve = new OpenLayers.Geometry.Curve([ geom_point_1, geom_point_2 ]);


Geometry.LineString: This class, as we saw earlier, is composed on point objects that are connected together. It is inherited from the Curve class—it is basically a curve which cannot contain less than two points. To instantiate, pass in an array of Point objects:
var geom_line = new OpenLayers.Geometry.LineString([ geom_point_1, geom_point_2 ]);


Geometry.MultiLineString: MultiLineStrings contain multiple LineString objects. To instantiate, pass in an array of LineString objects:
var geom_multi_line = new OpenLayers.Geometry.MultiLineString([geom_line_1, geom_line_2 ]);


Geometry.LinearRing: This class is a version of a LineString that is closed-meaning the line 'loops back' on itself, the beginning and end points are connected. When creating the object, you can close the line yourself by making the last point equal to the first point. To instantiate, pass in an array of LineString objects:
var geom_linear_ring = new OpenLayers.Geometry.LinearRing([geom_point_1, geom_point_2, geom_point_3, geom_point_1 ]);

You can also call it without passing the start point in as the end point. If you do this, it will be automatically closed for you (OpenLayers will automatically add in the start point as the end point).


Geometry.Polygon: This class is essentially just an {Array} of LinearRing objects. For a basic polygon, you can pass in just one LinearRing object. The first LinearRing object you pass in will serve as the outer bounds of the polygon. All LinearRings objects passed in after the first will be holes within the polygon (for example, you could form a doughnut by passing in a large circle first then a smaller circle). To instantiate, pass in an array of LinearRing objects:
var geom_polygon = new OpenLayers.Geometry.Polygon([ geom_linear_ring_1, geom_linear_ring_2 ]);


Geometry.MultiPolygon: A MultiPolygon consists of multiple Polygon objects. To instantiate, pass in an array of Polygon objects:
var geom_multi_polygon = new OpenLayers.Geometry.MultiPolygon([geom_polygon_1, geom_polygon_2 ]);

Geometry subclass methods

OpenLayers.Geometryにsubclassのmethodが記述されています。基本的には、Vector layer classのmethodを継承しています。


OpenLayersの簡単なGeometry classとFeature classについて学びました。(ちょい手抜きの部分もありますが。。。) 多くのmethodがあるので、いろいろ他のmethodについてtryしてみてください。
次回は、feature classについて基本を学んでいきます。

そこんところ ヨロシク~~!!

OpenLayers Tutorialの目次に戻る。

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


WP-SpamFree by Pole Position Marketing

Social Widgets powered by