Esri Leaflete visible map service

4418
17
Jump to solution
10-14-2014 07:20 AM
francescodi_vito
New Contributor

Hy guys,

i'm using the esri leaflet plugin for a html5 css3 mobile app. I worked with arcgis javascript and the map service visibility it's possible to set with "visible" method, but this method don't fuction in esri leaflet.

How can i set visibility of map service leaflet ?

Thanks

0 Kudos
17 Replies
PatrickArlt1
Esri Contributor

The MIME type error is ignorable. It never cases any problems.

Can you post any sample code (or JS Fiddle/CodePen) to show the problem you are seeing?

0 Kudos
francescodi_vito
New Contributor

Hi Patrick,

i implemented your code with script for popup:

CodePen - Pen

and this don't work.

0 Kudos
PatrickArlt1
Esri Contributor

You need to set the useCors option to false on the layer since the MapService doesn't support CORS. You can see this in the Custom Popup with Dynamic Map Layer | Esri Leaflet example.

0 Kudos
francescodi_vito
New Contributor

Hy Patrick,

thanks for your help and your advice.

Now the popup work but i try to implement more fields in the custom popup:

livello.bindPopup(function (error, featureCollection) {

    if(error || featureCollection.features.length === 0) {

      return false;

    } else {

      return 'Formazione: ' + featureCollection.features[0].properties.formazione;

      return 'Object: ' + featureCollection.features[0].properties.objectid;

    }

  });

it's possible?

And i have other 2 question:

it's possibile to create a basemap gallery similar to Arcgis JS?

it's possible to mix esri leaflet api with leaflet plugin as: drawing, add shape, etc?

Thank you for your attention

0 Kudos
PatrickArlt1
Esri Contributor

It should be possible to do both of those things.

Here are some links that might help you get started.

Basemap switcher... Switching basemaps | Esri Leaflet

Its worth noting im aginst basemap switchers and they tend to be underused and clutter the interface. How the Public Actually Uses Local Government Web Maps: Metrics from Denver :  MapBrief™ http://patrickarlt.github.io/uc-2014-esri-leaflet/demos/editing.html

Editing demo Esri Leaflet Editing Demo Code is at uc-2014-esri-leaflet/editing.html at gh-pages · patrickarlt/uc-2014-esri-leaflet · GitHub

Please leverage the Esri Leaflet website which has lots of examples and pretty complete documentation. The Leaflet plguins page is also a good resource for tasks like editing. Plugins - Leaflet - a JavaScript library for mobile-friendly maps

francescodi_vito
New Contributor

Patrick,

i have other question.

I use this map service in my code:

http://sgi.isprambiente.it/ArcGIS/rest/services/servizi/geologia1M/MapServer

and whene i call this service in debug mode i see a internal server error 500:

http://sgi.isprambiente.it/ArcGIS/rest/services/servizi/geologia1M/MapServer/export?bbox=1203118.825...

this is the url that generate the error but if in this url i change imageSR and bboxSR with 102100 the map export is ok.

How i can set in the map leaflet to call service with 102100?

I try to set properties bbox and imageSR to 102100:

var livello = new L.esri.dynamicMapLayer('http://sgi.isprambiente.it/ArcGIS/rest/services/servizi/geologia1M/MapServer', {

        opacity:0.5,

         useCors: false,

         bboxSR: 102100,

         imageSR:102100

      });

but don't work.

any idea?

Thanks

0 Kudos
PatrickArlt1
Esri Contributor

Your not seeing an image because ArcGIS Server 9.3 doesn't understand the 3857 spatial reference which is the default in Leaflet.

I remember early in Esri Leaflet development that I ran into a lot of issues with using 102100 (old versions of ArcGIS Server) vs 3857 (Leaflet) so I simply made Esri Leaflet always default to the spatial reference of the map (3857).

In general Esri Leaflet only supports versions of server that haven't been retired yet http://downloads.esri.com/support/product%20life%20cycle/server_gis/ArcGISServer_PLC.pdf which is unfortunately 9.3.

bboxSR and imageSR are actually set to the CRS of the map object not passed in as options.

0 Kudos
francescodi_vito
New Contributor

thanks Patrick for your reply.

I found a solution and i implemnted my code in this way:

// create the dynamic map layer

      var livello = new L.esri.dynamicMapLayer('http://sgi1.isprambiente.it/ArcGIS/rest/services/servizi/strutturale1M/MapServer', {

        opacity:0.5,

         useCors: false

      });

     

         

      // query the checkbox

      var checkbox = document.getElementById("liv");

     

      // listen for the 'change' event on the checkbox and toggle the layer on and off

      checkbox.addEventListener('change', function(e){

        if(checkbox.checked){

          livello.addTo(map);

          livello.options.bboxSR = 102100;

          livello.options.imageSR = 102100;

          livello._update(); // private method but will be exposed in the next version.

        } else {

          map.removeLayer(livello);

        }

      });

and now it's work

0 Kudos