Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Map Service Popups #28

Closed
kevinsigwart opened this issue Jun 25, 2013 · 4 comments
Closed

Dynamic Map Service Popups #28

kevinsigwart opened this issue Jun 25, 2013 · 4 comments
Milestone

Comments

@kevinsigwart
Copy link
Contributor

Provide Popup support for Dynamic Layers. Currently, we need to create a global variable for the map on click event result, then use that result within the identify result callback. It would be nice if the popup would work similarly to the feature service.

Here is how I currently handle the popup.

 map.on("click", function(e) {
    mapEvent = e;

    dynLayer.identify(e.latlng, function(data) {
        if(data.results.length > 0)
        {
            var popup = L.popup()
            .setLatLng(mapEvent.latlng)
            .setContent(data.results[0].value)
            .openOn(map);
        }
    });

 });
@patrickarlt
Copy link
Contributor

I think this a good idea, but there are some implementation issues.

I am assuming you would like some kind of built in version of this sample from the Javascript SDK http://developers.arcgis.com/en/javascript/sandbox/sandbox.html?sample=find_popup

The biggest problem here is that we dont know how developers want the data displayed. They might want only one property or the layer id or a whole custom template with graphs and bells and whistles.

It might be best to leave this alone for now and make a demo showing this behavior. @alaframboise could you whip something up?

There are 2 directions I think we could go in if we want to do a L.esri.DynamicMapLayer.bindPopup() method.

  1. There is a fixed template that developers cannot change. If they want a custom template they can use code like what @kevinsigwart did and make a custom popup.
  2. Instead of passing the HTML they want to display in the popup to bindPopup they pass a function. The string that is returned from this function is used as the popup content.

Option 2 could look something like this.

layer = new L.esri.dynamicLayer(url);

layer.bindPopup(function(identifyInfo){
  // do custom logic to build a template

  // return the html string you want inserted into the popup.
  return html;
});

@kevinsigwart
Copy link
Contributor Author

When implementing the popup we should also consider the capability of pulling the pop-up information (graphs,pictures,custom attribute display...) from an ArcGIS.com Web Map and have it display in a similar fashion within the leaflet application. Similar to this: https://developers.arcgis.com/en/javascript/jssamples/ags_createwebmapid.html

@knownasilya
Copy link
Contributor

@kevinsigwart You shouldn't need to create global variables.

 map.on("click", function(event) {
    dynLayer.identify(event.latlng, setupIdentifyHandler(event));
 });

function setupIdentifyHandler(event) {
  return function (data) {
     if (data.results.length > 0) {
       var popup = L.popup()
         .setLatLng(event.latlng)
         .setContent(data.results[0].value)
         .openOn(map);
     }
  };
}

@patrickarlt
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants