UNPKG

esri-leaflet

Version:

Leaflet plugins for consuming ArcGIS Online and ArcGIS Server services.

434 lines (399 loc) 25.1 kB
<!DOCTYPE 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.ClusteredFeatureLayer | 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-clusteredfeaturelayer">L.esri.Layers.ClusteredFeatureLayer</h1> <p><code>L.esri.Layers.ClusteredFeatureLayer</code> provides integration for Feature Layers with the <a href="https://github.com/Leaflet/Leaflet.markercluster">Leaflet.markercluster plugin</a>. Because of the extra dependency on Leaflet.markercluster we do not include <code>L.esri.Layers.ClusteredFeatureLayer</code> in the default build of Esri Leaflet. It lives in /dist/extras/clustered-feature-layer.js. You will also need to include your own copy of the <a href="https://github.com/Leaflet/Leaflet.markercluster">Leaflet.markercluster plugin</a>.</p> <p>More information about Feature Layers can be found in the <a href="../../api-reference/layers/feature-layer.html"><code>L.esri.Layers.FeatureLayer</code> documentation</a>.</p> <h3 id="constructor">Constructor</h3> <table> <thead> <tr> <th>Constructor</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code class="nobr">new L.esri.Layers.ClusteredFeatureLayer(<nobr class="param"><span>&lt;String&gt;</span> <code>url</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>options</code></nobr>)</code><br><br><code class="nobr">L.esri.Layers.clusteredFeatureLayer(<nobr class="param"><span>&lt;String&gt;</span> <code>url</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>options</code></nobr>)</code><br><br><code class="nobr">new L.esri.ClusteredFeatureLayer(<nobr class="param"><span>&lt;String&gt;</span> <code>url</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>options</code></nobr>)</code><br><br><code class="nobr">L.esri.clusteredFeatureLayer(<nobr class="param"><span>&lt;String&gt;</span> <code>url</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>options</code></nobr>)</code></td> <td><code>url</code> should be the URL to the Feature Layer.</td> </tr> </tbody> </table> <h3 id="options">Options</h3> <table> <thead> <tr> <th>Option</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>pointToLayer(<nobr class="param"><span>&lt;<a href="http://geojson.org/geojson-spec.html#feature-objects">GeoJSON Feature</a>&gt;</span> <code>feature</code></nobr>, <nobr class="param"><span>&lt;<a href="http://leafletjs.com/reference.html#latlng">LatLng</a>&gt;</span> <code>latlng</code></nobr>)</code></td> <td><code>Function</code></td> <td>Function that will be used for creating layers for GeoJSON points (if not specified, simple markers will be created).</td> </tr> <tr> <td><code>style(<nobr class="param"><span>&lt;<a href="http://geojson.org/geojson-spec.html#feature-objects">GeoJSON Feature</a>&gt;</span> <code>feature</code></nobr>, <nobr class="param"><span>&lt;<a href="http://leafletjs.com/reference.html#ilayer">ILayer</a>&gt;</span> <code>layer</code></nobr>)</code></td> <td><code>Function</code></td> <td>Function that will be used to get style options for vector layers created for GeoJSON features.</td> </tr> <tr> <td><code>onEachFeature(<nobr class="param"><span>&lt;<a href="http://geojson.org/geojson-spec.html#feature-objects">GeoJSON Feature</a>&gt;</span> <code>feature</code></nobr>, <nobr class="param"><span>&lt;<a href="http://leafletjs.com/reference.html#ilayer">ILayer</a>&gt;</span> <code>layer</code></nobr>)</code></td> <td><code>Function</code></td> <td> </td> </tr> <tr> <td><code>where</code></td> <td><code>String</code></td> <td>A server side expression that will be evaluated to filter features. By default this will include all features in a service.</td> </tr> <tr> <td><code>fields</code></td> <td><code>Array</code></td> <td>An array of metadata names to pull from the service. Includes all fields by default.</td> </tr> <tr> <td><code>from</code></td> <td><code>Date</code></td> <td>When paired with <code>to</code> defines the time range of features to display. Required the Feature Layer to be time enabled.</td> </tr> <tr> <td><code>to</code></td> <td><code>Date</code></td> <td>When paired with <code>from</code> defines the time range of features to display. Required the Feature Layer to be time enabled.</td> </tr> <tr> <td><code>timeField</code></td> <td><code>false</code></td> <td>The name of the field to lookup the time of the feature. Can be an object like <code>{start:&#39;startTime&#39;, end:&#39;endTime&#39;}</code> or a string like <code>&#39;created&#39;</code>.</td> </tr> <tr> <td><code>timeFilterMode</code></td> <td><nobr><code>&#39;client&#39;</code> or <code>&#39;server&#39;</code></nobr></td> <td>Determines where features are filtered by time. By default features will be filtered by the server. If set to <code>&#39;client&#39;</code> all features are loaded and filtered on the client before display.</td> </tr> <tr> <td><code>simplifyFactor</code></td> <td><code>Integer</code></td> <td>How much to simplify polygons and polylines. More means better performance, and less means more accurate representation.</td> </tr> <tr> <td><code>precision</code></td> <td><code>Integer</code></td> <td>How many digits of precision to request from the server. <a href="http://en.wikipedia.org/wiki/Decimal_degrees">Wikipedia</a> has a great reference of digit precision to meters.</td> </tr> <tr> <td><code>token</code></td> <td><code>String</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>URL of an <a href="https://developers.arcgis.com/javascript/jshelp/ags_proxy.html">ArcGIS API for JavaScript proxies</a> or <a href="https://github.com/Esri/resource-proxy">ArcGIS Resource Proxies</a> to use for proxying POST requests.</td> </tr> <tr> <td><code>useCors</code></td> <td><code>Boolean</code></td> <td>If this service should use CORS when making GET requests.</td> </tr> </tbody> </table> <p><code>ClusteredFeatureLayer</code> will also accept any options that can be passed to <a href="https://github.com/Leaflet/Leaflet.markercluster#all-options">Leaflet.MarkerClusterGroup</a> to customize the behavior and appearance of the clustering.</p> <h3 id="events">Events</h3> <table> <thead> <tr> <th>Event</th> <th>Type</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>loading</code></td> <td><a href="../../api-reference/events.html#loading-event">&lt;<code>LoadingEvent</code>&gt;</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">&lt;<code>LoadEvent</code>&gt;</a></td> <td>Fires when all features in the current bounds of the map have loaded.</td> </tr> <tr> <td><code>createfeature</code></td> <td><a href="../../api-reference/events.html#feature-create">&lt;<code>CreateFeatureEvent</code>&gt;</a></td> <td>Fired when a feature from the Feature Layer is loaded for the first time.</td> </tr> <tr> <td><code>removefeature</code></td> <td><a href="../../api-reference/events.html#feature-remove">&lt;<code>RemoveFeatureEvent</code>&gt;</a></td> <td>Fired when a feature on the layer is removed from the map.</td> </tr> <tr> <td><code>addfeature</code></td> <td><a href="../../api-reference/events.html#feature-add">&lt;<code>AddFeatureEvent</code>&gt;</a></td> <td>Fired when a previously removed feature is added back to the map.</td> </tr> </tbody> </table> <p><code>L.esri.Layers.FeatureLayer</code> also fires all <a href="../../api-reference/services/feature-layer.html"><code>L.esri.Services.FeatureLayer</code></a> events.</p> <p>In additon to these events <code>L.esri.FeatureLayer</code> also fires the following <a href="http://leafletjs.com/reference.html#event-objects">Mouse Events</a> <code>click</code>, <code>dblclick</code>, <code>mouseover</code>, <code>mouseout</code>, <code>mousemove</code>, and <code>contextmenu</code>, <code>clusterclick</code>, <code>clusterdblclick</code>, <code>clustermouseover</code>, <code>vmouseout</code>, <code>clustermousemove</code>, and <code>clustercontextmenu</code> as well as the following the <a href="http://leafletjs.com/reference.html#event-objects">Popup Events</a> <code>popupopen</code> and <code>popupclose</code>.</p> <h3 id="methods">Methods</h3> <table> <thead> <tr> <th>Method</th> <th>Returns</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>setStyle(<nobr class="param"><span>&lt;<a href="http://leafletjs.com/reference.html#path-options">PathOptions</a>&gt;</span> <code>style</code></nobr>)</code><br><br><code>setStyle(<nobr class="param"><span>&lt;Function&gt;</span> <code>style</code></nobr>)</code></td> <td><code>this</code></td> <td>Sets the given path options to each layer that has a <code>setStyle</code> method. Can also be a <code>Function</code> that will recive a <code>layer</code> argument and should return <a href="http://leafletjs.com/reference.html#path-options">Path Options</a></td> </tr> <tr> <td><code>resetStyle(<nobr class="param"><span>&lt;String or Integer&gt;</span> <code>undefined</code></nobr>)</code></td> <td><code>this</code></td> <td>Given the ID of a feature, reset that feature to the original style, useful for resetting style after hover events.</td> </tr> <tr> <td><code>setStyle(<nobr class="param"><span>&lt;<a href="http://leafletjs.com/reference.html#path-options">PathOptions</a>&gt;</span> <code>style</code></nobr>)</code><br><br><code>setStyle(<nobr class="param"><span>&lt;Function&gt;</span> <code>style</code></nobr>)</code></td> <td><code>this</code></td> <td>Sets the given path options to each layer that has a <code>setStyle</code> method. Can also be a <code>Function</code> that will receive a <code>feature</code> argument and should return <a href="http://leafletjs.com/reference.html#path-options">Path Options</a> <pre><code class="language-javascript">featureLayer.setStyle({ color: &#39;white&#39; })</code></pre> <pre><code class="language-javascript">featureLayer.setStyle(1, function(feature){ return { weight: feature.properties.pixelWidth }; })</code></pre> <tr> <td><code>bindPopup(<nobr class="param"><span>&lt;Function&gt;</span> <code>fn</code></nobr>, <nobr class="param"><span>&lt;<a href="http://leafletjs.com/reference.html#popup-options">PopupOptions</a>&gt;</span> <code>popupOptions</code></nobr>)</code></td> <td><code>this</code></td> <td> Defines a function that will return HTML to be bound to a popup on each feature. <pre class="js"><code>featureLayer.bindPopup(function(features){ return &quot;Name: &quot; + features.properties.NAME; });</code></pre> </td> </tr> <tr> <td><code>unbindPopup()</code></td> <td><code>this</code></td> <td>Removed a popup previously bound with <code>bindPopup</code>.</td> </tr> <tr> <td><code>eachFeature(<nobr class="param"><span>&lt;Function&gt;</span> <code>fn</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>context</code></nobr>)</code></td> <td><code>this</code></td> <td> Calls the passed function against every feature. The function will be passed the layer that represents the feature. <pre class="js"><code>featureLayer.eachFeature(function(layer){ console.log(layer.feature.properties.NAME); });</code></pre> </td> </tr> <tr> <td><code>getFeature(<nobr class="param"><span>&lt;String or Integer&gt;</span> <code>undefined</code></nobr> id)</code></td> <td><code>Layer</code></td> <td>Given the id of a Feature return the layer on the map that represents it. This will usually be a Leaflet vector layer like <a href="http://leafletjs.com/reference.html#polyline">Polygon</a> or <a href="http://leafletjs.com/reference.html#polyline">Polygon</a>, or a Leaflet <a href="http://leafletjs.com/reference.html#marker">Marker</a>.</td> </tr> <tr> <td><code>getWhere()</code></td> <td><code>String</code></td> <td>Returns the current <code>where</code> setting</td> </tr> <tr> <td><code>setWhere(<nobr class="param"><span>&lt;String&gt;</span> <code>where</code></nobr>, <nobr class="param"><span>&lt;Function&gt;</span> <code>callback</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>context</code></nobr>)</code></td> <td><code>this</code></td> <td>Sets the new <code>where</code> option and refreshes the layer to reflect the new <code>where</code> filter. Accepts an optional callback and function context.</td> </tr> <tr> <td><code>getTimeRange()</code></td> <td><code>Array</code></td> <td>Returns the current time range as an array like <code>[from, to]</code></td> </tr> <tr> <td><code>setTimeRange(<nobr class="param"><span>&lt;Date&gt;</span> <code>from</code></nobr>, <nobr class="param"><span>&lt;Date&gt;</span> <code>to</code></nobr>, , <nobr class="param"><span>&lt;Function&gt;</span> <code>callback</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>context</code></nobr>)</code></td> <td><code>this</code></td> <td>Sets the current time filter applied to features. An optional callback is run upon completion if <code>timeFilterMode</code> is set to <code>&#39;server&#39;</code>. Also accepts function context as the last argument.</td> </tr> <tr> <td><code>authenticate(<nobr class="param"><span>&lt;String&gt;</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>query()</code></td> <td><code>this</code></td> <td> Returns a new <a href=""><code>L.esri.services.Query</code></a> object that can be used to query 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>featureLayer.query() .within(latlngbounds) .where(&quot;Direction = &#39;WEST&#39;&quot;) .run(function(error, featureCollection){ console.log(featureCollection); });</code></pre> </td> </tr> <tr> <td><code>metadata(<nobr class="param"><span>&lt;Function&gt;</span> <code>callback</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</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>featureLayer.metadata(function(error, metadata){ console.log(metadata); });</code></pre> </td> </tr> <tr> <td><code>addFeature(<nobr class="param"><span>&lt;<a href="http://geojson.org/geojson-spec.html#feature-objects">GeoJSON Feature</a>&gt;</span> <code>feature</code></nobr>, <nobr class="param"><span>&lt;Function&gt;</span> <code>callback</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>context</code></nobr>)</code></td> <td><code>this</code></td> <td> Adds a new feature to the feature layer. this also adds the feature to the map if creation is successful. <ul> <li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li> <li>Requires the <code>Create</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li> </ul> </td> </tr> <tr> <td><code>updateFeature(<nobr class="param"><span>&lt;<a href="http://geojson.org/geojson-spec.html#feature-objects">GeoJSON Feature</a>&gt;</span> <code>feature</code></nobr>, <nobr class="param"><span>&lt;Function&gt;</span> <code>callback</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>context</code></nobr>)</code></td> <td><code>this</code></td> <td> Update the provided feature on the Feature Layer. This also updates the feature on the map. <ul> <li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li> <li>Requires the <code>Update</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li> </ul> </td> </tr> <tr> <td><code>deleteFeature(<nobr class="param"><span>&lt;String or Integer&gt;</span> <code>id</code></nobr>, <nobr class="param"><span>&lt;Function&gt;</span> <code>callback</code></nobr>, <nobr class="param"><span>&lt;Object&gt;</span> <code>context</code></nobr>)</code></td> <td><code>this</code></td> <td> Remove the feature with the provided id from the feature layer. This will also remove the feature from the map if it exists. <ul> <li>Requires authentication as a user who has permission to edit the service in ArcGIS Online or the user who created the service.</li> <li>Requires the <code>Update</code> capability be enabled on the service. You can check if creation exists by checking the metadata of your service under capabilities in the metadata.</li> </ul> </td> </tr> </tbody> </table> <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">45.53</span>,-<span class="number">122.64</span>], <span class="number">16</span>); L.esri.basemapLayer(<span class="string">"Streets"</span>).addTo(map); <span class="keyword">var</span> url = <span class="string">"http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/stops/FeatureServer/0"</span>; <span class="keyword">var</span> busStops = <span class="keyword">new</span> L.esri.ClusteredFeatureLayer(url, { <span class="comment">// Cluster Options</span> polygonOptions: { color: <span class="string">"#2d84c8"</span> }, <span class="comment">// Feature Layer Options</span> pointToLayer: <span class="function"><span class="keyword">function</span> <span class="params">(geojson, latlng)</span> {</span> <span class="keyword">return</span> L.circleMarker(latlng, <span class="number">10</span>, { color: <span class="string">"#2D84C8"</span> }); } }).addTo(map);</code></pre> <p><a href="http://github.com/esri/esri-leaflet/edit/master/site/source/pages/api-reference/layers/clustered-feature-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&amp;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>