Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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 加载后打开图层可以';t画_Javascript_Jquery_Openlayers - Fatal编程技术网

Javascript 加载后打开图层可以';t画

Javascript 加载后打开图层可以';t画,javascript,jquery,openlayers,Javascript,Jquery,Openlayers,我做了一个函数,它绘制并保存到GeoJson。我当时得到: 接下来,当我加载特征时,可以在需要绘制时计时,我得到错误:“layer.getSource().getFeaturesCollection()”==null,但我使用featureCollection类型保存了特征。当我使用getFeatures()时,它返回特性数组 开始加载层: if(map_info != "") { var layer_area = new ol.layer.Vector({

我做了一个函数,它绘制并保存到GeoJson。我当时得到:

接下来,当我加载特征时,可以在需要绘制时计时,我得到错误:“layer.getSource().getFeaturesCollection()”==null,但我使用featureCollection类型保存了特征。当我使用getFeatures()时,它返回特性数组

开始加载层:

if(map_info != "") {
            var layer_area = new ol.layer.Vector({
                source: new ol.source.Vector({
                    features: (new ol.format.GeoJSON()).readFeatures(map_info['layers'][0])
                }),
            });
            var layer_branch = new ol.layer.Vector({
                source: new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(map_info['layers'][1]) })
            });
            var layer_region = new ol.layer.Vector({
                source: new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(map_info['layers'][2]) })
            });
            var layer_ambon = new ol.layer.Vector({
                source: new ol.source.Vector({ features: (new ol.format.GeoJSON()).readFeatures(map_info['layers'][3]) })
            });

            var view=new ol.View({
                center: [{{map.pos_x}}, {{map.pos_y}}],
                zoom: {{map.zoom}}
            });
        }else {
            var layer_area = new ol.layer.Vector({
                source: new ol.source.Vector({ features: new ol.Collection() })
            });
            var layer_branch = new ol.layer.Vector({
                source: new ol.source.Vector({ features: new ol.Collection() })
            });
            var layer_region = new ol.layer.Vector({
                source: new ol.source.Vector({ features: new ol.Collection() })
            });
            var layer_ambon = new ol.layer.Vector({
                source: new ol.source.Vector({ features: new ol.Collection() })
            });
            var view=new ol.View({
                center: [2097096.387839827, 6887410.172738342],
                zoom: 5
            });
        }
绘图功能:

$("#draw_ambon").on("click", function(){
    var layer=manager["ambon"];
    map.removeInteraction(draw);
    select !== null ? map.removeInteraction(select) : 0;
    setInteraction(layer.getSource().getFeaturesCollection(), "Point");
    layer.setStyle(pointStyleFunction);
    layer.setMap(map);

    draw.on("drawend", function(e){
        layer.getSource().addFeatures(e.feature);
        e.feature.setProperties({
            'id': layer.getSource().getFeaturesCollection().getLength(),
            'type': "ambona",
            'name': ''
        })
    })
});
我解决了。 只需将类别集合添加到源中的“功能”选项:

source: new ol.source.Vector({ features: new ol.Collection(new ol.format.GeoJSON()).readFeatures(map_info['layers'][1])) })