Map Units Please?

569
2
04-11-2014 07:33 AM
LarryStout
Occasional Contributor III
I am going to describe functionality I have built into my version of the Esri Flex Viewer to illustrate why I need to get the Map Units (or the toMeterFactor) from the JavaScript API so I can enable the same functionality in a JavaScript Viewer.

The programming languages (Flex and JavaScript) are different, but the reason I need the Map Units and the functionality I am implementing are the same.

1. When the user clicks on a feature, I show a popup with several tabs.  One of the tabs shows the measurements of the feature area and perimeter for polygons, length for polylines, and coordinates for points.  If the feature was a polygon or a polyline, the popup also shows the coordinates of the point clicked.  In both cases, the user can change the spatial reference of the coordinates or the units of the length and area units.  I call the geometry service to convert the coordinates to a different spatial reference.  If the spatial reference is Web Mercator or Geographic, I can calculate the area and length on the client.  If the spatial reference is projected, I can also calculate the area and length on the client, but I need the map units or the ratio of the units to meters to do that.
2. We use the same popup (not an Esri popup, but our own Flex popup) in the Identify and the Search Widget results.
3. We also need the map units to calculate area and length dynamically in the Draw Widget.
4. We have enhanced the Print Widget to show a graphic on the screen that represents the paper size selected for the print.  It lets the user see what will be printed rather than guess what will be printed.  In this widget, we have to do an approximate projection of the paper into the map coordinate system.  We do this on the client, because the user can drag the paper around the map.

You can see all of these widgets in our "last" Flex Viewer here: http://gis.hamiltoncounty.in.gov/flexviewer/index.html.

I have started porting some of this functionality to a couple of different JavaScript Viewers, my version of the Dave Spriggs Configurable JavaScript Viewer that I got from GitHub (http://gis.hamiltoncounty.in.gov/jsViewer3/index.html), and the Stem App JavaScript Viewer that is part of WebApp Builder (http://gis.hamiltoncounty.in.gov/mapViewer1/index.html#).  These implementations are a little rough right now, so be gentle.  The Widget is called Print Plus in the JavaScript Viewers.

Larrye
0 Kudos
2 Replies
MichaelVolz
Esteemed Contributor
Larry:

This is not an answer to your post, but a question about the viewer you are using.

I copied the viewer to my webserver and replaced 2 mapservices with my mapservices.  When I try to use the Measurement Tool, the Identify tool gets in the way.  Are you experiencing this same phenomenon?
0 Kudos
RyanClancy
Occasional Contributor
Larry, have you tried parsing the units from a JSON representation of the map's spatial reference?

map.spatialReference.toJson() should give you the JSON representation of the spatial reference. Each spatial reference has a UNIT property according to https://developers.arcgis.com/javascript/jshelp/pcs.html and https://developers.arcgis.com/javascript/jshelp/gcs.html



Ryan
0 Kudos