javascriptleafletarcgisesri-leaflet

Leaflet labels on top


I am quite new to leaflet and would like some advice. I use the UN Clear map as a base map to which I add some polygons using a GeoJSON layer. I learned about a nice trick here, using map panes to get the labels on top of the polygons. I am trying to recreate that with the UN Clear Map, but the labels stay below the polygons. I don't get any error messages. I think I may not be referencing the labels layer correctly, but don't know how I should do it.

Simplified code:

map = L.map('map', {
    minZoom: 3,
    maxZoom: 10,
    worldCopyJump: true
    });

map.createPane('labels');
map.getPane('labels').style.zIndex = 850;

const mapLayer = esri.tiledMapLayer({
    url: "https://geoservices.un.org/arcgis/rest/services/ClearMap_WebTopo/MapServer/",
    maxZoom: 10,
    }).addTo(map);
map.setView([0, 0], 3);

const colorLayer = (L as any).geoJSON(GeoJsonData, geoJsonOptions).addTo(map);

const labelLayer = esri.tiledMapLayer({
    url:'https://geoservices.un.org/arcgis/rest/services/ClearMap_WebTopo/MapServer/0',
    pane: 'labels'}).addTo(map);

Solution

  • @IvanSanchez is correct. If you look at the map service definition for this layer (https://geoservices.un.org/arcgis/rest/services/ClearMap_WebTopo/MapServer), you will see Supports Dynamic Layers: false. As far as I can tell, this means the sublayers cannot be singled out and built into new dynamic layers. You can read a bit more about that here: esri TileLayer capabilities

    Unfortunately you will either need to build these layers from scratch using their underlying data as featurelayers (this is a ridiculous amount of work and I don't recommend it one bit), or you'll have to go looking for other basemap / labels layers that you like.

    I did manage to find what looks like just the baselayer on ArcGIS Online, here, but it doesn't seem to be available to the public. I would actually contact the UN site you referenced and see if anyone there knows how you can get access to just the baselayer. Probably any reference layer on top of that would be fine.

    Sorry for the bad news.