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

Projects
None yet
3 participants
@tmcgee
Copy link
Member

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 '';
},
Enable identify formatters for feature layers.
Pass the feature geometry to formatter to allow for calculated area/length/position/etc.
@roemhildtg

This comment has been minimized.

Copy link
Member

roemhildtg commented Dec 22, 2016

Works for me 👍

@roemhildtg

This comment has been minimized.

Copy link
Member

roemhildtg commented Dec 28, 2016

I wonder should we do

Lang.clone(geom.toJson())

To avoid that problem we had with the search widget?

@tmcgee

This comment has been minimized.

Copy link
Member

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.

@roemhildtg

This comment has been minimized.

Copy link
Member

roemhildtg commented Dec 29, 2016

Sounds good.

@DavidSpriggs

This comment has been minimized.

Copy link
Member

DavidSpriggs commented Jan 1, 2017

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

@DavidSpriggs DavidSpriggs merged commit f636350 into develop Jan 1, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@DavidSpriggs DavidSpriggs deleted the feature/formatters-for-feature-layers branch Jan 1, 2017

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