1

In the ArcGIS Field Maps app, there is an option to share a map, which creates a link to the map you are currently viewing and allows you to send via email. In the link, a center point and scale are specified. When I email myself a link using this functionality and try to open it in a web browser on my desktop, it redirects me to download the Field Maps app.

Is there a way to make this link work for the web map specified by the item ID in the URL, such that it centers and roughly scales in the same place as in Field Maps?

See the link for some details about how you can build links to give to people to open in Field Maps:
https://doc.arcgis.com/en/field-maps/android/help/deploy-your-map.htm

Specifically:

For example, https://fieldmaps.arcgis.app?referenceContext=center&itemID=3ac4145c1ac44aea86e9ed42e00fbb0d&center=34.0547155,-117.1961714 uses the parameter itemID and the value 3ac4145c1ac44aea86e9ed42e00fbb0d to open the map with that ID. The referenceContext parameter and its value center specify the type of action that should be performed in the app—in this case, centering the map. The center parameter and 34.0547155,-117.1961714 value provide the coordinates at which to center the map.

1 Answer 1

1

Update: Javascript solution

I wrote some javascript code that can be turned into a bookmarklet which will redirect the link after it loads in your browser:

javascript: (() => {function center_scale_to_bounds(center_lat, center_lon, scale, units) {
    const per_degree_lat = {feet: 365228, meters:111321};
    var unit_per_degree_lat = per_degree_lat[units];
    var unit_per_degree_lon = Math.cos((Math.PI/180)*center_lat)*unit_per_degree_lat;
    var degree_range_lat = scale/unit_per_degree_lat;
    var degree_range_lon = scale/unit_per_degree_lon;
    var lower_lat = center_lat - (degree_range_lat/2);
    var upper_lat = center_lat + (degree_range_lat/2);
    var left_lon = center_lon - (degree_range_lon/2);
    var right_lon = center_lon + (degree_range_lon/2);
    var bounds = {lower_lat: lower_lat, upper_lat: upper_lat, left_lon: left_lon, right_lon: right_lon};
    return bounds;
  }
  
  const field_maps_link = window.location.href;
  
  var item_id_start_i = field_maps_link.indexOf("itemID") + 7;
  var item_id_end_i = field_maps_link.indexOf("&", item_id_start_i);
  var item_id = field_maps_link.substring(item_id_start_i, item_id_end_i);
  
  
  var lat_start_i = field_maps_link.indexOf("center=", item_id_end_i) + 7;
  var char_after_lat = ",";
  try {
    var lat_end_i = field_maps_link.indexOf(char_after_lat, lat_start_i);
  } catch(e) {
    var char_after_lat = "%";
  }
  
  var lat_end_i = field_maps_link.indexOf(char_after_lat, lat_start_i);
  var latitude = parseFloat(field_maps_link.substring(lat_start_i, lat_end_i));
  
  
  var long_start_i = field_maps_link.indexOf("-", lat_end_i);
  var long_end_i = field_maps_link.indexOf("&", long_start_i);
  var longitude = parseFloat(field_maps_link.substring(long_start_i, long_end_i));
  
  
  var scale_start_i = field_maps_link.indexOf("scale=", long_end_i) + 6;
  var scale = parseFloat(field_maps_link.substring(scale_start_i));
  
  
  var bounds = center_scale_to_bounds(latitude, longitude, scale, "feet");
  var lower_lat = bounds["lower_lat"];
  var upper_lat = bounds["upper_lat"];
  var left_lon = bounds["left_lon"];
  var right_lon = bounds["right_lon"];
  
  var web_link_base = "https://webadaptorhost.domain.com/webadaptorname/home/webmap/viewer.html?webmap=";
  var new_link = `${web_link_base}${item_id}&extent=${left_lon.toPrecision(6)},${lower_lat.toPrecision(6)},${right_lon.toPrecision(6)},${upper_lat.toPrecision(6)}`;
  
  location.assign(new_link);})();

I have also posted this code into a Github repository here

Original answer

I created a script to rearrange the parts of the Field Maps URL and turn it into a link that sends you to the corresponding Web Map. I wrote this specifically to work with my company's ArcGIS Enterprise instance so no guarantees on how that may or may not translate for anyone else's work.

import math
import sys
field_maps_link = sys.argv[1]

item_id_start_i = field_maps_link.index("itemID=") + 7
item_id_end_i = field_maps_link.index("&", item_id_start_i)
item_id = field_maps_link[item_id_start_i:item_id_end_i]

lat_start_i = field_maps_link.index("center=", item_id_end_i) + 7
char_after_lat = ","
# Sometimes the comma gets converted to %2C
try:
    lat_end_i  = field_maps_link.index(char_after_lat, lat_start_i)
except ValueError:
    char_after_lat = "%"
    lat_end_i = field_maps_link.index(char_after_lat, lat_start_i)
latitude = float(field_maps_link[lat_start_i:lat_end_i])

long_start_i = field_maps_link.index("-", lat_end_i)
long_end_i = field_maps_link.index("&", long_start_i)
longitude = float(field_maps_link[long_start_i:long_end_i])

scale_start_i = field_maps_link.index("scale=", long_end_i) + 6
scale = float(field_maps_link[scale_start_i:])

# I am just guessing at how to best use the scale...
# See this link for info about information about scaling
# degrees of longitude to ground distance based on latitude:
# http://surferhelp.goldensoftware.com/editmap/using_scaling_to_minimize_distortion_on_latitude_longitude_maps.htm

#meters_per_degree_lat = 111321
#meters_per_degree_lon = math.cos(math.radians(latitude))*meters_per_degree_lat

feet_per_degree_lat = 365228
feet_per_degree_lon = math.cos(math.radians(latitude))*feet_per_degree_lat
degree_range_lat = scale/feet_per_degree_lat
degree_range_lon = scale/feet_per_degree_lon
lower_lat = latitude - (degree_range_lat/2)
upper_lat = latitude + (degree_range_lat/2)
left_lon = longitude - (degree_range_lon/2)
right_lon = longitude + (degree_range_lon/2)

# Code was written for an ArcGIS Enterprise instance using the form:
# https://webadaptorhost.domain.com/webadaptorname/home/webmap/viewer.html?webmap=
# See ESRI page here: https://enterprise.arcgis.com/en/portal/latest/use/link-to-items.htm#ESRI_SECTION1_BEB29D2E6835463F8A750E10B325CEE6
# Adjust accordingly for your use (replace webadaptorhost, domain, and webadaptorname for your instance)
web_link_base = r"https://webadaptorhost.domain.com/webadaptorname/home/webmap/viewer.html?webmap="
web_link = f"{web_link_base}{item_id}&extent={left_lon:.4f},{lower_lat:.4f},{right_lon:.4f},{upper_lat:.4f}"
print(web_link)

To use just save as a .py file (convert_field_map_link.py for example) and then run with the copied Field Maps link as the argument:

> python convert_field_map_link.py "https://fieldmaps.arcgis.app/?itemID=..."
https://webadaptorhost.domain.com/webadaptorname/home/webmap/viewer.html?webmap=...

You can then copy and paste the URL to your browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.