3

これは正しい方法ではありませんが、OpenLayers はポリゴンの配列から最後のポリゴンのみを描画します。

これが私のコードです:

          for (...) {
                var pointList = [];
                var polygonList = [];
                for (...) {
                    var newPoint = new OpenLayers.Geometry.Point(..X,...Y);
                    pointList.push(newPoint);
                }

                var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
                var polygons = new OpenLayers.Geometry.Polygon([linearRing]);
                polygonList.push(polygons);
          }

          var style_polygon2 = {
                strokeColor: "#05fbff",
                strokeOpacity: 1,
                strokeWidth: 2,
                fillColor: "#05fbff",
                fillOpacity: 0.2

          };

          var multiPol = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.MultiPolygon(polygonList), null, style_polygon2);
          ...layer.addFeatures(multiPol);

誰かがこのようなことをしたかどうか教えてください...

ありがとうございました!

4

1 に答える 1

6

私はあなたの例をテストしましたが、私の場合はすべて正常に動作します。ライブデモを参照してください。コード例:

var options = {
    div: "map",
    zoom: 13,
    center: [-9075004.4955698, 5028040.5259088],
    layers: [
        new OpenLayers.Layer.OSM()
    ]
},
source = [
    [{x: -9075004, y: 5028040}, {x:-9079132, y: 5025403}, {x: -9072673, y: 5023568}],
    [{x: -9074004, y: 5026040}, {x:-9073132, y: 5027403}, {x: -9074673, y: 5026568}],
    [{x: -9073004, y: 5027040}, {x:-9072132, y: 5029403}, {x: -9075673, y: 5028568}]
],
polygonList = [],
multuPolygonGeometry,
multiPolygonFeature,    
vector = new OpenLayers.Layer.Vector('multiPolygon'),
map = new OpenLayers.Map(options);


for (var i=0; i<source.length; i+=1) {
    var pointList = [];
    for (var j=0; j<source[i].length; j+=1) {
        var point = new OpenLayers.Geometry.Point(source[i][j].x, source[i][j].y);
        pointList.push(point);
    }
    var linearRing = new OpenLayers.Geometry.LinearRing(pointList);
    var polygon = new OpenLayers.Geometry.Polygon([linearRing]);
    polygonList.push(polygon);
}
multuPolygonGeometry = new OpenLayers.Geometry.MultiPolygon(polygonList);
multiPolygonFeature = new OpenLayers.Feature.Vector(multuPolygonGeometry);

vector.addFeatures(multiPolygonFeature);
map.addLayer(vector);
于 2012-12-19T03:41:54.413 に答える