Using pulldata javascript to project points not working in web app

181
0
02-28-2024 06:16 AM
EleanorCervigni
New Contributor II

Hello, I have a form that asks users to enter coordinates in Gauss Kruger Zone 7 and then converts them to Lat Long to calculate the geopoint question before saving to the database.

I am using a custom javascript function to transform from Gauss Kruger to Lat Long, and as it uses the proj4 library, I have used webpack to compile a single .js file that i put into the scripts folder (like this https://github.com/EsriPS/survey123-webpack)

This works perfectly in Survey123 connect but not in the web app. When i open the form in the web app and enter the gauss kruger coordinates the lat and long fields don't calculate, they remain empty.

I have checked the known limitations of javascript in survey123 but cant find one related to this error, but was wondering if i missed something. 

Does anyone know why it would work in connect and not in the web app? Or have any ideas of what i could do to get it to work?

I am using v3.19 of Connect, below is the jvascript i am using to convert the coordinates

Thanks!

import proj4 from 'proj4';

export function getCoordinateFromOther(easting,northing,value) {

    //check for empty/incorrect easting/northing values and return error
    if (isNaN(easting) || isNaN(northing)) {
        return 'Please provide numbers for x or y';
    }

    if (!isFinite(easting) || !isFinite(northing)) {
        return 'Please provide finite numbers for x or y';
    }
   
    var gk7 = "+proj=tmerc +lat_0=0 +lon_0=21 +k=0.9999 +x_0=7500000 +y_0=0 +ellps=bessel +towgs84=682,-203,480,0,0,0,0 +units=m +no_defs +type=crs";
    var wgs84 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
    let coordinate = proj4(gk7,wgs84,[easting,northing]);

    //subset coordinates and return requested value - either latitude or longitude
    if(value === 'Latitude') {
        return coordinate[1]
    }
    if(value === 'Longitude') {
        return coordinate[0]
    }
}

 

0 Kudos
0 Replies