Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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/6/cplusplus/141.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 打开第3层标签赢得';不显示_Javascript_Labels_Openlayers 3 - Fatal编程技术网

Javascript 打开第3层标签赢得';不显示

Javascript 打开第3层标签赢得';不显示,javascript,labels,openlayers-3,Javascript,Labels,Openlayers 3,我正在尝试使我的地图显示标签。但我的地图上没有显示文字。没有错误。以下是我创建样式的方式: labelItem = {name: "name1", font: "arial", fontSize: 20} computeFeatureStyle = function(labelItem) { return new ol.style.Style( { stroke: new ol.style.Stroke({ c

我正在尝试使我的地图显示标签。但我的地图上没有显示文字。没有错误。以下是我创建样式的方式:

labelItem = {name: "name1", font: "arial", fontSize: 20}
computeFeatureStyle = function(labelItem) {
    return new ol.style.Style(
        {   
            stroke: new ol.style.Stroke({
                color: 'black'
            }),
            text: new ol.style.Text(
                {
                    font: labelItem.fontSize + "px helvetica," + labelItem.font,
                    text: labelItem.name,
                    fill: new ol.style.Fill(
                        {
                            color: "#000" //labelItem.fill_color
                        }),
                    stroke: new ol.style.Stroke(
                        {
                            color: "#fff", //labelItem.stroke_color,
                            width: 2
                        }),
                })
        });
};
在这里,我创建图层对象:

labelData = [{name: "name1", font: "arial", fontSize: 20}]
createLabelLayer = function() {
    // Geometries
    // Source and vector layer
    var vectorSource = new ol.source.Vector({ projection: 'EPSG:4326' });
    var layer = new ol.layer.Vector({ source: vectorSource });
    var labelFeatures = [];
    for(var i = 0; i < labelData.length; ++i ) {
        var labelItem = labelData[i];
        var point = new ol.geom.Point(convertCoordinateToWeb( Ext.getCmp("map").map.getView().getCenter()) );
        var feature = new ol.Feature({
                                         geometry: point,
                                         name: labelItem.name
                                     });
        feature.setStyle([this.computeFeatureStyle(labelItem)]);
        vectorSource.addFeature( feature );
    }
    vectorSource.addFeatures(labelFeatures);

    return layer
};
labelData=[{name:“name1”,font:“arial”,fontSize:20}]
createLabelLayer=函数(){
//几何学
//源矢量层
var vectorSource=new ol.source.Vector({projection:'EPSG:4326'});
var layer=newol.layer.Vector({source:vectorSource});
var labelFeatures=[];
对于(变量i=0;i
这是我的向量层。我做了地图。添加图层(图层) 但是这些标签不会显示在地图上。我做错了什么

我还尝试将样式对象直接添加到向量:
layer.setStyle(computeFeatureStyle(labelItem)),它仍然不起作用。

调试代码的最佳方法是稍微分解一下。例如,与其直接在style函数中返回样式,不如先将其放入变量中。然后,在您最喜欢的浏览器开发工具中,在返回样式的行上放置一个断点。它将允许您监视样式的内容,并查看是否存在错误

另外,检查“静态”值是否有效。硬编码您期望的结果值,只是为了测试

您可以查看以下示例,这也会有所帮助: