Skip to content

Fix/url update on popup #495

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

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions src/history-api/url-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type RouteLocationAttributes = Record<
Route: string;
Srmp: number;
Direction: string;
EndSrmp?: number;
EndBack?: string;
};

/**
Expand All @@ -17,36 +19,51 @@ type RouteLocationAttributes = Record<
* @returns - The updated URL.
*/
export function updateUrlSearchParams(routeLocation: RouteLocationAttributes) {
const srmp = `${routeLocation.Srmp}${routeLocation.Back}`;
const { sr, rrt, rrq } = new RouteDescription(routeLocation.Route);
const direction = routeLocation.Direction;

const currentUrl = new URL(window.location.href);

/**
* Map of the search params and their values.
*/
const argsMap = new Map([
["SR", sr],
["RRT", rrt],
["RRQ", rrq],
["MP", srmp],
["DIR", direction],
] as const);

// Update the URL search parameters.
for (const [key, value] of argsMap) {
if (value) {
currentUrl.searchParams.set(key, value);
} else {
currentUrl.searchParams.delete(key);
/* __PURE__ */ console.group(updateUrlSearchParams.name, { routeLocation });
try {
const srmp = `${routeLocation.Srmp}${routeLocation.Back}`;
const { sr, rrt, rrq } = new RouteDescription(routeLocation.Route);
const direction = routeLocation.Direction;
const endMp =
routeLocation.EndSrmp != null
? `${routeLocation.EndSrmp}${routeLocation.EndBack}`
: undefined;

/* __PURE__ */ console.debug({ sr, rrt, rrq, srmp, direction, endMp });

const currentUrl = new URL(window.location.href);

/**
* Map of the search params and their values.
*/
const argsMap = new Map([
["SR", sr],
["RRT", rrt],
["RRQ", rrq],
["MP", srmp],
["DIR", direction],
["EMP", endMp],
] as const);

/* __PURE__ */ console.debug("Argument map", argsMap);

// Update the URL search parameters.
for (const [key, value] of argsMap) {
if (value) {
currentUrl.searchParams.set(key, value);
} else {
currentUrl.searchParams.delete(key);
}
}
}

// Update the browser's URL.
window.history.replaceState(null, "", currentUrl.toString());
/* __PURE__ */ console.debug("Updated URL", currentUrl);

return currentUrl;
// Update the browser's URL.
window.history.replaceState(null, "", currentUrl.toString());

return currentUrl;
} finally {
}
}

const urlSearchRe = /(?<key>[^?=&]+)(?:=(?<value>[^&]*))?/g;
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/Access Control.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Access Control.arcade
*/

/**
* The ArcGIS Online Item ID for the Access Control layer.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/Bing Maps.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Bing Maps.arcade
*/

var xy = webMercatorToWgs1984(Geometry($feature));
var x = xy.x;
var y = xy.y;
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/City.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* City.arcade
*/

var agolId = "0d96ba84b802425aa1d2b9a99e422c5d";
var p = Portal("https://wsdot.maps.arcgis.com");
var layerId = 1;
Expand Down
6 changes: 4 additions & 2 deletions src/layers/MilepostLayer/arcade/County.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* County.arcade
*/

var agolId = "12712f465fc44fb58328c6e0255ca27e";
var p = Portal("https://wsdot.maps.arcgis.com");

Expand All @@ -18,5 +22,3 @@ var match = Top(
for (var f in match) {
return f.JURISDICT_LABEL_NM
}

// return $userInput;
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/GeoHack.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* GeoHack.arcade
*/

var xy = webMercatorToWgs1984(Geometry($feature));
var x = xy.x;
var y = xy.y;
Expand Down
4 changes: 0 additions & 4 deletions src/layers/MilepostLayer/arcade/GeoURI.arcade

This file was deleted.

20 changes: 0 additions & 20 deletions src/layers/MilepostLayer/arcade/Google Street View.arcade

This file was deleted.

4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/LRS Date.arcade
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/**
* LRS Date.arcade
*/

DateOnly($feature.LRS_Date, "YMMDD");
13 changes: 13 additions & 0 deletions src/layers/MilepostLayer/arcade/LocateMP URL.arcade
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* LocateMP URL.arcade
*/

var urlBase = "";

// Split the Route ID into SR, RRT, and RRQ parts.
var routeParts = splitRouteId($feature.Route);
var attributes = Dictionary($feature)["attributes"];

// Construct the key value pairs for the query string.
var parts = [
Expand All @@ -12,6 +17,14 @@ var parts = [
["SRMP", Text($feature.SRMP,"#.##") + IIf($feature.Back == "B", "B", "")]
];

if (HasKey(attributes, "EndSrmp")) {
var mpText = Text(attributes.EndSrmp,"#.##");
if (HasKey(attributes, "EndBack") && attributes.EndBack == "B") {
mpText += "B";
}
Push(parts,["EMP", mpText]);
}

/**
* Detects if a tuple's value (element at index 1) is neither null nor empty.
* @param kvp - A tuple containing a key and a value.
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/Location Links.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Location Links.arcade
*/

/**
* Modified version of a function that came from https://github.com/Esri/arcade-expressions/blob/master/popup/url-withlocation.md
*/
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/Milepost Label.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Milepost Label.arcade
*/

/**
* Creates the label text for an SRMP point.
* - Rounds SRMP to three digits.
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/Region.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Region.arcade
*/

var regionId = "1c0845bd12944017b3bb3631bda09e0e"
var p = Portal("https://wsdot.maps.arcgis.com")

Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/SRView URL.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* SRView URL.arcade
*/

/*
Sample location w/ back mileage:
002i @ 60.50B
Expand Down
4 changes: 4 additions & 0 deletions src/layers/MilepostLayer/arcade/Township Section.arcade
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Township Section.arcade
*/

var displayField = "LEGAL_DESC_NM";
var thePortal = Portal("https://www.arcgis.com");
var itemId = "ae861d2304da4d099e0f7841fcbfa860";
Expand Down
8 changes: 5 additions & 3 deletions src/layers/MilepostLayer/arcade/WGS 1984 Coordinates.arcade
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* WGS 1984 Coordinates.arcade
*/

// import fromWebMercatorFunction from "./parts/fromWebMercator.function.arcade"

var featureGeometry = Geometry($feature);

if (TypeOf(featureGeometry) == "Point") {
webMercatorToWgs1984(Geometry($feature))
} else {
webMercatorToWgs1984(Point($userInput))
webMercatorToWgs1984(featureGeometry)
}
29 changes: 0 additions & 29 deletions src/layers/MilepostLayer/arcade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import ExpressionInfo from "@arcgis/core/popup/ExpressionInfo";
import ExpressionContent from "@arcgis/core/popup/content/ExpressionContent";
import { isInternal } from "../../../urls/isIntranet";
import AccessControlArcade from "./Access Control.arcade?raw";
// import BingMapsArcade from "./Bing Maps.arcade?raw";
import CityArcade from "./City.arcade?raw";
import CountyArcade from "./County.arcade?raw";
// import GeoHackArcade from "./GeoHack.arcade?raw";
import GeoURIArcade from "./GeoURI.arcade?raw";
// import GoogleStreetViewArcade from "./Google Street View.arcade?raw";
import LocateMPUrlArcade from "./LocateMP URL.arcade?raw";
import LocationLinksArcade from "./Location Links.arcade?raw";
import MilepostLabelArcade from "./Milepost Label.arcade?raw";
Expand Down Expand Up @@ -75,25 +71,6 @@ const expressionInfoProperties = [
expression: [splitRouteIdFunction, RegionArcade].join("\n"),
returnType: "string",
},
// {
// name: "bingMaps",
// title: "Bing Maps",
// expression: [webMercatorToWgs1984, BingMapsArcade].join("\n"),
// returnType: "string",
// },
// {
// name: "geoHack",
// title: "GeoHack",
// expression: [webMercatorToWgs1984, GeoHackArcade].join("\n"),
// returnType: "string",
// },

// {
// name: "googleStreetView",
// title: "Google Street View",
// expression: [webMercatorToWgs1984, GoogleStreetViewArcade].join("\n"),
// returnType: "string",
// },
{
name: "srViewURL",
title: "SRView URL",
Expand All @@ -118,12 +95,6 @@ const expressionInfoProperties = [
].join("\n"),
returnType: "string",
},
{
name: "geoURI",
title: "GeoURI",
expression: [webMercatorToWgs1984, GeoURIArcade].join("\n"),
returnType: "string",
},
] as const;

export type expressionNames = (typeof expressionInfoProperties)[number]["name"];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* splitRouteId.function.arcade
*/

/**
* Splits a WSDOT Route ID into its component
* SR, RRT, and RRQ parts.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* webMercatorToWgs1984.function.arcade
*/

// Constants
var R_MAJOR = 6378137.0;

Expand All @@ -17,18 +21,30 @@ function xyWebMercatorToWgs1984(xy) {
}

function webMercatorToWgs1984(geom) {
var point = null;
if (geom.type == "Point") {
// Web Mercator coordinates
var xWebMercator = geom.x;
var yWebMercator = geom.y;

var wgsXY = xyWebMercatorToWgs1984([xWebMercator, yWebMercator]);
point = geom
} else if (geom.type == "Polyline") {
point = geom.paths[0][0]
} else if (geom.type == "Polygon") {
point = geom.rings[0][0]
} else if (geom.type == "Multipoint") {
point = geom.points[0]
}

return {
x: wgsXY[0],
y: wgsXY[1],
};
if (point == null) {
return null;
}

return null;
// Web Mercator coordinates
var xWebMercator = point.x;
var yWebMercator = point.y;

var wgsXY = xyWebMercatorToWgs1984([xWebMercator, yWebMercator]);

return {
x: wgsXY[0],
y: wgsXY[1],
};
}

Loading
Loading