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

problem with formatter in identify #675

Closed
shshwang opened this issue Feb 23, 2017 · 6 comments
Closed

problem with formatter in identify #675

shshwang opened this issue Feb 23, 2017 · 6 comments
Assignees
Labels

Comments

@shshwang
Copy link

I was following the cmv doc to add url links for one identify field. But it seems the formater function was not executed. The alert doesn't even show up. The popup window still shows the label and field value but no link. Any idea why it is so? I downloaded cmv 1.3.4 a year ago. Is it possible that I might miss some functions or module in order to use formater? Thank you so much for your help!
Cadastral: {
0: {
title: 'Parcel Information',
fieldInfos: [{

               fieldName: 'Tax ID',
               label: 'Tax ID',
               visible: true,
               formatter: function (value, attributes) {
                   alert('value');
                   var FBLink = "http://fbcad.org/Property-Search-Results?searchtext=";
                   var MLink = "http://mcad-tx.org/Property-Search-Result?searchtext=";
                   var HLink = "http://www.hcad.org/records/outsider/hc.asp?acct=" + value;
                   alert(HLink);

                   if (value.includes("R")) {

                       MLink += value;
                       return '<a href="' + MLink + '"target="_blank">{Tax ID}</a>';
                   }
                   else if (value.includes("-")) {
                       FBLink += value.replace("-", "");
                       return '<a href="' + FBLink + '"target="_blank">{Tax ID}</a>';
                   }
                   else {
                       HLink += value;
                       return '<a href="' + HLink + '"target="_blank">{Tax ID}</a>';
                   }

               }
           }]

       }
   },
@tmcgee
Copy link
Member

tmcgee commented Feb 23, 2017

@shshwang formatters were not available in version 1.3.4. Documentation for that release is here.

You can download the current 2.0 beta version in development that includes formatters and dozens (or more! 😄) of additional enhancements here. The updated documentation (a work in progress) for this latest release can be found here.

@shshwang
Copy link
Author

shshwang commented Feb 23, 2017

@tmcgee Thank you so much for your quick reply! I actually played with the newer release too. Didn't get it to work yet. The popup window used the default field values instead of those specified in identify.js.
in viewer.js I have the following code

        }, {
            type: 'dynamic',
            url: 'http://mycity.houstontx.gov/cohgis/rest/services/PD/Cadastral_wm/MapServer',
            title: i18n.viewer.operationalLayers.cadastral,
            options: {
                id: 'cadastral',
                opacity: 1.0,
                visible: true,
                outFields: ['*'],
                imageParameters: buildImageParameters({
                    layerIds: [0],
                    layerOption: 'show'
                }),
                mode: 0
            },
            visibleLayerInfos: {
                layerIds: [-1] // Do not show any layers in default
            },
            identifyLayerInfos: {
                layerIds: [0]//
            }
        }

in identify.js

           cadastral: {
                0: {
                    title: i18n.identify.cadastral.parcels,
                    fieldInfos: [{
                        fieldName: 'County',
                        label: 'County',
                        visible: true
                         }, {
                        fieldName: 'Tax ID',
                        label: 'Tax ID',
                        visible: true,
                        formatter: function (value, attributes) {
                                alert('value='+value);
                                var FBLink = "http://fbcad.org/Property-Search-Results?searchtext=";
                                var MLink = "http://mcad-tx.org/Property-Search-Result?searchtext=";
                                var HLink = "http://www.hcad.org/records/outsider/hc.asp?acct="+value;
                                alert(HLink);
                                if (value.includes("R")){
                                    MLink += value;
                                    return '<a href="' + MLink + '"target="_blank">{Tax ID}</a>';
                                }
                                else if (value.includes("-")) {
                                    FBLink += value.replace("-", "");
                                    return '<a href="' + FBLink + '"target="_blank">{Tax ID}</a>';
                                }
                                else {
                                    HLink += value;
                                    return '<a href="' + HLink + '"target="_blank">{Tax ID}</a>';
                                }
                        }
                    }]
                }
            },

I also updated main.js for corresponding title values. There is no error message either. Do you have any ideas?

@tmcgee
Copy link
Member

tmcgee commented Feb 24, 2017

@shshwang there may be a new bug here when retrieving the info template for sublayer id = 0. I will investigate further.

@shshwang
Copy link
Author

Thank you!
Also I can't make it to Dev Summit this year. Is it possible that you can setup a skype account for some of us to remotely join your meeting on March 8th 2017, 6:30pm to 8:00pm?

@green3g green3g added the bug label Mar 24, 2017
@green3g
Copy link
Member

green3g commented Mar 29, 2017

There's definitely a bug with the Identify on layer 0 for dynamic layers. It happens here:

//....
 getInfoTemplate: function (layer, layerId, result) {
            var popup, config;
            if (result) {
                layerId = result.layerId || layer.layerId; //<---- if result.layerId is 0, layerId becomes undefined
            } else if (layerId === null) {
                layerId = layer.layerId;
            }

@green3g
Copy link
Member

green3g commented Mar 29, 2017

Introduced here: 04fd307

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

No branches or pull requests

3 participants