タグ : LineString

openlayers 複数ポイントを繋いで線(ライン)を表示

openlayersのexamplesフォルダにサンプルがあり。

ライン表示サンプル
OpenLayers-XXX\examples\resize-features.html

緯度経度を指定したポイントを作成し、配列に格納。
OpenLayers.Geometry.LineStringを使用して作成し、レイヤー追加。

var style_green = {
  strokeColor: “#339933″,
  strokeOpacity: 1,
  strokeWidth: 3,
  pointRadius: 6,
  pointerEvents: “visiblePainted”
};

var pointList = [];
var newPoint = point;
for(var p=0; p<5; ++p) {
  newPoint = new OpenLayers.Geometry.Point(newPoint.x + Math.random(1),
                                newPoint.y + Math.random(1));
  pointList.push(newPoint);
}
lineFeature = new OpenLayers.Feature.Vector(
               new OpenLayers.Geometry.LineString(pointList),null,style_green);

vectorLayer = new OpenLayers.Layer.Vector(“Simple Geometry”);
vectorLayer.addFeatures(lineFeature);
map.addLayer(vectorLayer);

 
WordPress SEO fine-tune by Meta SEO Pack from Poradnik Webmastera