Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 创建下拉列表以放大传单地图的选定国家/地区_Javascript_Html_Leaflet - Fatal编程技术网

Javascript 创建下拉列表以放大传单地图的选定国家/地区

Javascript 创建下拉列表以放大传单地图的选定国家/地区,javascript,html,leaflet,Javascript,Html,Leaflet,使用传单控件,我想创建一个下拉菜单,列出国家名称。选择此列表中的国家时,地图将放大该地图上的选定国家 countriesLayer = L.geoJson(countries, { onEachFeature: countriesOnEachFeature } ).addTo(map); 该层从我的geojson文件将我的国家加载到地图上 var geoJsonFeatures = []; func

使用传单控件,我想创建一个下拉菜单,列出国家名称。选择此列表中的国家时,地图将放大该地图上的选定国家

countriesLayer = L.geoJson(countries,
            {
                onEachFeature: countriesOnEachFeature
            }
        ).addTo(map);
该层从我的geojson文件将我的国家加载到地图上

var geoJsonFeatures = [];
function countriesOnEachFeature(feature, layer){
        if (feature.properties && feature.properties.Country){
            geoJsonFeatures.push(feature);
        }
}
然后我有一个加载的数组,它将我的geojson数据作为数组中的对象保存

 var legend = L.control({position: 'bottomright'});  
 legend.onAdd = function (map) {  
    var div = L.DomUtil.create('div', 'info legend');  
    var dropDownContent ='<select>';  
    for (var i = 0; i < uniqueCountryArray.length; i++ ){  
        dropDownContent += '<option value=' + "'" + uniqueCountryArray[i]["ISO3"] + "'>" + uniqueCountryArray[i]["Country"] + '</option>';  
       }  
        dropDownContent += '</select>';  
        div.innerHTML = dropDownContent;  
        div.firstChild.onmousedown = div.firstChild.ondblclick = L.DomEvent.stopPropagation;  
        return div;  
};
var legend=L.control({position:'bottomright'});
legend.onAdd=函数(映射){
var div=L.DomUtil.create('div','info legend');
var-dropDownContent='';
对于(var i=0;idropDownContent+='欢迎使用Stack Overflow!Stack Overflow不是一个讨论论坛,它是一个问答式网站,您可以在这里提出特定的编程问题,这些问题可以回答,而不是讨论。请阅读并编辑您的问题,以符合网站指南。像这样的离题问题通常会被忽略关闭,但如果编辑为询问可回答的问题,则可以重新打开。谢谢。您可能希望将所有代码放入包装器div中,作为
位置:相对;
,同时生成子项,包括
位置:绝对;
。换句话说,将
单独构建。我已经创建了ed我的问题提供了更多的上下文。请看一看!有关更多信息,我不能在geoJson数组对象上使用getBounds()。
$('select').change(function(){
            var selectedCountry = document.getElementById('ddVal').value;
            for (i=0 ; i < geoJsonFeatures.length; i++){
                if(selectedCountry == geoJsonFeatures[i].properties.ISO_3_CODE){
                    map.fitBounds(geoJsonFeatures[i].getBounds(),{padding: [10, 10]});
                }else if(selectedCountry == 'Anything'){
                    map.fitWorld();
                }
            }
});