2017-05-12 1 views
0

레이어의 맞춤 속성을 읽으려면 어떻게해야하나요?GUIDE4YOU/OL3 - 레이어의 맞춤 속성을 읽는 방법

예를 들어 사용자 지정 테스트 및 값 sam의 레이어를 추가했습니다.

createG4U('#g4u-map', 'conf/client.commented.json', 'conf/layers.commented.json').then(function (map) { map.asSoonAs('ready', true, function() { map.get('api').addFeatureLayer({ "id": "1", "type": "GeoJSON", "style": stylefunction, "source": { "url": "files/sample.json" }, "visible": true, "test" : "sam" }); map.getLayers().forEach(function (layer) { console.log(layer); }); }); });

종류의 관련

Console log map layers,

답변

0

layer.get('test') 가능합니다.

레이어가 다른 레이어 그룹에 중첩되어 있으므로 getLayers()으로 레이어를 가져올 수 없습니다.

메서드 addFeatureLayer은 레이어에 대한 참조를 반환합니다. 저장하고 나중에 사용할 수 있습니다.

또는 모든 중첩 된 레이어를 반복적으로 반복하는 recursiveForEach을 사용할 수 있습니다.

당신은이 map.getLayerGroup().recursiveForEach(function (layer) { ... })와 맵에있는 모든 레이어를 위해 할 중 수 있습니다 또는 당신은 단지 map.get('featureLayers').recursiveForEach(function (layer) { ... })

+0

가 작동하지, 나는 항상 '정의되지 않은'얻을. 속성 ID (필수 속성)를 읽는 것조차도 '정의되지 않음'입니다. – Sam

+0

답변을 업데이트했습니다. –

0

감사 시몬 featureLayers 또는 baseLayers을 위해 그것을 할 수 있습니다!

근무 코드 :

createG4U('#g4u-map', 'conf/client.commented.json', 'conf/layers.commented.json').then(function (map) { map.asSoonAs('ready', true, function() { map.get('api').addFeatureLayer({ "id": "1", "type": "GeoJSON", "style": stylefunction, "source": { "url": "files/sample.json" }, "visible": true, "test" : "sam" }); map.get('featureLayers').recursiveForEach(function (layer) { console.log(layer.get('test')); }); //Make the layer visible in the menu map.get('UIConfigurator').configureUI(); }); });

관련 문제