Select to view content in your preferred language

Accessing Map Methods after using .utils.createMap

761
1
07-26-2012 12:01 PM
JohnCorrea
Emerging Contributor
Hi anyone and everyone!

I've created a simple map on arcgis.com and am able to render the map in my web pages using a map key. However, I'd like to be able to add a point from my server side code. Here is my code so far. How do add a new graphic point? ESRI has terribly limited documentation and usually its examples cut out a lot of dependencies.

dojo.require("esri.map");
    dojo.require("esri.arcgis.utils");
    dojo.require("esri.layers.agstiled");
    esri.config.defaults.geometryService = new esri.tasks.GeometryService('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer');
     

    var mapDeferred;

    function init() {

        var mapid = "61b91bd7159d4712ac50988e5fd7d4c7"
        mapDeferred = esri.arcgis.utils.createMap(mapid, "map", {
            mapOptions: {
                slider: true,
                nav: false
            }

        });

    }

    dojo.ready(init);

    function addPointToMap(lon, lat) {

        var point = new esri.geometry.Point(lon, lat, mapDeferred.spatialReference);
        var symbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([0, 255, 0]));
        var graphic = new esri.Graphic(point, symbol);


        mapDeferred.graphics.add(graphic);

    }
   
    dojo.ready(addPointToMap);

below are my error messages

[ATTACH=CONFIG]16428[/ATTACH]
0 Kudos
1 Reply
StephenLead
Honored Contributor
ESRI has terribly limited documentation and usually its examples cut out a lot of dependencies.


Actually, compared to many other libraries I reckon their doco is pretty good!

You've got two dojo.ready functions, which might be a problem. Perhaps try running the addPointToMap function on the map's onLoad event to see if that makes any difference.

The help file says that "The graphics object is available to use after the Map.onLoad event."

Steve
0 Kudos