有谁知道如何为使用 leaflet 指令添加的一组基础层和覆盖层设置折叠的 control.layers 选项? 在我的场景中,control.layer 应始终展开。
我尝试在我的传单指令配置中添加一个选项对象,例如:
angular.extend($scope, {
center: {
lat: 0,
lng: 0,
zoom: 1,
autoDiscover: true
},
geofences: {},
defaults: {
scrollWheelZoom: true,
zoomControl: false
},
layers: {
options: {
collapsed: false
},
baselayers: {
defaultOSMMap: {
name: 'Map at Day',
type: 'xyz',
url: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
},
osmNight: {
name: 'Map at Night ',
type: 'xyz',
url: 'http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png',
layerParams: {
key: 'BC9A493B41014CAABB98F0471D759707',
styleId: 999
}
},
googleHybrid: {
name: 'Google Hybrid',
layerType: 'HYBRID',
type: 'google'
},
googleRoadmap: {
name: 'Google Streets',
layerType: 'ROADMAP',
type: 'google'
}
},
overlays: {
communityAreas: {
name: 'Community Areas',
type: 'group',
visible: false
}
}
},
controls: {
}
然后,在 Angular-leaflet 指令文件中添加以下内容:
// We have baselayers to add to the map
_leafletLayers.resolve(leafletLayers);
leafletData.setLayers(leafletLayers, attrs.id);
leafletLayers.baselayers = {};
leafletLayers.controls = {};
leafletLayers.controls.layers = new L.control.layers({}, {}, isDefined(layers.options) ? layers.options : {}); --> this is the line I modified
leafletLayers.controls.layers.setPosition(defaults.controlLayersPosition);
leafletLayers.controls.layers.addTo(map);
但是我在调试控制台上遇到了与各层相关的错误,例如:“未捕获错误:在 leaflet.js 文件中没有为变量 {s} 提供值”。
也许是我在 Angular-leaflet-directive 上实例化基础层和覆盖层的方式......有什么想法吗?
最佳答案
现在可能有点晚了,但以防万一其他人也遇到同样的问题(就像我刚刚遇到的那样!)
这就是我将控制层设置为展开的方式。
基思
angular.extend($scope, {
center: {
lat: 0,
lng: 0,
zoom: 1,
autoDiscover: true
},
geofences: {},
defaults: {
scrollWheelZoom: true,
zoomControl: false,
controls :{
layers : {
visible: true,
position: 'topright',
collapsed: false
}
}
},
layers: ...
关于javascript - Control.Layer 折叠选项用于使用 leaflet 指令覆盖层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20432156/