Adding points on a dynamic map problem

640
2
Jump to solution
09-05-2013 11:51 AM
sailiTang
New Contributor III
Hi,

This is my code. I would like to add a point to my dynamic map, but it doesn't work and nothing is on my map. I don't know if map.graphics.add(graphic) works on dynamic map? If not, for dynamic map, how to add a point? Thanks.

<script>
      var map;
require([
        "esri/map", "esri/geometry/Point",
        "esri/symbols/SimpleMarkerSymbol", "esri/graphic",
        "dojo/_base/array", "dojo/dom-style", "dojox/widget/ColorPicker",
        "esri/layers/ArcGISDynamicMapServiceLayer", "dojo/domReady!"
      ], function(
        Map, Point,
        SimpleMarkerSymbol, Graphic,
        arrayUtils, domStyle, ColorPicker, ArcGISDynamicMapServiceLayer
      ) {

        map = new Map("map");
       
        var basemaplayer = new ArcGISDynamicMapServiceLayer(
          "http://dnr-mrn-wms.gnb.ca/arcgisproxy/rest/services/BMS_Proxy_Test/MapServer");
          map.addLayer(basemaplayer);
       
        map.on("load", mapLoaded);
     
        function mapLoaded(){
          var points = [[-66.653, 45.967]];
          var initColor = "#ce641d";
          arrayUtils.forEach(points, function(point) {
            var graphic = new Graphic(new Point(point), createSymbol(initColor));
            map.graphics.add(graphic);
          });    
         
        };
       
        function createSymbol(color){
          var markerSymbol = new esri.symbol.SimpleMarkerSymbol();
         
          markerSymbol.setColor(new dojo.Color(color));
          markerSymbol.setOutline(null);
          return markerSymbol;
        };
      });
    </script>
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor
The graphics aren't displaying because you are adding points to the map in lat/lon which works fine if your map has a Web Mercator or Geographic spatial reference. However your map's spatial reference is 2943 (matches your dynamic layer) so you'll need to project the points before adding them to the map. Here's a fiddle that shows how this would work:

http://jsfiddle.net/m9SZB/

View solution in original post

0 Kudos
2 Replies
KellyHutchins
Esri Frequent Contributor
The graphics aren't displaying because you are adding points to the map in lat/lon which works fine if your map has a Web Mercator or Geographic spatial reference. However your map's spatial reference is 2943 (matches your dynamic layer) so you'll need to project the points before adding them to the map. Here's a fiddle that shows how this would work:

http://jsfiddle.net/m9SZB/
0 Kudos
sailiTang
New Contributor III
Thank you so much, Kelly! You have solved my problem.
0 Kudos