1.点、线、面

企业微信截图_20210623153058.png
官方:链接

  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  5. <title>Intro to graphics | Sample | ArcGIS API for JavaScript 4.19</title>
  6. <link rel="stylesheet" href="https://js.arcgis.com/4.19/esri/themes/light/main.css" />
  7. <script src="https://js.arcgis.com/4.19/"></script>
  8. <style>
  9. html,
  10. body,
  11. #viewDiv {
  12. padding: 0;
  13. margin: 0;
  14. height: 100%;
  15. width: 100%;
  16. }
  17. </style>
  18. <script>
  19. require(["esri/Map", "esri/views/MapView", "esri/Graphic"], (Map, MapView, Graphic) => {
  20. const map = new Map({
  21. basemap: "hybrid"
  22. });
  23. const view = new MapView({
  24. center: [-80, 35],
  25. container: "viewDiv",
  26. map: map,
  27. zoom: 3
  28. });
  29. /*************************
  30. * Create a point graphic
  31. *************************/
  32. // First create a point geometry (this is the location of the Titanic)
  33. const point = {
  34. type: "point", // autocasts as new Point()
  35. longitude: -49.97,
  36. latitude: 41.73
  37. };
  38. // Create a symbol for drawing the point
  39. const markerSymbol = {
  40. type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
  41. color: [226, 119, 40],
  42. outline: {
  43. // autocasts as new SimpleLineSymbol()
  44. color: [255, 255, 255],
  45. width: 2
  46. }
  47. };
  48. // Create a graphic and add the geometry and symbol to it
  49. const pointGraphic = new Graphic({
  50. geometry: point,
  51. symbol: markerSymbol
  52. });
  53. /****************************
  54. * Create a polyline graphic
  55. ****************************/
  56. // First create a line geometry (this is the Keystone pipeline)
  57. const polyline = {
  58. type: "polyline", // autocasts as new Polyline()
  59. paths: [[-111.3, 52.68], [-98, 49.5], [-93.94, 29.89]]
  60. };
  61. // Create a symbol for drawing the line
  62. const lineSymbol = {
  63. type: "simple-line", // autocasts as SimpleLineSymbol()
  64. color: [226, 119, 40],
  65. width: 4
  66. };
  67. // Create an object for storing attributes related to the line
  68. const lineAtt = {
  69. Name: "Keystone Pipeline",
  70. Owner: "TransCanada",
  71. Length: "3,456 km"
  72. };
  73. /*******************************************
  74. * Create a new graphic and add the geometry,
  75. * symbol, and attributes to it. You may also
  76. * add a simple PopupTemplate to the graphic.
  77. * This allows users to view the graphic's
  78. * attributes when it is clicked.
  79. ******************************************/
  80. const polylineGraphic = new Graphic({
  81. geometry: polyline,
  82. symbol: lineSymbol,
  83. attributes: lineAtt,
  84. popupTemplate: {
  85. // autocasts as new PopupTemplate()
  86. title: "{Name}",
  87. content: [
  88. {
  89. type: "fields",
  90. fieldInfos: [
  91. {
  92. fieldName: "Name"
  93. },
  94. {
  95. fieldName: "Owner"
  96. },
  97. {
  98. fieldName: "Length"
  99. }
  100. ]
  101. }
  102. ]
  103. }
  104. });
  105. /***************************
  106. * Create a polygon graphic
  107. ***************************/
  108. // Create a polygon geometry
  109. const polygon = {
  110. type: "polygon", // autocasts as new Polygon()
  111. rings: [[-64.78, 32.3], [-66.07, 18.45], [-80.21, 25.78], [-64.78, 32.3]]
  112. };
  113. // Create a symbol for rendering the graphic
  114. const fillSymbol = {
  115. type: "simple-fill", // autocasts as new SimpleFillSymbol()
  116. color: [227, 139, 79, 0.8],
  117. outline: {
  118. // autocasts as new SimpleLineSymbol()
  119. color: [255, 255, 255],
  120. width: 1
  121. }
  122. };
  123. // Add the geometry and symbol to a new graphic
  124. const polygonGraphic = new Graphic({
  125. geometry: polygon,
  126. symbol: fillSymbol
  127. });
  128. // Add the graphics to the view's graphics layer
  129. view.graphics.addMany([pointGraphic, polylineGraphic, polygonGraphic]);
  130. });
  131. </script>
  132. </head>
  133. <body>
  134. <div id="viewDiv"></div>
  135. </body>
  136. </html>