Select to view content in your preferred language

Adding a graphic to graphic layer is adding it to different position then map click

994
5
Jump to solution
03-28-2014 06:08 AM
KirtikaChauhan
Deactivated User
Hi,

I am trying to add graphic(point) to my map, it adds the graphic but not at the mapclick point. It adds at a different position when I
zoom out the Map then only I am able to see the added graphic. But this works fine for second mapclick onwards. I am facing this
issue only for first map click. When I click on the map second time it draws the graphic at click location but not first time.

Any help would be really grateful.

My sample code is :     if (dojo.connect(Map, "onClick", function (e) {

        var newgraphic = new esri.Graphic(e.mapPoint, symbol);
        Map.reposition();
        graphicsLayer.clear();
        graphicsLayer.add(newgraphic);
    }));

I have already added graphics layer to map.
0 Kudos
1 Solution

Accepted Solutions
KirtikaChauhan
Deactivated User
Fixed myself. With Map.reposition() and Map.resize() after every click on map so that it doesn't loose its extents.

View solution in original post

0 Kudos
5 Replies
MichaelVolz
Esteemed Contributor
Check that the spatial reference for the graphic is the same as the map you are using.  That appears to have solved similar problems that other javascript api users were having.
0 Kudos
KirtikaChauhan
Deactivated User
Check that the spatial reference for the graphic is the same as the map you are using.  That appears to have solved similar problems that other javascript api users were having.


It doesn't works for the first click event only, from second time onwards it draws at correct location. If spatial reference issue was there then it would not draw at correct place after second click also. and I have tried with same spatial reference also doesn't helps. 😞
0 Kudos
KirtikaChauhan
Deactivated User
I debugged and found out that for first click x and y coordinates are coming wrong although from second click onwards it is coming correct. This is the reason why it is not making graphic at correct position.
But I am not able to figure out why is it taking wrong coordinates at first time
0 Kudos
KenBuja
MVP Esteemed Contributor
I suspect it has to do with the Map.reposition() line. Does this need to be called every time you click on the map? I'm guessing that the first time you click on the map, the map gets repositioned and the point that you clicked isn't the same in the new position.
0 Kudos
KirtikaChauhan
Deactivated User
Fixed myself. With Map.reposition() and Map.resize() after every click on map so that it doesn't loose its extents.
0 Kudos