Select to view content in your preferred language

Unable to update hasStaticData property on layers with ArcGIS REST API Typescript

157
0
4 weeks ago
NoahPerimeter
New Contributor

Hello,
I currently have a script that finds template layers that I have via ID, copies their styles, and then applies those styles to all of my other layers. This works fine for all of my layers is they're fresh, but it doesn't do anything for layers that I've edited manually in the map viewer even though it returns success responses for them. Note that I have both hosted feature layers and view layers created from them; the issue seems to apply to them both equally. Through some digging I've determined that the cause is that the hasStaticData property on these layers is set to true once I edit them manually, and that the fix is to set this property back to false. However, when I try to set the hasStaticData property to false, it doesn't get properly updated. 

This is my update function:

export const updateHostedFeatureLayer = async (
    accessToken: string,
    layer: HostedFeatureLayer,
    styleData
) => {
    const { name, index, orgId, serviceDomain } = layer;

    const form = new FormData();
    form.append('token', accessToken);
    form.append('f', 'json');
    form.append('updateDefinition', JSON.stringify(styleData));

    const updateFeaturesRes = await axios({
        method: 'POST',
        url: `https://${serviceDomain}/${orgId}/arcgis/rest/admin/services/${name}/FeatureServer/${index}/updateDefinition`,
        headers: {
            'Content-Type': 'multipart/form-data',
            ...form.getHeaders(),
        },
        data: form.getBuffer(),
    });

    if (updateFeaturesRes.data.error) {
        throw new Error(updateFeaturesRes.data.error.message);
    }

    const response = await axios({
        method: 'GET',
        url: `https://${serviceDomain}/${orgId}/arcgis/rest/services/${name}/FeatureServer/${index}`,
        params: {
            token: accessToken,
            f: 'json',
        },
    });

    console.log(response.data);
};

The final response and console.log are just for me to confirm the changes. And here's an example of what I'm passing into the function:


await updateHostedFeatureLayer(token, layer, {
                    drawingInfo: templateLayerDrawingInfo,
                    hasStaticData: false,
                    copyrightText: '© 2023 Esri',
                });

In this case the drawing info are the styles I'm pulling from my template, and copyrightText is an example property that I'm just including to confirm that my properties are being properly updated. So if I were to run this on my layers, my response would show that the drawingInfo and copyrightText are properly updated with the values provided, but hasStaticData is not. Is there something that's locking the hasStaticData property and preventing it from being edited? And if so, what else can I do to make my layers receptive to my script again besides deleting and remaking them?
0 Kudos
0 Replies