为JavaScript

时间:2018-12-04 01:27:42

标签: arcgis arcgis-js-api arcgis-server

如您所知,在arcgis中为JavaScript添加带有FeatureLayer类的动态shp图层很容易,我以为在Raster Layer中是相同的,但是不行,那么我如何为arcgis为JavaScript添加动态栅格层? >

2 个答案:

答案 0 :(得分:1)

谢谢您的回答@雷达下方,我的情况是要显示许多图层,所以我无法将它们作为服务发布,我发现它在ArcGIS Server v10.1之后支持动态图层,但是昨天我没有找到如何动态添加栅格图层(而不是作为MapService),现在我已经解决了这个问题,这是该代码:

var dynamicLayer = new ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/labWorldFolder/labWorldService/MapServer");
var map = new Map("mapDiv");
map.addLayer(dynamicLayer); 

$("#btnAddRasterLayer").click(function() {
    var dynamicLayerInfos = [];
    var dynamicLayerInfo = new DynamicLayerInfo();  // set dynamicLayerInfo
    dynamicLayerInfo.id = 1;

    var dataSource = new RasterDataSource();        // define a rasterDataSource
    dataSource.workspaceId = "labWorldRasterWS";
    dataSource.dataSourceName = "./test_d.img";

    var layerSource = new LayerDataSource();      
    layerSource.dataSource = dataSource;

    dynamicLayerInfo.source = layerSource;  
    dynamicLayerInfos.push(dynamicLayerInfo);

    dynamicLayer.setDynamicLayerInfos(dynamicLayerInfos, false);
});

非常感谢您

答案 1 :(得分:0)

当您使用arcgis-server标记问题时,我假设您有权访问ArcGIS Server或ArcGIS Online。

使用ArcGIS javascript API v4.9,您可以使用MapImageLayerRasterDataSource subLayer添加在MapService中发布的栅格图层。

  1. 使用ArcMap或ArcPro将栅格图层添加到工作空间中
  2. 将您的工作空间作为MapService发布到ArcGIS Server或ArcGIS Online
  3. 使用javascript API v4.9,使用url或您的MapService实例化MapImageLayer

    var layer = new MapImageLayer({
        url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services  /USA/MapServer",  //map service url
        sublayers: [{
            title: "Slope",
            source: {
                type: "data-layer",
                dataSource: {
                    type: "raster",
                    workspaceId: "MyDatabaseWorkspaceIDSSR2", //registered workspace id,
                    dataSourceName: "slope" //raster name
                }
            }
        }]
    });
    

请参见以下示例:https://developers.arcgis.com/javascript/latest/sample-code/layers-dynamicdatalayer-raster/index.html