unable to view graphic.

407
2
Jump to solution
10-16-2022 12:47 PM
umarfarook
New Contributor

Hello, Im a beginner, I tried this code to view point graphic but I cant see it, kindly help me out.

Thank you.

<html>
    <Head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    </Head>
    <script src = "http://js.arcgis.com/3.41/"></script>
    <link rel="stylesheet" href="http://js.arcgis.com/3.41/esri/css/esri.css">
    <script>
        require ([
            "esri/map",
            "esri/graphic",
            "esri/geometry/Point",
            "esri/symbols/SimpleMarkerSymbol",
            "dojo/domReady!"
        ], function (Map, Graphic, Point, SimpleMarkerSymbol) {
            var map = new Map("map", {
                basemap: "topo",
                center: [-118.805, 34.027],
                zoom: 13
            });
            var point = new Point(-118.805, 34.027);
            var markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,
                new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                    new Color([255, 0, 0]), 1),
                new Color([0, 255, 0, 0.25])
            );
            var graphic = new Graphic(point, markerSymbol);
            map.graphics.add(graphic);
        });
    </script>
    <body>
        <div id="map" style="width: 100%; height: 100%"></div>
    </body>
</html>
0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

Hi @umarfarook, there were 2 issues with your code. First is you were missing some required modules, like SimpleLineSymbol and Color. Whenever you see a "new" in a constructor, make sure you have the required AMD module in the app with an appropriate local variable name. The second issue is that you want to make sure the map is loaded and ready before adding graphics to it. Here is a working test-app that shows what I'm talking about:

https://codepen.io/noash/pen/PoegOxR?editors=1000

 

View solution in original post

2 Replies
Noah-Sager
Esri Regular Contributor

Hi @umarfarook, there were 2 issues with your code. First is you were missing some required modules, like SimpleLineSymbol and Color. Whenever you see a "new" in a constructor, make sure you have the required AMD module in the app with an appropriate local variable name. The second issue is that you want to make sure the map is loaded and ready before adding graphics to it. Here is a working test-app that shows what I'm talking about:

https://codepen.io/noash/pen/PoegOxR?editors=1000

 

umarfarook
New Contributor

Thank you for the help @Noah-Sager. I understood it now :).

0 Kudos