From 11c9df94837284a0a901334d7df81e7993ac6b78 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Thu, 20 Mar 2025 11:24:59 +0000 Subject: [PATCH] update api for coords for DMW --- pages/api/endpoint/getdnscoords_api.js | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pages/api/endpoint/getdnscoords_api.js b/pages/api/endpoint/getdnscoords_api.js index c64e9e35..3bdc0b55 100644 --- a/pages/api/endpoint/getdnscoords_api.js +++ b/pages/api/endpoint/getdnscoords_api.js @@ -1,6 +1,7 @@ import axios from "axios"; import CryptoJS from "crypto-js"; import { azureHeaders, consoleLogger, getToken } from "../../../actions"; +import OSPoint from "ospoint"; const WORDKEY = process.env.HASHKEY; @@ -24,11 +25,11 @@ export default async function ApiProxy(req, res) { var token = await getToken(); var queryUrl = - "pinswg_dnses?$select=pinswg_name,pinswg_anticipatedgridreferenceeastingtext,pinswg_anticipatedgridreferencenorthingtext,pinswg_projectname,pinswg_dnsid,_pinswg_associatedlpa_value,_pinswg_appellant_value&$filter=pinswg_anticipatedgridreferencenorthingtext ne null and pinswg_anticipatedgridreferenceeastingtext ne null&$count=true"; + "pinswg_dnses?$select=pinswg_projectlocation,pinswg_mapzoomlevel,pinswg_name,pinswg_anticipatedgridreferenceeastingtext,pinswg_anticipatedgridreferencenorthingtext,pinswg_projectname,pinswg_dnsid,_pinswg_associatedlpa_value,_pinswg_appellant_value&$filter=pinswg_anticipatedgridreferencenorthingtext ne null and pinswg_anticipatedgridreferenceeastingtext ne null&$count=true"; //console.log("dns ", queryUrl); var queryUrlSips = - "pinswg_sipses?$select=pinswg_name,pinswg_anticipatedgridrefeasting,pinswg_anticipatedgridrefnorthing,pinswg_projectname,pinswg_sipscase,_pinswg_associatedlpa_value,_pinswg_appellant_value&$filter=pinswg_anticipatedgridrefeasting ne null and pinswg_anticipatedgridrefnorthing ne null&$count=true"; + "pinswg_sipses?$select=pinswg_projectlocation,pinswg_mapzoomlevel,pinswg_name,pinswg_anticipatedgridrefeasting,pinswg_anticipatedgridrefnorthing,pinswg_projectname,pinswg_sipscase,_pinswg_associatedlpa_value,_pinswg_appellant_value&$filter=pinswg_anticipatedgridrefeasting ne null and pinswg_anticipatedgridrefnorthing ne null&$count=true"; var coordsObj = { value: [] }; @@ -59,6 +60,35 @@ export default async function ApiProxy(req, res) { Object.assign(coordsObj, { "@odata.count": coordsObj.value.length }); + coordsObj.value.forEach((item) => { + // You can replace the following line with actual calculation logic for latitude + // Here, we will just mock it as `easting / 1000` for demonstration. + + let point = new OSPoint( + item.pinswg_anticipatedgridrefnorthing || + item.pinswg_anticipatedgridreferencenorthingtext || + 0, + item.pinswg_anticipatedgridrefeasting || + item.pinswg_anticipatedgridreferenceeastingtext || + 0 + ); + let siteCoords = point.toOSGB36(); + + item.latitude = siteCoords.latitude; + item.longitude = siteCoords.longitude; + item.zoom = isNaN(parseFloat(siteCoords.latitude)) ? 7 : 12; + + item.center = { + id: "", + lat: isNaN(parseFloat(siteCoords.latitude)) + ? 52.412272 + : parseFloat(siteCoords.latitude), + lng: isNaN(parseFloat(siteCoords.longitude)) + ? -3.437989 + : parseFloat(siteCoords.longitude), + }; + }); + // Send the merged values as the response return res.status(200).json(coordsObj); } catch (error) {