Select to view content in your preferred language

How to add markers to area polygon in Measurement tool

1668
3
Jump to solution
04-17-2017 08:21 AM
PaulBelew
Occasional Contributor

I'm using dijit Measurement tool:

var fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 167, 25, 0.9]), 4), new esri.Color([255, 167, 25, 0.25]));
          var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 167, 25, 0.9]), 4);
          var pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 255, 255, 0.9]), 2), new esri.Color([255, 167, 25, 0.9]))

          this._measure_tool = new esri.dijit.Measurement({
                  map: this.map,
                  defaultAreaUnit: esri.Units.SQUARE_METERS, defaultLengthUnit: esri.Units.METERS,
                  fillSymbol: fillSymbol, lineSymbol: lineSymbol, pointSymbol: pointSymbol
              }
                , constr.create("div"));
          this._measure_tool.startup();

When I draw a line to measure distance pointSymbol markers are appears at line points but its visible under the lines.

How can I make markers be above the lines?

When I draw a polygon to measure area markers is not visible.

How can I make markers visible on polygon figure?

I'm using version 3.20.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Paul,

   As the widget is not designed for that you would have to add code to accomplish that. Here is a sample that does that:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Measure Tool</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/themes/calcite/dijit/calcite.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/themes/calcite/esri/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:280px;
      }
      </style>
      <script src="https://js.arcgis.com/3.20/"></script>
    <script>
    var map, clickHandler, moveHandler;
    require([
        "dojo/dom",
        "esri/Color",
        "dojo/keys",
        "dojo/parser",
        "dojo/on",
        "dojo/_base/array",

        "esri/config",
        "esri/sniff",
        "esri/map",
        "esri/graphic",
        "esri/SnappingManager",
        "esri/dijit/Measurement",
        "esri/layers/FeatureLayer",
        "esri/renderers/SimpleRenderer",
        "esri/tasks/GeometryService",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/SimpleMarkerSymbol",

        "esri/dijit/Scalebar",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dijit/TitlePane",
        "dijit/form/CheckBox",
        "dojo/domReady!"
      ], function(
        dom, Color, keys, parser, on, arrayUtils,
        esriConfig, has, Map, Graphic, SnappingManager, Measurement, FeatureLayer, SimpleRenderer, GeometryService, SimpleLineSymbol, SimpleFillSymbol, SimpleMarkerSymbol
      ) {
        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/";
        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("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

        map = new Map("map", {
          basemap: "satellite",
          center: [-85.743, 38.256],
          zoom: 17
        });
        moveHandler = on.pausable(map, "mouse-move", measureMove);
        moveHandler.pause();
        clickHandler = on.pausable(map, "click", measureClick);
        clickHandler.pause();

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

        var parcelsLayer = new FeatureLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/...", {
          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 fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 167, 25, 0.9]), 4), new esri.Color([255, 167, 25, 0.25]));
          var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 167, 25, 0.9]), 4);
          var pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 255, 255, 0.9]), 2), new esri.Color([255, 167, 25, 0.9]))

        var measurement = new Measurement({
          map: map,
          fillSymbol:fillSymbol,
          lineSymbol:lineSymbol,
          pointSymbol: pointSymbol
        }, dom.byId("measurementDiv"));
        measurement.startup();
        measurement.on("tool-change", function(evt){
          if(evt.toolName){
            if(evt.toolName === "area"){
              clickHandler.resume();
            }else{
              clickHandler.pause();
            }
            moveHandler.resume();
          }else{
            moveHandler.pause();
          }
        });

        measurement.on("measure-end", function(evt){
          moveHandler.pause();
          arrayUtils.map(measurement._measureGraphics, function(graphic){
            if(graphic.geometry && graphic.geometry.type === "point" && graphic.getShape()){
              graphic.getShape().moveToFront();
            }
          });
        });

        measurement.on("measure-start", function(evt){
          moveHandler.resume();
        });

        function measureMove(evt){
          arrayUtils.map(measurement._measureGraphics, function(graphic){
            if(graphic.geometry && graphic.geometry.type === "point" && graphic.getShape()){
              graphic.getShape().moveToFront();
            }
          });
        }

        function measureClick(evt){
          var pt = new Graphic(evt.mapPoint, measurement.pointSymbol);
          setTimeout(function(){
            map.graphics.add(pt);
            measurement._measureGraphics.push(pt);
          }, 50);
        }
      });
    </script>
  </head>

  <body class="calcite">
    <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

