简体   繁体   中英

Display Raster Layer using ArcGIS Javascript API

I Want to display a raster layer on to my page using ArcGIS javascript API. Loading Feature layer is easy and pretty forward but the raster layer is giving me hard time.

Here is the the MapService: http://ags.servirlabs.net/ArcGIS/rest/services/ReferenceNode/TRMM_30DAY/MapServer/0 which is Raster layer.

Do you have any ideas on how to do this?

How you add a map service layer depends on whether or not the service is cached. Look at http://ags.servirlabs.net/ArcGIS/rest/services/ReferenceNode/TRMM_30DAY/MapServer in a browser and see the following:

: false :false

Because it's not cached, you must use ArcGISDynamicMapServiceLayer , not ArcGISTiledMapServiceLayer . If it were cached, you could use either one.

map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer(
    "http://ags.servirlabs.net/ArcGIS/rest/services/ReferenceNode/TRMM_30DAY/MapServer"));

Note that if you had a service with multiple layers in it and you wanted to display only a subset of them, you would create an ArcGISDynamicMapServiceLayer and then use its setVisibleLayers method to set which layers should be visible. In this case, you don't need to worry about it, because your map has only one layer in it.

You can add raster layers to your map using the ArcGISTiledMapService layer, for example:

// assuming 'map' is a reference to your map
map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://ags.servirlabs.net/ArcGIS/rest/services/ReferenceNode/TRMM_30DAY/MapServer"));

There are some good examples on the ArcGIS JavaScript API site here:

https://developers.arcgis.com/en/javascript/jssamples/#tiled_layers

One thing to be aware of with tiled layers is that you can only add tiled layers to your map if they are using the same spatial reference. You can't add a layer as a tiled layer with a different spatial reference as it's cache of tiles have already been produced using it's spatial reference. You can add a layer as a Dynamic layer to re-project it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM