2016-03-24 13 views
0

geojsonファイルからプロパティ"SCHULNAME"を取得しようとしました。ここでOpenlayers 3:geojsonプロパティの "undefined"を1つのレイヤーに取得

はにGeoJSONファイルからの抜粋です:

{"type":"FeatureCollection", 

"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC:1.3:CRS84"}}, 

"features":[{"type":"Feature","properties":{"spatial_name":"01A01", 
    "spatial_alias":"1. Schulpraktisches Seminar (S) Mitte", 
    "spatial_type":"Point", 
    "SCHULNAME":"1. Schulpraktisches Seminar (S) Mitte", 
    "SCHULART":"Schulpraktisches Seminar", 
    "TRAEGER":"Bezirk", 
    "ZWEIG_01":"Schulpraktisches Seminar", 
    "ZWEIG_02":null, 
    "ZWEIG_03":null, 
    "ZWEIG_04":null, 
    "BEZIRK":"Mitte", 
    "ORTSTEIL":"Wedding", 
    "PLZ":"13353", 
    "ADRESSE":"Tegeler Str. 16", 
    "TELEFON":"4677779713", 
    "FAX":"4677779720", 
    "EMAIL":"<a href=\"mailto:[email protected]\">[email protected]</a>", 
    "INTERNET":null,"LEITUNG":null}, 
"geometry":{"type":"Point", 
    "coordinates":[13.35812948892163,52.54071751171907]}},... 

ここでプロパティを持つポップアップウィンドウを開くための機能です:

map.on('singleclick', function(evt) { 
    var feature = map.forEachFeatureAtPixel(evt.pixel, 
       function(feature, layer) { 
       return feature; 
       }); 
    if (feature) { 
    var coordinate = evt.coordinate; 
    var printCoord = ol.proj.transform(feature.getGeometry().getCoordinates(), 'EPSG:3857','EPSG:4326'); 
    var printProps = feature.getProperties(); 
    PopupContent.innerHTML = '<table style="width:100%">'+ 
           '<tr>' + '<td>'+'<b>Coordinates:</b> ' + Math.round(printCoord[1] * 100)/100 + 'N, ' + Math.round(printCoord[0] * 100)/100 +'E' +'</td>'+'</tr>'+ 
           '<tr>'+'<td>'+"<b>Name:</b> " +printProps.SCHULNAME+'</td>'+'</tr>'+ 
           '</table>'; 
    Popup.setPosition(coordinate); 


    }}); 

座標が正しく表示されます。プロパティ"SCHULNAME"の場合、結果はundefinedです。しかし、私は次のようにGeoJSONファイルとそのプロパティ"name"ために同じコードを使用している場合、それは完璧に動作します:

{"type":"FeatureCollection", 
"features":[{"type":"Feature","properties":{"name":"Mitte", 
    "description":"", 
    "cartodb_id":1, 
    "created_at":"2013-09-03T12:32:04+0200", 
    "updated_at":"2013-09-03T12:32:04+0200"}, 
"geometry":{"type":"MultiPolygon", 
    "coordinates":[[[[13.403528,52.540212], ... 

私はここで何をしないのですか?

+0

予想される機能が確実に得られていますか? –

+0

前に述べたように、座標は正しく表示されます。だから私はかなり期待された機能を得ることを確信しています。 – TotoSchillaci

+0

@ user3725485 bit座標はclickイベントの座標です。マッチのために十分近い他の機能があるかもしれませんか? –

答えて

0

問題の原因は何かを知りましたが、どうしてこのようなことが起こるのか理解できないので、私はあなたからの説明に感謝します。

私が最初にGeoJSON層のためのol.source.Clusterを作成し、そのクラスタ源にそのol.layer.Vector層のソースを言及:

var schoolCluster = new ol.source.Cluster({ 
    source:new ol.source.Vector({ 
     url: 'Schools.geojson', 
     format: new ol.format.GeoJSON(), 
    }) 
}); 

var Schools = new ol.layer.Vector({ 
    source: schoolCluster, 
    style: iconStyleSchools 
    }); 

しかし、どういうわけか、それは唯一私が直接のソースを参照する際の特性を得るために働きますこのような任意のクラスターないベクター層:このコードで

var Schools = new ol.layer.Vector({ 
    source:new ol.source.Vector({ 
     url: 'Schools.geojson', 
     format: new ol.format.GeoJSON(), 
    }), 
    style: iconStyleSchools 
    }); 

私はにGeoJSONファイルから望んでいたすべてのプロパティを取得する可能性があり、もはやいかなるundefinedを取得できませんでした。誰かが理由を説明できますか?

関連する問題