Select to view content in your preferred language

My added point is in BFE

765
2
07-26-2012 01:34 PM
JohnCorrea
Emerging Contributor
Well not necessarily Bum Effing Egypt but 200 km south of Ghana. This means that my points coordinates are at 0. But why?

Here is my code.

dojo.require("dijit.dijit");
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("esri.map");
    dojo.require("esri.arcgis.utils");
    dojo.require("esri.dijit.Legend");
    dojo.require("esri.dijit.Scalebar");

    esri.config.defaults.geometryService = new esri.tasks.GeometryService('http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer');
     

   
    var map;
    var x = eval('@Model.Longitude'), y = eval('@Model.Latitude');


    function init() {

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

        });

        mapDeferred.addCallback(function (response) {

            map = response.map;

            //resize the map when the browser resizes
            dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
            //add the legend

            if (map.loaded) {
                addPointToMap( x, y );
            }
            else {
                dojo.connect(map, "onLoad", function () {
                    addPointToMap(x, y);
                });
            }
        });
        mapDeferred.addErrback(function (error) {
            console.log("Map creation failed: ", dojo.toJson(error));
        });

    }


    function addPointToMap(lon, lat) {
    

        var point = new esri.geometry.Point(parseFloat(lon), parseFloat(lat), new esri.SpatialReference({ wkid: 4326 }));

       
       
        var symbol = new esri.symbol.SimpleMarkerSymbol().setColor(new dojo.Color([0, 255, 0]));
        var graphic = new esri.Graphic(point, symbol);


        map.graphics.add(graphic);

    }

    dojo.ready(init);
   

</script>
<div id="map"  style="width: 650px; height: 600px; border: 1px solid #000;">
</div>
0 Kudos
2 Replies
StephenLead
Honored Contributor
Assuming that your map is in Web Mercator projection, you probably need to re-project your points from decimal degrees.

See the geographicToWebMercator help doco.

Steve
0 Kudos
JohnCorrea
Emerging Contributor
Yep, that did it.

It was as simple as wrapping the new point definition in this function:

var point = esri.geometry.geographicToWebMercator(
            new esri.geometry.Point(lon, lat, new esri.SpatialReference({ wkid: 4326 }))
        );

Thank you sir!
0 Kudos