npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

esri-leaflet-legend

v2.0.1

Published

Layer legend plugin for esri-leaflet

Downloads

109

Readme

Esri Leaflet Legend npm version CircleCI

Esri leaflet plugin for retrieving map service legends. Also aimed to cover the lack of similar API for FeatureServers and render the symbols from layer definitions. No assumptions on how you want to render the legend, you are simply getting the legend data(see format). There is a templating example in the demo.

The legend task for mapservers is ready & tested, feature layers part is developed separately and will be released later

Example (Leaflet 1.0.x)

var map = L.map('map', {maxZoom: 20}).setView([ 41.78408507289525, -88.13716292381285], 18);

L.esri.basemapLayer('Gray').addTo(map);

var waterNetwork = L.esri.dynamicMapLayer(
    'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Water_Network/MapServer', {
    useCors: false
}).addTo(map);

waterNetwork.legend(function(error, legend){
    if(!error) {
        var html = '<ul>';
        for(var i = 0, len = legend.layers.length; i < len; i++) {
            html += '<li><strong>' + legend.layers[i].layerName + '</strong><ul>';
            for(var j = 0, jj = legend.layers[i].legend.length; j < jj; j++){
                html += L.Util.template('<li><img width="{width}" height="{height}" src="data:{contentType};base64,{imageData}"><span>{label}</span></li>', legend.layers[i].legend[j]);
            }
            html += '</ul></li>';
        }
        html+='</ul>';
        document.getElementById('legend').innerHTML = html;
    }
});

Legend Control

L.esri.Controls.Legend will render symbology for a single or multiple layers, loading the data and rendering it in a queue. That can take some time, but it's a lot of requests(one per each feature layer).

var map = L.map('map').setView([...], 12);
L.esri.Controls.legend([dynamicLayer, featureLayer], {position: 'topright'}).addTo(map);

You can also adjust the templates for legend output:

{
    listTemplate: '<ul>{layers}</ul>',
    layerTemplate: '<li><strong>{layerName}</strong><ul>{legends}</ul></li>',
    listRowTemplate: '<li><img width="{width}" \
                               height="{height}" \
                               src="data:{contentType};base64,{imageData}">\
                           <span>{label}</span>\
                      </li>',
    emptyLabel: '<all values>'
}

Legend task

var f = new L.esri.Layers.FeatureLayer('/some/arcgis/rest/services/xxx/FeatureServer/0', {}).addTo(map);
f.legend(function(error, legend) {  /* same format as /legend API */  });
// or
var m = L.esri.Services.MapService('some/MapServer/', {});
m.legend(function(error, legend) {  /* same format as /legend API */  });

Approach with symbols

For featureservers(and ArcGIS servers <= 10.0 with no legend API) I want to mimic the API with the data taken from layer definitions. So the symbols have to be rendered into <canvas> and exported as base64. But esriPMS and esriPFS symbols are problematic: I can't get CORS patterns to work, no solution with avoiding cacheing or <img crossOrigin=''> seem to work. Suggestions are appreciated.

esriST is not implemented yet - cannot find a working example.

Development Instructions

Make sure you have the Grunt CLI installed.

  1. Fork and clone
  2. cd into the esri-leaflet-legend folder
  3. Install the dependencies with npm install
  4. run grunt from the command line. This will create minified source, run linting, and start watching the source files for changes.
  5. Make your changes and create a pull request

Dependencies

Licensing

MIT