3 Replies
KellyHutchins
Esri Frequent Contributor

The default experience for the widget is to display the measurement distance on the widget. Based on your image it looks like you are adding a tooltip. Is this correct? If so can you share the code you are using - that might help us give you advice on displaying the units correctly. 

Here's a test app that shows the default behavior. 

JS Bin - Collaborative JavaScript Debugging 

PaulBelew
Occasional Contributor

Thank you.

As I see the example is working in the same manner. If you can modify your example to show markers on polygon figure then I can do the same.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Paul,

   As the widget is not designed for that you would have to add code to accomplish that. Here is a sample that does that:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Measure Tool</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/themes/calcite/dijit/calcite.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/themes/calcite/esri/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:280px;
      }
      </style>
      <script src="https://js.arcgis.com/3.20/"></script>
    <script>
    var map, clickHandler, moveHandler;
    require([
        "dojo/dom",
        "esri/Color",
        "dojo/keys",
        "dojo/parser",
        "dojo/on",
        "dojo/_base/array",

        "esri/config",
        "esri/sniff",
        "esri/map",
        "esri/graphic",
        "esri/SnappingManager",
        "esri/dijit/Measurement",
        "esri/layers/FeatureLayer",
        "esri/renderers/SimpleRenderer",
        "esri/tasks/GeometryService",
        "esri/symbols/SimpleLineSymbol",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/SimpleMarkerSymbol",

        "esri/dijit/Scalebar",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dijit/TitlePane",
        "dijit/form/CheckBox",
        "dojo/domReady!"
      ], function(
        dom, Color, keys, parser, on, arrayUtils,
        esriConfig, has, Map, Graphic, SnappingManager, Measurement, FeatureLayer, SimpleRenderer, GeometryService, SimpleLineSymbol, SimpleFillSymbol, SimpleMarkerSymbol
      ) {
        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/";
        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("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

        map = new Map("map", {
          basemap: "satellite",
          center: [-85.743, 38.256],
          zoom: 17
        });
        moveHandler = on.pausable(map, "mouse-move", measureMove);
        moveHandler.pause();
        clickHandler = on.pausable(map, "click", measureClick);
        clickHandler.pause();

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

        var parcelsLayer = new FeatureLayer("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville/LOJIC_LandRecords_Louisville/...", {
          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 fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 167, 25, 0.9]), 4), new esri.Color([255, 167, 25, 0.25]));
          var lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 167, 25, 0.9]), 4);
          var pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new esri.Color([255, 255, 255, 0.9]), 2), new esri.Color([255, 167, 25, 0.9]))

        var measurement = new Measurement({
          map: map,
          fillSymbol:fillSymbol,
          lineSymbol:lineSymbol,
          pointSymbol: pointSymbol
        }, dom.byId("measurementDiv"));
        measurement.startup();
        measurement.on("tool-change", function(evt){
          if(evt.toolName){
            if(evt.toolName === "area"){
              clickHandler.resume();
            }else{
              clickHandler.pause();
            }
            moveHandler.resume();
          }else{
            moveHandler.pause();
          }
        });

        measurement.on("measure-end", function(evt){
          moveHandler.pause();
          arrayUtils.map(measurement._measureGraphics, function(graphic){
            if(graphic.geometry && graphic.geometry.type === "point" && graphic.getShape()){
              graphic.getShape().moveToFront();
            }
          });
        });

        measurement.on("measure-start", function(evt){
          moveHandler.resume();
        });

        function measureMove(evt){
          arrayUtils.map(measurement._measureGraphics, function(graphic){
            if(graphic.geometry && graphic.geometry.type === "point" && graphic.getShape()){
              graphic.getShape().moveToFront();
            }
          });
        }

        function measureClick(evt){
          var pt = new Graphic(evt.mapPoint, measurement.pointSymbol);
          setTimeout(function(){
            map.graphics.add(pt);
            measurement._measureGraphics.push(pt);
          }, 50);
        }
      });
    </script>
  </head>

  <body class="calcite">
    <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>