简体   繁体   English

openlayers geojson GeometryCollection序列化

[英]openlayers geojson GeometryCollection serialize

I tried to add a geojson GeometryCollection (two polygons in one feature) with the following code: 我尝试使用以下代码添加geojson GeometryCollection(一个要素中包含两个多边形):

var featurecollection = {"type":"Feature", "properties":{"WKR_NR":{"value":"66", "displayName":"WKR_NR"}, "WKR_NAME":{"value":"Altmark", "displayName":"WKR_NAME"}, "LAND_NR":{"value":"15", "displayName":"LAND_NR"}, "LAND_NAME":{"value":"Sachsen-Anhalt", "displayName":"LAND_NAME"}}, "geometry":{"type":"GeometryCollection", "geometries":[{"type":"Polygon", "coordinates":[[[11.82209622587612, 52.34301860166207], [11.817774093487138, 52.334218350541896], [11.807618922039657, 52.334988060217924], [11.790223804374884, 52.3372550858293], [11.78804671117088, 52.35066482829717], [11.80055500070333, 52.35470147787753], [11.819318685600722, 52.34773879534134], [11.82209622587612, 52.34301860166207]]]}, {"type":"Polygon", "coordinates":[[[11.625490226126516, 53.014155173198034], [11.643792593971638, 53.005353749176265], [11.678605317048948, 53.007500272184636], [11.691508960695465, 52.97890177931147], [11.744900087714374, 52.98836377813224], [11.785485168911753, 52.96123819494062], [11.843231838584519, 52.953331343009545], [11.846841832814349, 52.940137809430865], [11.823030489231808, 52.92303250071203], [11.83682008625954, 52.90938467138226], [11.981941169062262, 52.87607203121912], [12.020385227153387, 52.88841247097549], [12.080988158376819, 52.88220894061335], [12.127289816840882, 52.88981664655036], [12.119895693664516, 52.87543803746719], [12.13248219200621, 52.8558211228031], [12.199403343824061, 52.8714428383796], [12.232750317016908, 52.86024742307424], [12.251497497148451, 52.809510687301696], [12.247443721853234, 52.791959611234866], [12.22364885088984, 52.785328135584855], [12.21227265368092, 52.77301936690752], [12.197091298456408, 52.7188147816694], [12.238613424621569, 52.665409856765734], [12.230258850787465, 52.62968330608261], [12.190385960758247, 52.6201934757329], [12.17515906502223, 52.60457261828375], [12.174433832794424, 52.58003052479018], [12.143361062323343, 52.53573113037129], [12.171210063866818, 52.5062636155928], [12.162640316645106, 52.500835395082156], [12.108195830773255, 52.50822883163489], [12.103168497725802, 52.52477556943423], [12.076814313382958, 52.54004044347858], [12.050694924487075, 52.525045881355894], [11.990420550370642, 52.52007883088814], [11.997901831632793, 52.571024464450616], [11.988240632385583, 52.57527707609638], [11.980151608981359, 52.53823974699831], [11.95970542521976, 52.51858066040097], [12.002753238668047, 52.460333327925404], [11.992708877983876, 52.43103249736487], [11.962270843821118, 52.400999345836794], [11.929241869486036, 52.39181373779316], [11.900270801301792, 52.35418951773055], [11.851935108210942, 52.33139272188436], [11.817433924211613, 52.372403339618714], [11.834328379190685, 52.38188020438711], [11.840446842567902, 52.40164092728919], [11.824000038133862, 52.421633313829446], [11.79788329849156, 52.4048537794548], [11.748126546321151, 52.403015286614185], [11.719844059178572, 52.409742937959756], [11.699715351222565, 52.459041056498315], [11.642991884388962, 52.47027254032829], [11.58745520968375, 52.458591499535565], [11.562455406690738, 52.41074571800978], [11.445607147252204, 52.386918975933064], [11.451253714966386, 52.40716604689364], [11.382327026093915, 52.43044308452597], [11.33303944763232, 52.42398398569652], [11.243861916949461, 52.43771185485013], [11.147647875850998, 52.43388371635617], [11.089960257644199, 52.455533659368896], [11.05650628403439, 52.5062061560478], [11.00865540209794, 52.49743833029479], [10.959367089863635, 52.534880501626205], [10.937115198576306, 52.56809668379479], [10.940699738434244, 52.58980058724528], [10.972900452451096, 52.60390715247509], [10.976957812353136, 52.624198440535906], [10.945210633577373, 52.62031889495053], [10.926765054712599, 52.60921629226031], [10.908807605370766, 52.62675394652262], [10.902900060583416, 52.63288635850292], [10.838250804892366, 52.69536905177916], [10.79667724408703, 52.71431343626516], [10.755698500874928, 52.78463211599313], [10.759750766469935, 52.79609356944849], [10.765414355239177, 52.8414963636739], [10.841955892273544, 52.85196752350796], [10.93957634429748, 52.85277462442411], [10.986189746274858, 52.88272387705999], [11.001678908430973, 52.91108170517689], [11.069342325527263, 52.909623974478905], [11.110626400886918, 52.89555950095206], [11.156283854647228, 52.90608086656519], [11.21878208126892, 52.89799790911749], [11.239884606905864, 52.879517541557206], [11.29579804373252, 52.875170703477764], [11.406571977621434, 52.904075444754625], [11.470842953571694, 52.938951093845404], [11.504592143927084, 52.941128094313925], [11.492348754753628, 52.95953308861247], [11.512383406030214, 53.00726268548251], [11.555636882784334, 52.998602963293635], [11.59617386672076, 53.0362803481102], [11.623050800347798, 53.041932006345355], [11.641148205721082, 53.0377603493648], [11.625490226126516, 53.014155173198034]]]}]}, "crs":{"type":"name", "properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}};

       var geojson_format = new OpenLayers.Format.GeoJSON({
                'internalProjection': new OpenLayers.Projection("EPSG:900913"),
                'externalProjection': new OpenLayers.Projection("EPSG:4326")
            });
       vectors.addFeatures(geojson_format.read(featurecollection));

The polygon is shown quite well, as you can see here: 如您在此处看到的,多边形显示得很好:

http://217.16.163.138/flaechen.php

With a click on the polygon the function "serialize" is triggered and the geojson-code is written in an output-box: 单击多边形,将触发“序列化”功能,并将geojson代码写入输出框中:

        var type = "geojson";
        var pretty = false;
        var str = formats['out'][type].write(feature, pretty);
        str = str.replace(/,/g, ', ');
        document.getElementById('output_featureonly').value = str;

The problem is that the projection of the polygon is changing to something realy strange. 问题在于多边形的投影正变为某种真正奇怪的东西。

The code works well for only one polygon in one feature. 该代码仅对一项要素中的一个多边形有效。 You can try it on your own here: 您可以在这里自己尝试:

http://217.16.163.138/flaechen.php

Thanks in advance Florian 在此先感谢Florian

It does not look like OpenLayers supports this type, or at least not presented in this way: 看起来OpenLayers不支持这种类型,或者至少没有这样显示:

For multiple polygons the type should be 'MultiPolygon': 对于多个多边形,类型应为“ MultiPolygon”:

Try reducing the input to a minimal test case it should be easier to debug. 尝试将输入减少到最小的测试用例,这样应该更容易调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM