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

Enable identify formatters for feature layers. #655

Merged
merged 2 commits into from
Jan 1, 2017

Conversation

tmcgee
Copy link
Member

@tmcgee tmcgee commented Dec 22, 2016

Not sure I am formatting the attributes at the right place for all scenarios. Improvements or suggestions welcome. This modifies the original attributes which is a negative side effect previously noted in #650

Also includes passing the feature geometry to the formatter. This allows for calculation of area/length/position/etc.

Example formatter for acres:
(assumes geometryEngine included in define statement)

acres: function (value, attributes, geometry) {
    if (geometry && geometry.type === 'polygon') {
        return geometryEngine.geodesicArea(geometry, 'acres');
    }
    return '';
},

Example fieldInfo:

{
    fieldName: 'acres',
    label: 'Acres',
    visible: true,
    format: {places: 2, digitSeparator: true},
    formatter: formatters.acres
},

More formatter examples:

latlng: function (value, attributes, geometry) {
    if (geometry && geometry.type === 'point' && geometry.spatialReference.wkid === 102100) {
        var pt = webMercatorUtils.webMercatorToGeographic(geometry);
        var lat = number.format(pt.y, {
            places: 6
        });
        var lng = number.format(pt.x, {
            places: 6
        });
        return 'Latitude: ' + lat + '<br/>Longitude: ' + lng;
    }
    return '';
},

latitude: function (value, attributes, geometry) {
    if (geometry && geometry.type === 'point' && geometry.spatialReference.wkid === 102100) {
        var pt = webMercatorUtils.webMercatorToGeographic(geometry);
        return pt.y;
    }
    return '';
},

longitude: function (value, attributes, geometry) {
    if (geometry && geometry.type === 'point' && geometry.spatialReference.wkid === 102100) {
        var pt = webMercatorUtils.webMercatorToGeographic(geometry);
        return pt.x;
    }
    return '';
},

length: function (value, attributes, geometry) {
    if (geometry && geometry.type === 'polyline') {
        return geometryEngine.geodesicLength(geometry, 'feet');
    }
    return '';
},

Pass the feature geometry to formatter to allow for calculated area/length/position/etc.
@green3g
Copy link
Member

green3g commented Dec 22, 2016

Works for me 👍

@green3g
Copy link
Member

green3g commented Dec 28, 2016

I wonder should we do

Lang.clone(geom.toJson())

To avoid that problem we had with the search widget?

@tmcgee
Copy link
Member Author

tmcgee commented Dec 29, 2016

I thought about that. I have tested just using lang.clone on the geometry and it seems to work in all browsers. If we use .toJson(), it is more involved needing to actually create a new Point/Polyline/Polygon.

@green3g
Copy link
Member

green3g commented Dec 29, 2016

Sounds good.

@DavidSpriggs
Copy link
Member

The clone is a good idea. Perhaps even for attributes. Will merge...

@DavidSpriggs DavidSpriggs merged commit f636350 into develop Jan 1, 2017
@DavidSpriggs DavidSpriggs deleted the feature/formatters-for-feature-layers branch January 1, 2017 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants