measurement tool and local coordinates

2044
10
Jump to solution
04-03-2018 09:05 AM
AhmadLibda
New Contributor III

Using the sample here ArcGIS API for JavaScript Sandbox 
the measurement tool woks only if I used an esri basemap - topo, satellite.. etc - as a basemap in the map object, and it uses the

"WGS 1984 Web Mercator (Auxiliary Sphere)" coordinate system as a reference for measurements.

But I do not want to use an esri basemap. I want to only consume my local map services published through my Arcgis server with my local coordinate system as a reference for measurements.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ahmad,

   The measurement widget absolutely work with local basemaps. Here is a sample of how I do it (notice I do not specify an esri basemap in the map constructor and then I add my own local layers).

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <!--The viewport meta tag is used to improve the presentation and behavior of the samples
    on iOS devices-->
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Measure Tool</title>
  <link rel="stylesheet" href="http://js.arcgis.com/3.23/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.23/esri/css/esri.css">
  <style>
    html,
    body {
      height: 100%;
      width: 100%;
      margin: 0;
    }

    body {
      background-color: #FFF;
      overflow: hidden;
      font-family: "Trebuchet MS";
    }

    #map {
      border: solid 2px #808775;
      -moz-border-radius: 4px;
      -webkit-border-radius: 4px;
      border-radius: 4px;
      margin: 5px;
      padding: 0px;
    }

    #titlePane {
      width: 240px;
    }

    .claro .dijitTitlePaneTitle {
      background: #fff;
      font-weight: 600;
      border: none;
      border-bottom: solid 1px #29201A;
      border-top: solid 1px #29201A;
    }

    .claro .dijitTitlePaneTitleHover {
      background: #eee;
    }

    .claro .dijitTitlePaneTitleActive {
      background: #808775;
    }

    .claro .dijitTitlePaneContentOuter {
      border-right: none;
      border-bottom: none;
      border-left: none;
    }
  </style>
  <script src="http://js.arcgis.com/3.23/"></script>
  <script>
    var map;
    require([
        "dojo/dom",
        "esri/Color",
        "dojo/keys",
        "dojo/parser",
        "dojo/query",
        "dojo/on",
        "dojo/dom-construct",
        "dojo/_base/array",
        "dojo/dom-style",

        "esri/config",
        "esri/sniff",
        "esri/map",
        "esri/SnappingManager",
        "esri/dijit/Measurement",
        "esri/layers/FeatureLayer",
        "esri/layers/GraphicsLayer",
        "esri/graphic",
        "esri/renderers/SimpleRenderer",
        "esri/tasks/GeometryService",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/PictureMarkerSymbol",
        "esri/geometry/Point",
        "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/layers/ArcGISTiledMapServiceLayer",

        "esri/dijit/Scalebar",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dijit/TitlePane",
        "dijit/form/CheckBox",
        "dojo/domReady!"
      ], function (
      dom, Color, keys, parser, query, on, domConstruct, array, domStyle,
      esriConfig, has, Map, SnappingManager, Measurement, FeatureLayer, GraphicsLayer, Graphic,
      SimpleRenderer, GeometryService, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol,
      Point, ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer
    ) {
      parser.parse();
      //This sample may require a proxy page to handle communications with the ArcGIS Server services. You will need to
      //replace the url below with the location of a proxy on your machine. See the 'Using the proxy page' help topic
      //for details on setting up a proxy page.
      esriConfig.defaults.io.proxyUrl = "/Proxy/proxy.ashx";
      esriConfig.defaults.io.alwaysUseProxy = false;

      //This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications
      esriConfig.defaults.geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

      map = new Map("map", {
        center: new Point({"x": 654661.637354886, "y": 1187279.83575856, "spatialReference": {"wkid": 102629}}),
        zoom: 1
      });

      var orthoLayer = new ArcGISTiledMapServiceLayer("My service URL/rest/services/ParcelOrthos/MapServer", {
        visible: false,
        id: "Ortho Photography"
      });
      var parcelViewer = new ArcGISDynamicMapServiceLayer("My service URL/rest/services/ParcelViewer/MapServer", {
        id: "County Parcel Map"
      });
      map.addLayers([orthoLayer, parcelViewer]);

      var sfs = new SimpleFillSymbol(
        "solid",
        new SimpleLineSymbol("solid", new Color([195, 176, 23]), 2),
        null
      );

      var parcelsLayer = new FeatureLayer("My service URL/rest/services/ParcelViewer/MapServer/67", {
        mode: FeatureLayer.MODE_ONDEMAND,
        outFields: ["*"]
      });
      parcelsLayer.setRenderer(new SimpleRenderer(sfs));
      map.addLayers([parcelsLayer]);

      //dojo.keys.copyKey maps to CTRL on windows and Cmd on Mac., but has wrong code for Chrome on Mac
      var snapManager = map.enableSnapping({
        snapKey: has("mac") ? keys.META : keys.CTRL
      });
      var layerInfos = [{
        layer: parcelsLayer
        }];
      snapManager.setLayerInfos(layerInfos);
      var measurement = new Measurement({
        map: map,
      }, dom.byId("measurementDiv"));
      measurement.startup();
    });
  </script>
</head>

<body class="claro">
  <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline',gutters:false" style="width:100%; height:100%;">
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
      <div style="position:absolute; right:20px; top:10px; z-Index:999;">
        <div id="titlePane" data-dojo-type="dijit/TitlePane" data-dojo-props="title:'Measurement', closable:'false', open:'false'">
          <div id="measurementDiv"></div>
          <span style="font-size:smaller;padding:5px 5px;">Press <b>CTRL</b> to enable snapping.</span>
        </div>
      </div>
    </div>
  </div>
</body>

</html>

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Ahmad,

   The measurement widget absolutely work with local basemaps. Here is a sample of how I do it (notice I do not specify an esri basemap in the map constructor and then I add my own local layers).

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <!--The viewport meta tag is used to improve the presentation and behavior of the samples
    on iOS devices-->
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Measure Tool</title>
  <link rel="stylesheet" href="http://js.arcgis.com/3.23/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.23/esri/css/esri.css">
  <style>
    html,
    body {
      height: 100%;
      width: 100%;
      margin: 0;
    }

    body {
      background-color: #FFF;
      overflow: hidden;
      font-family: "Trebuchet MS";
    }

    #map {
      border: solid 2px #808775;
      -moz-border-radius: 4px;
      -webkit-border-radius: 4px;
      border-radius: 4px;
      margin: 5px;
      padding: 0px;
    }

    #titlePane {
      width: 240px;
    }

    .claro .dijitTitlePaneTitle {
      background: #fff;
      font-weight: 600;
      border: none;
      border-bottom: solid 1px #29201A;
      border-top: solid 1px #29201A;
    }

    .claro .dijitTitlePaneTitleHover {
      background: #eee;
    }

    .claro .dijitTitlePaneTitleActive {
      background: #808775;
    }

    .claro .dijitTitlePaneContentOuter {
      border-right: none;
      border-bottom: none;
      border-left: none;
    }
  </style>
  <script src="http://js.arcgis.com/3.23/"></script>
  <script>
    var map;
    require([
        "dojo/dom",
        "esri/Color",
        "dojo/keys",
        "dojo/parser",
        "dojo/query",
        "dojo/on",
        "dojo/dom-construct",
        "dojo/_base/array",
        "dojo/dom-style",

        "esri/config",
        "esri/sniff",
        "esri/map",
        "esri/SnappingManager",
        "esri/dijit/Measurement",
        "esri/layers/FeatureLayer",
        "esri/layers/GraphicsLayer",
        "esri/graphic",
        "esri/renderers/SimpleRenderer",
        "esri/tasks/GeometryService",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/PictureMarkerSymbol",
        "esri/geometry/Point",
        "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/layers/ArcGISTiledMapServiceLayer",

        "esri/dijit/Scalebar",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dijit/TitlePane",
        "dijit/form/CheckBox",
        "dojo/domReady!"
      ], function (
      dom, Color, keys, parser, query, on, domConstruct, array, domStyle,
      esriConfig, has, Map, SnappingManager, Measurement, FeatureLayer, GraphicsLayer, Graphic,
      SimpleRenderer, GeometryService, SimpleLineSymbol, SimpleFillSymbol, PictureMarkerSymbol,
      Point, ArcGISDynamicMapServiceLayer, ArcGISTiledMapServiceLayer
    ) {
      parser.parse();
      //This sample may require a proxy page to handle communications with the ArcGIS Server services. You will need to
      //replace the url below with the location of a proxy on your machine. See the 'Using the proxy page' help topic
      //for details on setting up a proxy page.
      esriConfig.defaults.io.proxyUrl = "/Proxy/proxy.ashx";
      esriConfig.defaults.io.alwaysUseProxy = false;

      //This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications
      esriConfig.defaults.geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

      map = new Map("map", {
        center: new Point({"x": 654661.637354886, "y": 1187279.83575856, "spatialReference": {"wkid": 102629}}),
        zoom: 1
      });

      var orthoLayer = new ArcGISTiledMapServiceLayer("My service URL/rest/services/ParcelOrthos/MapServer", {
        visible: false,
        id: "Ortho Photography"
      });
      var parcelViewer = new ArcGISDynamicMapServiceLayer("My service URL/rest/services/ParcelViewer/MapServer", {
        id: "County Parcel Map"
      });
      map.addLayers([orthoLayer, parcelViewer]);

      var sfs = new SimpleFillSymbol(
        "solid",
        new SimpleLineSymbol("solid", new Color([195, 176, 23]), 2),
        null
      );

      var parcelsLayer = new FeatureLayer("My service URL/rest/services/ParcelViewer/MapServer/67", {
        mode: FeatureLayer.MODE_ONDEMAND,
        outFields: ["*"]
      });
      parcelsLayer.setRenderer(new SimpleRenderer(sfs));
      map.addLayers([parcelsLayer]);

      //dojo.keys.copyKey maps to CTRL on windows and Cmd on Mac., but has wrong code for Chrome on Mac
      var snapManager = map.enableSnapping({
        snapKey: has("mac") ? keys.META : keys.CTRL
      });
      var layerInfos = [{
        layer: parcelsLayer
        }];
      snapManager.setLayerInfos(layerInfos);
      var measurement = new Measurement({
        map: map,
      }, dom.byId("measurementDiv"));
      measurement.startup();
    });
  </script>
</head>

<body class="claro">
  <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline',gutters:false" style="width:100%; height:100%;">
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
      <div style="position:absolute; right:20px; top:10px; z-Index:999;">
        <div id="titlePane" data-dojo-type="dijit/TitlePane" data-dojo-props="title:'Measurement', closable:'false', open:'false'">
          <div id="measurementDiv"></div>
          <span style="font-size:smaller;padding:5px 5px;">Press <b>CTRL</b> to enable snapping.</span>
        </div>
      </div>
    </div>
  </div>
</body>

</html>
AhmadLibda
New Contributor III

Thanks Robert
I found that i did not add the geometry service (which is not needed in case you used an esri basemap).
Still, I get universal coordinates of the locations e.g.(31.557192 degree) or (31°33'25.9" DMS) for using the provided (development and testing) esri geometry service.
Any idea on how to design my own geometry service?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ahmad,

   In your ArcGIS Server Manager you will already have a Geometry Service created but it is not started by default. It will be under the utilities folder in your Server Manager.

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

AhmadLibda
New Contributor III

I started the ArcGIS Server Geometry Service and the measurement tool is working but I still get universal coordinates for locations. Although I am using a local spatial reference in my map.


var map = new Map("map", {
center: new Point({ "x": 98190, "y": 102773, "spatialReference": { "wkid": 28191 } }),
zoom: 2
});

var bm = new ArcGISTiledMapServiceLayer("http://localhost:6080/arcgis/rest/services/basemap3/MapServer");
map.addLayers([bm]);

var Neighborhoods = new FeatureLayer(gazaStripURL + "/4",
{
id: "Neighborhoods",
showLabels: true,
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});

map.addLayers([Neighborhoods]);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ahmad,

   Sorry for the misunderstanding. The Measurement widget is developed to only display the coordinate units MGRS, USNG, UTM, GeoRef, GARS, DMS, DDM, DD. Not the maps local coordinate system.

0 Kudos
AhmadLibda
New Contributor III

So, in my case, the widget uses the maps local coordinate system as a base for length and area measurements, however, a coordinate system transformation is done for locations. Am I right?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ahmad,

    Yes

RichardMoussopo
Occasional Contributor III

Hi Robert,

it seems that when using a projected map, the measurements widget loses the live result update such as showing live length as you measure or live coordinates while moving the mouse around. See this example: ArcGIS API for JavaScript Sandbox 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Richard,

  That is expected behavior as the dijit will not display live coordinates if it detects that the map is WGS84 or WebMercator.