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

Should be able to pass identify options into bindPopup for a dynamic layer #633

Closed
anatolyg opened this issue Sep 11, 2015 · 15 comments
Closed
Assignees

Comments

@anatolyg
Copy link

Right now there are defaults that are applied to the identify call from a dynamic layer. It would be great to be able to pass an options object that overwrote some of those. For example, I might not want to return the geometry for the feature, or, I might want to make the tolerance higher (or lower).

@jgravois
Copy link
Contributor

jgravois commented Sep 11, 2015

we typically expect people to call the available methods for setting identify request properties in advance of calling run().

L.esri.Tasks.identifyFeatures({
    url: 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer'
})
  .on(map)
  .at([45.543, -122.621])
  .layers('visible:1')
  .returnGeometry(false)
  .tolerance(3)
  .run(function(error, featureCollection, response){
    console.log("UTC Offset: " + featureCollection.features[0].properties.ZONE);
});

is there a reason why this isn't ideal for you?

@anatolyg
Copy link
Author

I create the layer using L.esri.dynamicMapLayer and then use the bindPopup to set up popup. I may do this to multiple layers on the same map, so it's really convenient that the layer itself handles the identify service creation (via _getPopupData function). But I don't see a way to pass options to the identify task from instanciating the layer this way. Totally possible I am missing something.

@jgravois
Copy link
Contributor

thanks for clarifying.. i'll have to think about this a bit to try and decide the best way to expose an opportunity to get more fine grained control (ie: dynamicMapService initialization, when calling bindPopup() etc.)

would it be sufficient to be able to pass identifyParameters that applied to all layers, or are you expecting to set things differently layer by layer?

@anatolyg
Copy link
Author

I hope layer by layer. Use case is time-based identify calls -- maybe you want to see data for a layer a year in the future of data for another layer. The single parameter set won't do there. But bigger picture, it would be useful to set a variety of parameters that are currently exposed via methods as parameters into the identifyFeatures call (and then allow for an identify field to be set during dynamicMapLayer init).

@jgravois
Copy link
Contributor

but for the time being you can just listen for the map click, fire your own identifyFeatures request and display the results in a popup, correct?

@anatolyg
Copy link
Author

Oh, for sure! This isn't blocking me, just a nice to have. I really like the bindPopup feature, just thought you guys might be interested in some feedback.

@jgravois
Copy link
Contributor

thought you guys might be interested in some feedback.

always. thank you for it. 😄

@pdiddyb
Copy link

pdiddyb commented Mar 3, 2016

Is there any more thought to adding the ability to set tolerance per dyn layer? I would actually take it on all dyn layers because on the phone people are having trouble hitting the features.

@jgravois
Copy link
Contributor

@pdiddyb: I would actually take it on all dyn layers because on the phone people are having trouble hitting the features.

its already possible to modify tolerance when identifying on all layers using the corresponding exposed method.

var map = new L.Map('map').setView([ 45.543, -122.621 ], 5);
L.esri.identifyFeatures({
    url: 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer'
})
  .on(map)
  // ...
  .tolerance(5) // default value is 3 screen pixels 
  .run(function(error, featureCollection, response){
    // ...
  });

@carrbrpoa
Copy link

@jgravois, I wish to do the same thing (modify tolerance parameter), but didn't get how this:

var mySpecificLayer = L.esri.dynamicMapLayer({
		url: ".../MapServer",
		layers: [0]
	});
mySpecificLayer.bindPopup(function (error, featureCollection) {
	if (error || featureCollection.features.length === 0) {
		return false;
	} else {
		// plot popup contents
	}
});

is related to your example

var map = new L.Map('map').setView([ 45.543, -122.621 ], 5);
L.esri.identifyFeatures({
    url: 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer'
})
  .on(map)
  // ...
  .tolerance(5) // default value is 3 screen pixels 
  .run(function(error, featureCollection, response){
    // ...
  });

Should I do that declaration for every specific layer I have? What about the .at(<LatLng> latlng)? I just want it working like bindPopup; is it possible?

@jgravois
Copy link
Contributor

jgravois commented Apr 10, 2017

but didn't get how this is related to your example

@carrbrpoa check out #919 (comment) for more information about that.

until we decide on a way to expose more configuration options when calling bindPopup(), identifyFeatures gives you an opportunity to get more fine grained control.

Should I do that declaration for every specific layer I have?

you don't have to call it over and over because the operation is capable of returning results from multiple layers.

var serviceUrl = 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer';

var id = L.esri.identifyFeatures({ url: serviceUrl })
  .on(map)
  .layers("all:0,1,2") // http://esri.github.io/esri-leaflet//api-reference/tasks/identify-features.html#methods
  .tolerance(5) 

map.on('click', function (evt) {
  id.at(evt.latlng);
  id.run(function(error, featureCollection, response){
    console.log(featureCollection);
  });
});

@jgravois
Copy link
Contributor

i had another look at this today and i think we'd get the most bang for our buck by giving developers an opportunity to supply their own custom IdentifyFeatures object when they instantiate their dynamicMapLayer

var customBehavior = L.esri.identifyFeatures({ url: serviceUrl })
  .layers("all:0,1,2")
  .tolerance(5)
  // etc.

var dynamicLayer = L.esri.dynamicMapLayer({
  url: serviceUrl,
  popup: customBehavior
}).addTo(map);

dynamicLayer.bindPopup(/* ... */)

this would allow for more fine-grained control over the /identify request triggered by 'bindPopup()' without increasing the surface area of the API.

@jgravois jgravois self-assigned this Jul 28, 2017
@Biboba
Copy link
Contributor

Biboba commented Dec 11, 2017

Hi @jgravois,

I gave it a try there: 3cb108

What do you think ?

Thanks

@jgravois
Copy link
Contributor

@Biboba very cool!

please open up a PR so i can take a deeper look, hopefully later this week.

@jgravois
Copy link
Contributor

in #1031 @Biboba implemented my pseudo-code in #633 (comment) in the actual library.

thank you for another excellent contribution! 🎉

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

5 participants