Openlayers 3 具有自定义多边形的OpenLayers:ol.geom.LinearRing的问题

Openlayers 3 具有自定义多边形的OpenLayers:ol.geom.LinearRing的问题,openlayers-3,Openlayers 3,我正在将一个简单的ASP.NET应用程序从OpenLayers 2转换为OpenLayers 3 此应用程序使用自定义定义的向量层,即我用自定义多多边形填充的向量对象。我基本上调用了一个存储过程,并填充了一个名为polyline的变量,在此基础上我应该能够创建我的ol.geom.LinearRing对象 问题在于,通过创建LinearString对象,我得到了以下错误: AssertionError:失败:不支持的跨步:未定义 这是我的密码: for (var i in polyline) {

我正在将一个简单的ASP.NET应用程序从OpenLayers 2转换为OpenLayers 3

此应用程序使用自定义定义的向量层,即我用自定义多多边形填充的向量对象。我基本上调用了一个存储过程,并填充了一个名为polyline的变量,在此基础上我应该能够创建我的ol.geom.LinearRing对象

问题在于,通过创建LinearString对象,我得到了以下错误:

AssertionError:失败:不支持的跨步:未定义

这是我的密码:

for (var i in polyline)
{
    var coord = polyline[i];
    var point = new ol.geom.Point([coord.x, coord.y]).transform("EPSG:4326", "EPSG:900913"); 
    sitePoints.push(point);
}
linearRing = new ol.geom.LinearRing(sitePoints);
我还试图明确指定GeometryLayout,到目前为止没有结果

linearRing = new ol.geom.LinearRing(sitePoints, ol.geom.GeometryLayout.XY);
通过手动检查代码和浏览网页,我意识到问题可能出在ol.js库的setCoordinates函数中,我目前使用的是ol-debug.js v.3.5.0。但我不知道如何解决它/我可以利用哪些解决方法

任何帮助都将不胜感激


g4lvuz

似乎线性化构造函数需要的是坐标数组,而不是点数组

试着改变你的想法

sitePoints.push(point);
进入


似乎线性化构造函数需要的是坐标数组,而不是点数组

试着改变你的想法

sitePoints.push(point);
进入

下面是您在“注释”部分中提供的多段线的注释

你提到多重多边形?您想给我一个多多边形的例子,还是只使用JSFIDLE就可以了

您将从坐标对创建几何图形

然后使用变换函数对几何体应用变换,可以从中获得

下面是您在“注释”部分中提供的多段线的注释

你提到多重多边形?您想给我一个多多边形的例子,还是只使用JSFIDLE就可以了

您将从坐标对创建几何图形

然后使用变换函数对几何体应用变换,可以从中获得


我最终设法使ASP.NET+Javascript代码与OpenLayers 3一起工作。以下是一段代码片段:

tranformFn = ol.proj.getTransform('EPSG:4326', 'EPSG:900913'); // 'EPSG:3857'
var featureMultiGeometry = new ol.geom.MultiPolygon(null);
@{
    foreach (var item in modelGeographieMultiPolygon.Select(x => new { geoKennung = x.geoKennung, Bezeichnung = x.Bezeichnung, Vorfahren_geoKennung = x.Parent_geoKennung}).Distinct()) // for each region
    {
        <text>        
        @*
        siteStyle =
        {
            strokeColor: "#000000", // #770077
            strokeOpacity: 1,
            strokeWidth: 0.5,
            fillColor: getRandomColor(),
            fillOpacity: 0.5,
            pointRadius: 20,
            label: $("<div/>").html("</text>@item.Bezeichnung<text>").text(),
        };
        *@
        siteStyle = new ol.style.Style
        ({
            fill: new ol.style.Fill
            ({
                color: [255, 155, 255, 0.5]
            })
        });
        </text>

        foreach (var PolID in modelGeographieMultiPolygon.Where(x => x.geoKennung == @item.geoKennung).Select(x => x.Polygon_ID).Distinct()) // for each polygon
        {
            int count = 0;
            <text>featureGeometry = new ol.geom.Polygon([[</text>                   
            foreach (var punkt in modelGeographieMultiPolygon.Where(x => x.geoKennung == @item.geoKennung && x.Polygon_ID == PolID.Value)) // for each point in the polygon
            {
                if(count!=0)
                {
                    <text>, </text>;
                }
                <text>[</text>@punkt.Ecke_Longitude.ToString().Replace(",", ".")<text>, </text>@punkt.Ecke_Latitude.ToString().Replace(",", ".")<text>]</text>
                count++;
            }
            <text>]]);
            featureMultiGeometry.appendPolygon(featureGeometry);
            </text>;
        }
    }
}

featureMultiGeometryTf = featureMultiGeometry.applyTransform(tranformFn);

var multiPolygonFeature = new ol.Feature
({
    geometry: featureMultiGeometry
})
;
geometryMultiPolygonFeatureArray.push(multiPolygonFeature);
vectorLayer.getSource().addFeatures(geometryMultiPolygonFeatureArray);

谢谢大家的帮助!你的答案对我来说真的很有用。

我最终设法使ASP.NET+Javascript代码与OpenLayers 3一起工作。以下是一段代码片段:

tranformFn = ol.proj.getTransform('EPSG:4326', 'EPSG:900913'); // 'EPSG:3857'
var featureMultiGeometry = new ol.geom.MultiPolygon(null);
@{
    foreach (var item in modelGeographieMultiPolygon.Select(x => new { geoKennung = x.geoKennung, Bezeichnung = x.Bezeichnung, Vorfahren_geoKennung = x.Parent_geoKennung}).Distinct()) // for each region
    {
        <text>        
        @*
        siteStyle =
        {
            strokeColor: "#000000", // #770077
            strokeOpacity: 1,
            strokeWidth: 0.5,
            fillColor: getRandomColor(),
            fillOpacity: 0.5,
            pointRadius: 20,
            label: $("<div/>").html("</text>@item.Bezeichnung<text>").text(),
        };
        *@
        siteStyle = new ol.style.Style
        ({
            fill: new ol.style.Fill
            ({
                color: [255, 155, 255, 0.5]
            })
        });
        </text>

        foreach (var PolID in modelGeographieMultiPolygon.Where(x => x.geoKennung == @item.geoKennung).Select(x => x.Polygon_ID).Distinct()) // for each polygon
        {
            int count = 0;
            <text>featureGeometry = new ol.geom.Polygon([[</text>                   
            foreach (var punkt in modelGeographieMultiPolygon.Where(x => x.geoKennung == @item.geoKennung && x.Polygon_ID == PolID.Value)) // for each point in the polygon
            {
                if(count!=0)
                {
                    <text>, </text>;
                }
                <text>[</text>@punkt.Ecke_Longitude.ToString().Replace(",", ".")<text>, </text>@punkt.Ecke_Latitude.ToString().Replace(",", ".")<text>]</text>
                count++;
            }
            <text>]]);
            featureMultiGeometry.appendPolygon(featureGeometry);
            </text>;
        }
    }
}

featureMultiGeometryTf = featureMultiGeometry.applyTransform(tranformFn);

var multiPolygonFeature = new ol.Feature
({
    geometry: featureMultiGeometry
})
;
geometryMultiPolygonFeatureArray.push(multiPolygonFeature);
vectorLayer.getSource().addFeatures(geometryMultiPolygonFeatureArray);

谢谢大家的帮助!你的答案对我真的很有用。

EPSG:900913是胡说八道。这应该是OL3中的EPSG:3857。你能提供一个JSFIDLE或者给我们提供一个几何体样本,我可以为你提供一个JSFIDLE样本。嗨,谢谢你的提示-我是Javascript新手,我从来没有使用过JSFIDLE,但我现在要看一看。这是一个我想使用的多段线样本:polyline=[{x:16.37376206,y:48.19958029},{x:16.37385355,y:48.19959905},{x:16.35548841,y:48.21036004},{x:16.3553591,y:48.20966506},{x:16.35519314,y:48.20921214},{x:16.37337628,y:48.19965110},{x:16.37376206,y:48.19958029}];EPSG:900913是胡说八道。这应该是OL3中的EPSG:3857。你能提供一个JSFIDLE吗?或者给我们提供一个示例几何体,我可以为你提供一个带有示例的JSFIDLE。嗨,谢谢你的提示-我是Javascript新手,从未使用过JSFIDLE,但我现在要看一看。这是我想要使用的多段线示例:polyline=[{x:16.37376206,y:48.19958029},{x:16.37385355,y:48.19959905},{x:16.35548841,y:48.21036004},{x:16.3553591,y:48.20966506},{x:16.35519314,y:48.20921214},{x:16.37337628,y:48.19965110},{x:16.37376206,y:48.19958029}];您好,谢谢您的回答。实际上,您创建ol.geom.Polygons对象的方法很有效,而且似乎更易于实现。我将尝试使用multipolygons,但这不应该是一个问题。实际上,我在尝试将功能添加到vectorLayer对象时仍然遇到一些问题:vectorLayer.getSource.addFeatures[multiPolygonFeature];您好,谢谢您的回答。实际上,您创建ol.geom.Polygons对象的方法很有效,而且似乎更易于实现。我将尝试使用multipolygons,但这不应该是一个问题。实际上,我在尝试将功能添加到vectorLayer对象时仍然遇到一些问题:vectorLayer.getSource.addFeatures[multiPolygonFeature];