2017-05-10 1 views
0

동적으로 추가 레이어를 추가해야합니다. 레이어는 레이어 메뉴에서도 볼 수 있어야합니다. 어떻게 접근합니까?GUIDE4YOU - 레이어를 추가하고 레이어를 만드는 방법은 레이어 메뉴에서 볼 수 있습니다.

의 I는 예를 들어이 할 더 구체적으로 :

문제 # 1 : 층은지도에 표시되지 않습니다. 내가 틀린 게 뭐야? 자바 스크립트 오류가 없습니다.

문제 2 : 어떻게 레이 레이어 메뉴에 레이어를 추가 할 수 있습니까? 사전에

createG4U('#g4u-map', 'conf/client.commented.json', 'conf/layers.commented.json').then(function (map) { 
    map.asSoonAs('ready', true, function() { 

     var openSeaMap_layer = new ol.layer.Tile({ 
      title: 'OpenSeaMap', 
      name: 'OpenSeaMap', 
      code: 'OpenSeaMap', 
      datalayer: 'N', 
      source: new ol.source.OSM({ 
       crossOrigin: null, 
       url: 'http://t1.openseamap.org/seamark/{z}/{x}/{y}.png' 
      }) 
     }); 

     alert('Visibility: ' + openSeaMap_layer.getVisible()); 

     map.get('api').addLayer(openSeaMap_layer); 
     }); 
}); 

감사합니다!

종류와 관련,

답변

0

당신은 레이어를 만들 수있는 다른 방법에 내놓고, 그것을 달성하기 위해 두 가지 선택이있다.

첫 번째 : API 함수를 사용하려는 경우 layerConfig.json 파일의 객체와 같은 layerConfigObjects를 전달할 수 있습니다. (여기에 설명되어 있습니다 : https://github.com/KlausBenndorf/guide4you/blob/31e118c8f4bc5490dec92d4a03bc53fff08258fd/src/configurators/LayerFactory.js#L37).

가능한 API 함수 addBaseLayer, addFeatureLayer합니다 (layerselector에서 서로를 비활성화 표시지도 기본)된다합니다 (baselayers의 상단에 레이어를,의 layerselector에 표시 결합 될 수있다)과 addFixedFeatureLayer (FeatureLayers 같은,하지만 눈에 보이는 항상 그것들은 layerselector에 나타나지 않습니다). (addLayer는 API 함수가 아니기 때문에 자바 스크립트 오류가 발생합니다.) https://github.com/KlausBenndorf/guide4you/blob/master/src/API.js의 모든 API 메소드를 볼 수 있습니다.

이 함수는 동일한 객체를 layerConfig에 직접 추가하는 것과 같습니다.

이 작업을 수행하는 또 다른 방법은 (당신이 예에서처럼)을 openlayers 레이어로 레이어를 생성하고이에 표시해야 layergroup에 직접 추가하는 것입니다. layergroups는 map.get('baseLayers'), map.get('featureLayers'), map.get('fixedFeatureLayers')을 통해 액세스 할 수 있습니다. 이것들은 addLayer 방법을 가지고 있으며 이것들을 사용할 수 있습니다.

레이어 선택기에 레이어가 표시되도록하려면 UI를 업데이트하려면 map.get('UIConfigurator').configureUI()을 호출해야합니다.

0

감사합니다. Simon!

난 다음 코드로 작업있어했습니다

createG4U('#g4u-map', 'conf/client.commented.json', 'conf/layers.commented.json').then(function (map) { map.asSoonAs('ready', true, function() { var openSeaMap_layer = { "id": "f0", "title": { "en": "OpenSeaMap", "de": "OpenSeaMap" }, "type": "OSM", "source": { "url": " http://t1.openseamap.org/seamark/ {z}/{x}/{y}.png", "crossOrigin": null, "attribution": { "en": "© http://www.openseamap.org/\" target=\"_blank\">OpenSeaMap contributors", "de": "© http://www.openseamap.org/\" target=\"_blank\">OpenSeaMap Mitwirkende" } }, "visible": true }; map.get('api').addFeatureLayer(openSeaMap_layer); //Make the layer visible in the layermenu map.get('UIConfigurator').configureUI(); }); });

관련 문제