1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Graphic</title> <link rel="stylesheet" href="https://js.arcgis.com/3.28/esri/css/esri.css"/> <link rel="stylesheet" href="https://js.arcgis.com/3.28/dijit/themes/tundra/tundra.css"/> <script type="text/Javascript" src="https://js.arcgis.com/3.28/"></script> <style> .MapClass{ width:100%; height:800px; border:1px solid #000; } </style> <script> require(["esri/map","esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/GraphicsLayer", "dojo/on","dojo/query","dojo/colors", "esri/graphic","esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/geometry/Point", "dojo/domReady!"], function(Map,ArcGISDynamicMapServiceLayer, GraphicsLayer,on,query,Color,Graphic, SimpleMarkerSymbol,SimpleLineSymbol,Point){ var map = new Map("mapDiv"); var layer = new ArcGISDynamicMapServiceLayer ("http://localhost:6080/arcgis/rest/services/ecology/beijing_2012_3/MapServer"); map.addLayer(layer); var graphicsLayer=new GraphicsLayer(); map.addLayer(graphicsLayer); function addGraphic() { var lineSymbol=new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASH, new Color([255, 0, 0]), 3); var pSymbol=new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE,10, lineSymbol, new Color([255, 0, 0])); var geometry; var graphic; geometry=new Point({ "x":510706, "y":3986100, "spatialReference":map.spatialReference, attributes:{ "h":100, } }); graphic=new Graphic(geometry,pSymbol); graphicsLayer.add(graphic); geometry=new Point({ "x":510326, "y":3985702, "spatialReference":map.spatialReference, attributes:{ "h":200, } }); graphic=new Graphic(geometry,pSymbol); graphicsLayer.add(graphic); geometry=new Point({ "x":510275, "y":3986100, "spatialReference":map.spatialReference, attributes:{ "h":300, } }); graphic=new Graphic(geometry,pSymbol); graphicsLayer.add(graphic); } addGraphic(); on(graphicsLayer,"click",function(event){ var graphic=event.graphic; alert(graphic.attributes["h"]); })
}) </script> </head> <body> <div id="mapDiv" class="MapClass"></div> </body> </html>
|