L.esri.DynamicMapLayer

Extends L.esri.RasterLayer

Render and visualize Map Services from ArcGIS Enterprise. L.esri.DynamicMapLayer also supports custom popups and identification of features.

Map Services are used when its preferable to ask the server to draw layers and pass back the image which was generated on the fly instead of attempting to render client-side graphics. It is possible to control which specific layers from the Map Service are displayed using the layers constructor option.

Map Service URLs do not end in a number.

Use dark colors for code blocksCopy
1
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/

Constructor

ConstructorDescription
L.esri.dynamicMapLayer(<Object> options)The options parameter can accept the same options as L.ImageOverlay.Passing a url is mandatory.

Options

OptionTypeDefaultDescription
urlStringRequired URL of the Map Service.
formatString'png24'Output format of the image.
transparentBooleantrueAllow the server to produce transparent images.
fString'json'Server response content type "json" | "image".
attributionStringAttribution from service metadata copyright text is automatically displayed in Leaflet's default control. This property can be used for customization.
layersArrayAn array of Layer IDs like [3,4,5] to show from the service.
layerDefsObjectSQL filters to define what features will be included in the image rendered by the service. An object is used with keys that map each query to its respective layer. { 3: "STATE_NAME='Kansas'", 9: "POP2007>25000" }
opacityNumber1Opacity of the layer. Should be a value between 0 (completely transparent) and 1 (completely opaque).
paneStringoverlayPaneThe map pane to render on. This is the preferred technique to control draw order in Leaflet 1.x.
zIndexNumberUsed to refine draw order further (within a map pane).
positionString'front'Legacy option to control draw order. For best results, use pane.
maxZoomNumberClosest zoom level the layer will be displayed on the map.
minZoomNumberFurthest zoom level the layer will be displayed on the map.
dynamicLayers[Object]Array of one or more JSON objects used to override the layer symbology defined by the service. Requires a 10.1+ map service which supports dynamicLayers requests.
disableCacheBooleanIf enabled, appends a timestamp to each request to ensure a fresh image is created server-side.
tokenStringIf you pass a token in your options it will be included in all requests to the service.
proxyStringfalseURL of an ArcGIS API for JavaScript proxy or ArcGIS Resource Proxy to use for proxying POST requests.
useCorsBooleantrueIf this service should use CORS when making GET requests.
popupObjectInstance of IdentifyFeatures to allow for more fine-grained control over the /identify request triggered by 'bindPopup()'.
toDateUsed to filter the features displayed in the service based on a time range.
fromDateUsed to filter the features displayed in the service based on a time range.

Methods

MethodReturnsDescription
bringToBack()thisRedraws this layer below all other overlay layers.
bringToFront()thisRedraws this layer above all other overlay layers.
bindPopup(<Function> fn, <PopupOptions> popupOptions)this

Uses the provided function to create a popup that will identify features whenever the map is clicked. Your function will be passed a GeoJSON FeatureCollection of the features at the clicked location and should return the appropriate HTML. If you do not want to open the popup when there are no results, return false.

dynamicMapLayer.bindPopup(function(err, featureCollection, response){
    var count = featureCollection.features.length;
    return (count) ? count + ' features' : false;
});
unbindPopup()thisRemoves a popup previously bound with bindPopup.
getOpacity()FloatReturns the current opacity of the layer.
setOpacity(<Float> opacity)thisSets the opacity of the layer.
getLayers()ArrayReturns the array of visible layers specified in the layer constructor.
setLayers(<Array> layers)thisRedraws the layer to show the passed array of layer ids.
getLayerDefs()ObjectReturns the current layer definition(s) being used for rendering.
setLayerDefs(<Object> layerDefs)thisRedraws the layer with the new layer definitions. Corresponds to the layerDefs option on the export API.
getTimeRange()ArrayReturns the current time range being used for rendering.
setTimeRange(<Date> from, <Date> to)thisRedraws the layer with he passed time range.
getTimeOptions()ObjectReturns the current time options being used for rendering.
setTimeOptions(<Object> timeOptions)thisSets the current time options being used to render individual layers. Corresponds to the layerTimeOptions option on the export API.
getDynamicLayers()[Object]Returns an array of JSON objects representing the modified layer symbology being requested from the map service.
setDynamicLayers(<Array> dynamicLayers)this

Used to insert raw dynamicLayers JSON in array form in situations where you'd like to modify layer symbology defined in the service itself.

dynamicMapLayer.setDynamicLayers([{
    ...
    "drawingInfo": { ... }
}]);
metadata(<Function> callback, <Object> context)this

Requests metadata about this Feature Layer. Callback will be called with error and metadata.

dynamicMapLayer.metadata(function(error, metadata){
    console.log(metadata);
});
authenticate(<String> token)thisAuthenticates this service with a new token and runs any pending requests that required a token.
identify()this

Returns a new L.esri.services.IdentifyFeatures object that can be used to identify features on this layer. Your callback function will be passed a GeoJSON FeatureCollection with the results or an error.

dynamicMapLayer.identify()
.at(latlng)
.run(function(error, featureCollection){
    console.log(featureCollection);
});
find()this

Returns a new L.esri.services.Find object that can be used to find features. Your callback function will be passed a GeoJSON FeatureCollection with the results or an error.

dynamicMapLayer.find()
.layers('18')
.text('Colorado')
.run(function(error, featureCollection){
    console.log(featureCollection);
});
query()this

Returns a new L.esri.Query object that can be used to query this service.

mapService.query()
.layer(0)
.within(latlngbounds)
.run(function(error, featureCollection, response){
    console.log(featureCollection);
});
redraw()Used to make a fresh request to the service and draw the response.

Events

EventDataDescription
loading<LoadingEvent>Fires when new features start loading.
load<LoadEvent>Fires when all features in the current bounds of the map have loaded.

L.esri.DynamicMapLayer also fires all L.esri.MapService events.

Example

Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
      const map = L.map("map").setView([37.71, -99.88], 4);

      L.esri.Vector.vectorBasemapLayer("arcgis/imagery/standard", {
        token: accessToken
      }).addTo(map);

      L.esri
        .dynamicMapLayer({
          url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
          opacity: 0.7
        })
        .addTo(map);
Expand

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.