使用UniqueValueRenderer的问题-颜色未显示在chrome中,但已在Firefox和Edge中显示

时间:2019-07-11 11:37:47

标签: arcgis arcgis-js-api

我想使用ArcGIS Javascript API将Legends功能用于ArcGIS。所以我在我的CSVLayer中使用UniqueValueRenderer。

CSVLayer正确显示。但是,当我使用Google Chrome浏览器显示时,在所有情况下都会呈现defaultSymbol。但是当我使用Mozilla Firefox或Microsoft Edge进行查看时,效果很好。

Chrome的屏幕截图:Screenshot - Chrome

Firefox的屏幕截图:Screenshot - Firefox

var renderer = new UniqueValueRenderer({
    defaultLabel: "Other files",
    field: "Category",
    defaultSymbol: {
        type: "point-3d", // autocasts as new PointSymbol3D()
        symbolLayers: [{
            type: "icon", // autocasts as new IconSymbol3DLayer()
            material: {
                color: "#ABB2B9"
            },
            outline: {
                width: 0.2,
                color: p6
            },
            size: "12px"
        }]
    }, // autocasts as new SimpleFillSymbol()
    legendOptions: {
        title: "File type"
    }
});


renderer.addUniqueValueInfo({
    label: "Drawing",
    description: "Drawing files(.dwg, .rvt etc.)",
    value: "1",
    symbol: {
        type: "point-3d", // autocasts as new PointSymbol3D()
        symbolLayers: [{
            type: "icon", // autocasts as new IconSymbol3DLayer()
            material: {
                color: "#2ECC71"
            },
            outline: {
                width: 0.8,
                color: p6
            },
            size: "12px"
        }]
    }
});

renderer.addUniqueValueInfo({
    label: "Specter",
    description: "Specter files.",
    value: "2",
    symbol: {
        type: "point-3d", // autocasts as new PointSymbol3D()
        symbolLayers: [{
            type: "icon", // autocasts as new IconSymbol3DLayer()
            material: {
                color: "#F3AD12"
            },
            outline: {
                width: 0.8,
                color: p6
            },
            size: "12px"
        }]
    }
});

renderer.addUniqueValueInfo({
    label: "Snapshots",
    description: "Image files (.jpg, .png, .bmp etc.)",
    value: "3",
    symbol: {
        type: "point-3d", // autocasts as new PointSymbol3D()
        symbolLayers: [{
            type: "icon", // autocasts as new IconSymbol3DLayer()
            material: {
                color: "#E74C3C"
            },
            outline: {
                width: 0.8,
                color: p6
            },
            size: "12px"
        }]
    }
});

renderer.addUniqueValueInfo({
    label: "Documents",
    description: "Office files (.doc, .xls, .xlsx etc.)",
    value: "4",
    symbol: {
        type: "point-3d", // autocasts as new PointSymbol3D()
        symbolLayers: [{
            type: "icon", // autocasts as new IconSymbol3DLayer()
            material: {
                color: "#A569BD"
            },
            outline: {
                width: 0.8,
                color: p6
            },
            size: "12px"
        }]
    }
});

这些是我的CSVFile中的内容

Latitude,Longitude,Depth,DocumentId,FileId,DocumentNumber,DocumentCreatedByUserName,DocumentDescription,RevisionNoValue,Category,OriginalFileName
"28.963349","77.684915","0","STR##104440","105134","ENGG-DOC-DEC-004","User","Description 1","0","0",""
"28.792274","77.522666","0","STR##102182","103587","ENGG-CIV-003","User","Description 2","0","2","ENGG-CIV-003.pdf"

整个ArcGIS代码

require([
    "esri/Map",
    "esri/layers/CSVLayer",
    "esri/views/SceneView",
    "esri/widgets/BasemapGallery",
    "esri/widgets/Expand",
    "esri/widgets/Locate",
    "esri/widgets/Search",
    "esri/Graphic",
    "esri/PopupTemplate",
    "esri/renderers/UniqueValueRenderer",
    "esri/widgets/Legend"
], function(Map, CSVLayer, SceneView, BasemapGallery, Expand, Locate, Search, Graphic, PopupTemplate, UniqueValueRenderer, Legend) {
    // If CSV files are not on the same domain as your website, a CORS enabled server
    // or a proxy is required.
    debugger;

    var renderer = new UniqueValueRenderer({
        defaultLabel: "Other files",
        field: "Category",
        defaultSymbol: {
            type: "point-3d",
            symbolLayers: [{
                type: "icon", 
                material: {
                    color: "#ABB2B9"
                },
                outline: {
                    width: 0.2,
                    color: p6
                },
                size: "12px"
            }]
        }, // autocasts as new SimpleFillSymbol()
        legendOptions: {
            title: "File type"
        }
    });

    renderer.addUniqueValueInfo({
        label: "Drawing",
        description: "Drawing files(.dwg, .rvt etc.)",
        value: "1",
        symbol: {
            type: "point-3d",
            symbolLayers: [{
                type: "icon",
                material: {
                    color: "#2ECC71"
                },
                outline: {
                    width: 0.8,
                    color: p6
                },
                size: "12px"
            }]
        }
    });

    renderer.addUniqueValueInfo({
        label: "Specter",
        description: "Specter files.",
        value: "2",
        symbol: {
            type: "point-3d",
            symbolLayers: [{
                type: "icon",
                material: {
                    color: "#F3AD12"
                },
                outline: {
                    width: 0.8,
                    color: p6
                },
                size: "12px"
            }]
        }
    });

    renderer.addUniqueValueInfo({
        label: "Snapshots",
        description: "Image files (.jpg, .png, .bmp etc.)",
        value: "3",
        symbol: {
            type: "point-3d", 
            symbolLayers: [{
                type: "icon",
                material: {
                    color: "#E74C3C"
                },
                outline: {
                    width: 0.8,
                    color: p6
                },
                size: "12px"
            }]
        }
    });

    renderer.addUniqueValueInfo({
        label: "Documents",
        description: "Office files (.doc, .xls, .xlsx etc.)",
        value: "4",
        symbol: {
            type: "point-3d",
            symbolLayers: [{
                type: "icon", 
                material: {
                    color: "#A569BD"
                },
                outline: {
                    width: 0.8,
                    color: p6
                },
                size: "12px"
            }]
        }
    });

    var url = '<valid csv file url>';



    var template = {
        title: "Document basic info - {DocumentNumber}",
        content: "Document number: {DocumentNumber}," +
            "<br/>Description: {DocumentDescription}" +
            "<br/>Revision no: {RevisionNoValue}" +
            "<br/>File name: {OriginalFileName}" +
            "<br/>Created by: {DocumentCreatedByUserName}" +
            "<br/><br/><a href='#' onclick='ViewDocumentDetails(`{DocumentId}`)'>Click here</a> to view the document details"
    };



    var csvLayer = new CSVLayer({
        title: "Documents",
        url: url,
        copyright: "Wrench Solutions",
        popupTemplate: template,
        elevationInfo: {
            // drapes icons on the surface of the globe
            mode: "on-the-ground"
        },
        renderer: renderer
    });



    var map = new Map({
        basemap: "topo",
        ground: "world-elevation",
        layers: [csvLayer]
    });

    var view = new SceneView({
        container: "viewDiv",
        center: [138, 35],
        zoom: 4,
        map: map
    });

    var basemapGallery = new BasemapGallery({
        view: view,
        container: document.createElement("div")
    });

    var locateBtn = new Locate({
        view: view
    });

    var search = new Search({
        view: view
    });


    view.ui.add(search, "top-right");


    var bgExpand = new Expand({
        view: view,
        content: basemapGallery
    });

    view.ui.add(locateBtn, {
        position: "top-left"
    });

    view.ui.add(bgExpand, "bottom-right");

    var legendExpand = new Expand({
        view: view,
        content: new Legend({
            view: view,
            style: "card",
        })
    });

    view.ui.add(legendExpand, "bottom-left");

    $(".esri-attribution__sources").css('display', 'none');
});

我想知道这是整个ArcGIS Online的问题,还是ArcGIS Online中存在类似的问题。

1 个答案:

答案 0 :(得分:0)

似乎Chrome浏览器对CSV中的字段的解释与Firefox不同。在Chrome中,字段DocumentIDCategoryRevisionNoValue被解释为日期,这就是UniqueValueRenderer的值都不匹配的原因。

您必须选择:

  1. 通过删除数字周围的引号(")来固定CSV
  2. 告诉CSVLayer具体是您的CSV文件中的type of fields

    var csvLayer = new CSVLayer({
      title: "Documents",
      url: url,
      copyright: "Wrench Solutions",
      popupTemplate: template,
      elevationInfo: {
        // drapes icons on the surface of the globe
        mode: "on-the-ground"
      },
      renderer: renderer,
      fields: [
        {
          alias: "__OBJECTID",
          name: "__OBJECTID",
          type: "oid"
        },{
          alias: "Latitude",
          name: "Latitude",
          type: "double"
        },
    
        ... 
    
        ,{
          alias: "Category",
          name: "Category",
          type: "integer"
        },{
          alias: "OriginalFileName",
          name: "OriginalFileName",
          type: "string"
        }
      ]
    });
    

有关完整的源代码,请参见以下Codepen https://codepen.io/arnofiva/pen/cba32aedd13ceec9719cbf20b485f458