Reputation: 19
As u know, it's easy to Add a dynamic shp layer with FeatureLayer Class in arcgis for javascript, i thought it's same in Raster Layer, but no, so how can i Add a dynamic Raster Layer with arcgis for javascript?
Upvotes: 0
Views: 764
Reputation: 19
Thank you for your answer @Below the Radar, my situation is that I have a number of layers to show , so i can't publish them as service, I found that it support dynamic layer after ArcGIS Server v10.1, but yesterday I don't found how to add a Raster Layer dynamicly (not as a MapService), now i have solved this problem, here's that code:
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);
});
Thank you very much
Upvotes: 1
Reputation: 7635
As you tagged your question with arcgis-server, I assume you have access to ArcGIS Server or ArcGIS Online.
With ArcGIS javascript API v4.9, you can add a raster layer published in MapService using a MapImageLayer
with RasterDataSource
subLayer
.
With the javascript API v4.9, instantiate a MapImageLayer
using the url or your MapService
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
}
}
}]
});
See this example: https://developers.arcgis.com/javascript/latest/sample-code/layers-dynamicdatalayer-raster/index.html
Upvotes: 0