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

Side effect of custom fields formatters in Identify #650

Closed
tmcgee opened this issue Dec 14, 2016 · 3 comments · Fixed by cmv/cmv-docs#28
Closed

Side effect of custom fields formatters in Identify #650

tmcgee opened this issue Dec 14, 2016 · 3 comments · Fixed by cmv/cmv-docs#28
Assignees
Labels
Milestone

Comments

@tmcgee
Copy link
Member

tmcgee commented Dec 14, 2016

@roemhildtg I think we may want to reconsider the approach we worked on for #618. Changing the attributes of the original feature is liekly not a desirable outcome. For example, if you have code elsewhere that does this:

var feature = this.map.infoWindow.getSelectedFeature();

you get a result that you might not expect. What is returned will have modified attributes based on the formatters, not those of the original feature.

I ran into this in a current application. Capturing it here for review and discussion. No immediate solution comes to mind.

@tmcgee tmcgee added the bug label Dec 14, 2016
@tmcgee tmcgee added this to the v2.0.0-beta.1 milestone Dec 14, 2016
@green3g
Copy link
Member

green3g commented Dec 14, 2016

I see the issue, and the thought had crossed my mind earlier. I agree it could definitely be an undesirable side-effects.

Off the top of my head, one solution I see is to build a default content formatter property for each identify layer in the identify widget.

function getContentFormatter(args){
  return function(attributes){
    // getFormattedAttributes will return the attributes and apply any formatters
    // it can also remove properties that have `include: false` or we could implement 
    formattedAttributes = getFormattedAttributes(lang.clone(attributes), args.fieldInfos);

    //getTableHtml will iterate through the attributes and create table html
    return getTableHtml(formattedAttributes);
  }
}

and then

popup.setContent(getContentFormatter(this.identifies[layerid][sublayer_id]))

@green3g
Copy link
Member

green3g commented Mar 7, 2017

I don't think there's really a great solution to this that doesn't result in a lot of redundancy. The solution I mentioned above wouldn't work well since we'd have to replicate the functionality of the popup parts when there is no content function (title, fieldInfos, attachments, etc...)

Another solution would be to put the original cloned attributes in an extra property like feature.originalAttributes but I don't see the real benefit there since we're renaming the property and much of the api that would use the attributes property anyways.

Perhaps the best solution is to warn people, and if they need the original value, create instead a virtual field with a formatter and exclude the other field from the identify popup.

@tmcgee
Copy link
Member Author

tmcgee commented Mar 7, 2017

@roemhildtg I agree. Using virtual fields with a formatter is how I work around this and it meets all my requirements so far. I think some info in the docs alerting folks to the potential pitfalls is the way to go.

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

Successfully merging a pull request may close this issue.

2 participants