esri-leaflet
Version:
Leaflet plugins for consuming ArcGIS Online and ArcGIS Server services.
438 lines (404 loc) • 18.9 kB
HTML
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class="not-ie"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<title>L.esri.Layers.DynamicMapLayer | Esri Leaflet</title>
<meta name="description" content="Esri Leaflet">
<meta name="viewport" content="width=device-width">
<!--[if lt IE 9]>
<script src="//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv-printshiv.js"></script>
<![endif]-->
<!-- google fonts -->
<link href='//fonts.googleapis.com/css?family=Vollkorn:400italic,700italic,400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//brick.a.ssl.fastly.net/Source+Code+Pro:300">
<link href='//fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<!-- stylesheet -->
<link rel="stylesheet" href="../../css/style.css">
<!-- leaflet -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/leaflet/0.7.7/leaflet.css" />
<!-- require combined leaflet, esri leaflet and jsdelivr-rum -->
<script src="//cdn.jsdelivr.net/leaflet/0.7.7/leaflet.js"></script>
<!--script src="//cdn.jsdelivr.net/leaflet.esri/1.0.3/esri-leaflet.js"></script-->
<script src="../../js/esri-leaflet-src.js"></script>
<script src="//cdn.jsdelivr.net/jsdelivr-rum/latest/jsdelivr-rum.min.js"></script>
<!-- 'livereload' for development -->
<script src="//localhost:35729/livereload.js"></script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44963317-3', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
</head>
<body>
<div class="page-content ">
<div class="container">
<a class="site-nav" href="../../" class="left logo">Esri Leaflet</a>
<nav class="right">
<a class="site-nav" href="../../examples/">Examples</a>
<a class="site-nav" href="../../api-reference/">API Reference</a>
<a class="site-nav" href="../../download/">Download</a>
<a class="site-nav" href="https://github.com/Esri/esri-leaflet">View on GitHub</a>
</nav>
</div>
<div id="background-map" class="background-map"></div>
<div class="container white">
<aside class="sidebar">
<h5>L.esri.Layers</h5>
<nav>
<a href="../../api-reference/layers/basemap-layer.html">BasemapLayer</a>
<a href="../../api-reference/layers/feature-layer.html">FeatureLayer</a>
<a href="../../api-reference/layers/tiled-map-layer.html">TiledMapLayer</a>
<a href="../../api-reference/layers/dynamic-map-layer.html">DynamicMapLayer</a>
<a href="../../api-reference/layers/image-map-layer.html">ImageMapLayer</a>
<a href="../../api-reference/layers/clustered-feature-layer.html">ClusteredFeatureLayer</a>
<a href="../../api-reference/layers/heatmap-feature-layer.html">HeatmapFeatureLayer</a>
</nav>
<h5>L.esri.Tasks</h5>
<nav>
<a href="../../api-reference/tasks/query.html">Query</a>
<a href="../../api-reference/tasks/find.html">Find</a>
<a href="../../api-reference/tasks/identify-features.html">Identify Features</a>
<a href="../../api-reference/tasks/identify-image.html">Identify Image</a>
<a href="../../api-reference/tasks/task.html">Task</a>
</nav>
<h5>Misc.</h5>
<nav>
<a href="../../api-reference/request.html">Request</a>
<a href="../../api-reference/util.html">Util</a>
<a href="../../api-reference/events.html">Events</a>
</nav>
<h5>Base Classes</h5>
<nav>
<a href="../../api-reference/services/image-service.html">ImageService</a>
<a href="../../api-reference/services/feature-layer.html">FeatureLayerService</a>
<a href="../../api-reference/services/map-service.html">MapService</a>
<a href="../../api-reference/services/service.html">Service</a>
</nav>
</aside>
<div class="main-content">
<h1 id="l-esri-layers-dynamicmaplayer">L.esri.Layers.DynamicMapLayer</h1>
<!-- Inherits from [`L.esri.Layers.RasterLayer`](../../api-reference/layers/raster-layer.html) -->
<p>Render and visualize Map Services from ArcGIS Online and ArcGIS Server. L.esri.Layers.DynamicMapLayer also supports custom popups and identification of features.</p>
<p>Map Services are a way to expose the contents of a map as a web service and expose capabilities for exporting tile images, querying and identifying features and more.</p>
<h3 id="constructor">Constructor</h3>
<table>
<thead>
<tr>
<th>Constructor</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>L.esri.dynamicMapLayer(<nobr class="param"><span><Object></span> <code>options</code></nobr>)</code></td>
<td>The <code>options</code> parameter can accept the same options as <a href="http://leafletjs.com/reference.html#imageoverlay"><code>L.ImageOverlay</code></a>. You also must pass a <code>url</code> key in your <code>options</code>.</td>
</tr>
</tbody>
</table>
<h3 id="options">Options</h3>
<p><code>L.esri.DynamicMapLayer</code> also accepts all the options you can pass to <a href="http://leafletjs.com/reference.html#imageoverlay"><code>L.ImageOverlay</code></a>.</p>
<table>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>url</code></td>
<td><code>String</code></td>
<td></td>
<td><em>Required</em> URL of the <a href="http://resources.arcgis.com/en/help/arcgis-rest-api/#/Map_Service/02r3000000w2000000/">Map Service</a>.</td>
</tr>
<tr>
<td><code>format</code></td>
<td><code>String</code></td>
<td><code>'png24'</code></td>
<td>Output format of the image.</td>
</tr>
<tr>
<td><code>transparent</code></td>
<td><code>Boolean</code></td>
<td><code>true</code></td>
<td>Allow the server to produce transparent images.</td>
</tr>
<tr>
<td><code>f</code></td>
<td><code>String</code></td>
<td><code>'json'</code></td>
<td>Server response content type.</td>
</tr>
<tr>
<td><code>bboxSR</code></td>
<td><code>Integer</code></td>
<td><code>4326</code></td>
<td>Spatial reference of the bounding box to generate the image with. If you don't know what this is don't change it.</td>
</tr>
<tr>
<td><code>imageSR</code></td>
<td><code>Integer</code></td>
<td><code>3857</code></td>
<td>Spatial reference of the output image. If you don't know what this is don't change it.</td>
</tr>
<tr>
<td><code>layers</code></td>
<td><code>Array</code></td>
<td><code>''</code></td>
<td>An array of Layer IDs like <code>[3,4,5]</code> to show from the service.</td>
</tr>
<tr>
<td><code>layerDefs</code></td>
<td><code>String</code> <code>Object</code></td>
<td><code>''</code></td>
<td>A string representing a query to run against the service before the image is rendered. This can be a string like <code>"STATE_NAME='Kansas' and POP2007>25000"</code> or an object mapping different queries to specific layers <code>{5:"STATE_NAME='Kansas'", 4:"STATE_NAME='Kansas'}</code>.</td>
</tr>
<tr>
<td><code>opacity</code></td>
<td><code>Number</code></td>
<td><code>1</code></td>
<td>Opacity of the layer. Should be a value between 0 (completely transparent) and 1 (completely opaque).</td>
</tr>
<tr>
<td><code>position</code></td>
<td><code>String</code></td>
<td><code>'front'</code></td>
<td>Position of the layer relative to other overlays.</td>
</tr>
<tr>
<td><code>dynamicLayers</code></td>
<td><code>Object</code></td>
<td><code>null</code></td>
<td>JSON object literal used to manipulate the layer symbology defined in the service itself. Requires a 10.1 (or above) map service which supports <a href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Map/02r3000000v7000000/">dynamicLayers</a> requests.</td>
</tr>
<tr>
<td><code>token</code></td>
<td><code>String</code></td>
<td><code>null</code></td>
<td>If you pass a token in your options it will be included in all requests to the service.</td>
</tr>
<tr>
<td><code>proxy</code></td>
<td><code>String</code></td>
<td><code>false</code></td>
<td>URL of an <a href="https://developers.arcgis.com/javascript/jshelp/ags_proxy.html">ArcGIS API for JavaScript proxy</a> or <a href="https://github.com/Esri/resource-proxy">ArcGIS Resource Proxy</a> to use for proxying POST requests.</td>
</tr>
<tr>
<td><code>useCors</code></td>
<td><code>Boolean</code></td>
<td><code>true</code></td>
<td>If this service should use CORS when making GET requests.</td>
</tr>
</tbody>
</table>
<h3 id="methods">Methods</h3>
<table>
<thead>
<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>bringToBack()</code></td>
<td><code>this</code></td>
<td>Redraws this layer below all other overlay layers.</td>
</tr>
<tr>
<td><code>bringToFront()</code></td>
<td><code>this</code></td>
<td>Redraws this layer above all other overlay layers.</td>
</tr>
<tr>
<td><code>bindPopup(<nobr class="param"><span><Function></span> <code>fn</code></nobr>, <nobr class="param"><span><<a href="http://leafletjs.com/reference.html#popup-options">PopupOptions</a>></span> <code>popupOptions</code></nobr>)</code></td>
<td><code>this</code></td>
<td>
Uses the provided function to create a popup that will identify features whenever the map is clicked. Your function will be passed a <a href="http://geojson.org/geojson-spec.html#feature-collection-objects">GeoJSON FeatureCollection</a> 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 <code>false</code>.
<pre class="js"><code>
dynamicMapLayer.bindPopup(
function(err, featureCollection, response){
var count = featureCollection.features.length;
return (count) ? count + ' features' : false;
});</code></pre>
</td>
</tr>
<tr>
<td><code>unbindPopup()</code></td>
<td><code>this</code></td>
<td>Removes a popup previously bound with <code>bindPopup</code>.</td>
</tr>
<tr>
<td><code>getOpacity()</code></td>
<td><code>Float</code></td>
<td>Returns the current opacity of the layer.</td>
</tr>
<tr>
<td><code>setOpacity(<nobr class="param"><span><Float></span> <code>opacity</code></nobr>)</code></td>
<td><code>this</code></td>
<td>Sets the opacity of the layer.</td>
</tr>
<tr>
<td><code>getLayers()</code></td>
<td><code>Array</code></td>
<td>Returns the array of layers on the MapService that are being shown.</td>
</tr>
<tr>
<td><code>setLayers(<nobr class="param"><span><Array></span> <code>layers</code></nobr>)</code></td>
<td><code>this</code></td>
<td>Redraws the layer to show the passed array of layer ids.</td>
</tr>
<tr>
<td><code>getLayerDefs()</code></td>
<td><code>Object</code></td>
<td>Returns the current layer definition(s) being used for rendering.</td>
</tr>
<tr>
<td><code>setLayerDefs(<nobr class="param"><span><<a href="http://resources.arcgis.com/en/help/arcgis-rest-api/#/Export_Map/02r3000000v7000000/">Object</a>></span> <code>layerDefs</code></nobr>)</code></td>
<td><code>this</code></td>
<td>Redraws the layer with the new layer definitions. Corresponds to the <a href="http://resources.arcgis.com/en/help/arcgis-rest-api/#/Export_Map/02r3000000v7000000/">layerDefs</a> option on the export API.</td>
</tr>
<tr>
<td><code>getTimeRange()</code></td>
<td><code>Array</code></td>
<td>Returns the current time range being used for rendering.</td>
</tr>
<tr>
<td><code>setTimeRange(<nobr class="param"><span><Date></span> <code>from</code></nobr>, <nobr class="param"><span><Date></span> <code>to</code></nobr>)</code></td>
<td><code>this</code></td>
<td>Redraws the layer with he passed time range.</td>
</tr>
<tr>
<td><code>getTimeOptions()</code></td>
<td><code>Object</code></td>
<td>Returns the current time options being used for rendering.</td>
</tr>
<tr>
<td><code>setTimeOptions(<nobr class="param"><span><<a href="http://resources.arcgis.com/en/help/arcgis-rest-api/#/Export_Map/02r3000000v7000000/">Object</a>></span> <code>timeOptions</code></nobr>)</code></td>
<td><code>this</code></td>
<td>Sets the current time options being used to render the layer. Corresponds to the <a href="http://resources.arcgis.com/en/help/arcgis-rest-api/#/Export_Map/02r3000000v7000000/">layerTimeOptions</a> option on the export API.</td>
</tr>
<tr>
<td><code>getDynamicLayers()</code></td>
<td><code>Object</code></td>
<td>Returns a JSON object representing the modified layer symbology being requested from the map service.</td>
</tr>
<tr>
<td><code>setDynamicLayers(<nobr class="param"><span><Object></span> <code>layers</code></nobr>)</code></td>
<td><code>Object</code></td>
<td>Used to insert raw dynamicLayers JSON in situations where you'd like to modify layer symbology defined in the service itself.
<pre class="js"><code>dynamicMapLayer.setDynamicLayers([{
...
"drawingInfo": { ... }
}]);
</code></pre>
</td>
</tr>
<tr>
<td><code>metadata(<nobr class="param"><span><Function></span> <code>callback</code></nobr>, <nobr class="param"><span><Object></span> <code>context</code></nobr>)</code></td>
<td><code>this</code></td>
<td>
Requests metadata about this Feature Layer. Callback will be called with <code>error</code> and <code>metadata</code>.
<pre class="js"><code>dynamicMapLayer.metadata(function(error, metadata){
console.log(metadata);
});</code></pre>
</td>
</tr>
<tr>
<td><code>authenticate(<nobr class="param"><span><String></span> <code>token</code></nobr>)</code></td>
<td><code>this</code></td>
<td>Authenticates this service with a new token and runs any pending requests that required a token.</td>
</tr>
<tr>
<td><code>identify()</code></td>
<td><code>this</code></td>
<td>
Returns a new <a href="../..//api-reference/tasks/identify-features.html"><code>L.esri.services.IdentifyFeatures</code></a> object that can be used to identify features on this layer. Your callback function will be passed a <a href="http://geojson.org/geojson-spec.html#feature-collection-objects">GeoJSON FeatureCollection</a> with the results or an error.
<pre class="js"><code>dynamicMapLayer.identify()
.at(latlng, latlngbounds, 5)
.run(function(error, featureCollection){
console.log(featureCollection);
});</code></pre>
</td>
</tr>
<tr>
<td><code>find()</code></td>
<td><code>this</code></td>
<td>
Returns a new <a href="../..//api-reference/tasks/find.html"><code>L.esri.services.Find</code></a> object that can be used to find features. Your callback function will be passed a <a href="http://geojson.org/geojson-spec.html#feature-collection-objects">GeoJSON FeatureCollection</a> with the results or an error.
<pre class="js"><code>dynamicMapLayer.find()
.layers('18')
.searchText('Colorado')
.run(function(error, featureCollection){
console.log(featureCollection);
});</code></pre>
</td>
</tr>
<tr>
<td><code>query()</code></td>
<td><code>this</code></td>
<td>
Returns a new <a href="../../api-reference/tasks/query.html"><code>L.esri.Tasks.Query</code></a> object that can be used to query this service.
<pre class="js"><code>mapService.query()
.layer(0)
.within(latlngbounds)
.run(function(error, featureCollection, response){
console.log(featureCollection);
});</code></pre>
</td>
</tr>
</tbody>
</table>
<h3 id="events">Events</h3>
<table>
<thead>
<tr>
<th>Event</th>
<th>Data</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>loading</code></td>
<td><a href="../../api-reference/events.html#loading-event"><<code>LoadingEvent</code>></a></td>
<td>Fires when new features start loading.</td>
</tr>
<tr>
<td><code>load</code></td>
<td><a href="../../api-reference/events.html#load-event"><<code>LoadEvent</code>></a></td>
<td>Fires when all features in the current bounds of the map have loaded.</td>
</tr>
</tbody>
</table>
<p><code>L.esri.Layers.DynamicMapLayer</code> also fires all <a href="../../api-reference/services/map-service.html"><code>L.esri.Services.MapService</code></a> events.</p>
<h3 id="example">Example</h3>
<pre><code class="language-js"><span class="keyword">var</span> map = L.map(<span class="string">'map'</span>).setView([ <span class="number">38.83</span>,-<span class="number">98.5</span>], <span class="number">7</span>);
L.esri.basemapLayer(<span class="string">'Gray'</span>).addTo(map);
<span class="keyword">var</span> url = <span class="string">"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServer"</span>;
L.esri.dynamicMapLayer(url, {
opacity : <span class="number">0.25</span>
}).addTo(map);</code></pre>
<p><a href="http://github.com/esri/esri-leaflet/edit/master/site/source/pages/api-reference/layers/dynamic-map-layer.md">Edit this page on GitHub</a></p>
</div>
<div style='clear:both;'></div>
</div>
<div class="container centered-text">
<p class="copyright">Esri Leaflet is a project from the <a href="http://pdx.esri.com">Esri PDX R&D Center</a> and the <a href="https://github.com/Esri/esri-leaflet/graphs/contributors">Esri Community</a></p>
</div>
</div>
<script src="../../js/script.js"></script>
</body>
</html>