featuretable.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 PopupTemplate - 4.8</title>
  6. <style>
  7. html,
  8. body,
  9. #viewDiv {
  10. padding: 0;
  11. margin: 0;
  12. height: 100%;
  13. width: 100%;
  14. }
  15. </style>
  16. <link rel="stylesheet" href="https://js.arcgis.com/4.8/esri/css/main.css">
  17. <script src="https://js.arcgis.com/4.8/"></script>
  18. <script>
  19. require([
  20. "esri/Map",
  21. "esri/layers/FeatureLayer",
  22. "esri/views/MapView",
  23. "dojo/domReady!"
  24. ], function(
  25. Map,
  26. FeatureLayer,
  27. MapView
  28. ) {
  29. // Create the map
  30. var map = new Map({
  31. basemap: "osm"
  32. });
  33. // Create the MapView
  34. var view = new MapView({
  35. container: "viewDiv",
  36. map: map,
  37. extent: { // autocasts as new Extent()
  38. xmin: -74.255591362951,
  39. ymin: 40.4961153956091,
  40. xmax: -73.7000090634675,
  41. ymax: 40.915532775817,
  42. spatialReference: 4326
  43. },
  44. });
  45. /*************************************************************
  46. * The PopupTemplate content is the text that appears inside the
  47. * popup. {fieldName} can be used to reference the value of an
  48. * attribute of the selected feature. HTML elements can be used
  49. * to provide structure and styles within the content. The
  50. * fieldInfos property is an array of objects (each object representing
  51. * a field) that is use to format number fields and customize field
  52. * aliases in the popup and legend.
  53. **************************************************************/
  54. var template = { // autocasts as new PopupTemplate()
  55. title: "Boroughs in NY",
  56. content: [{
  57. // It is also possible to set the fieldInfos outside of the content
  58. // directly in the popupTemplate. If no fieldInfos is specifically set
  59. // in the content, it defaults to whatever may be set within the popupTemplate.
  60. type: "fields",
  61. fieldInfos: [{
  62. fieldName: "boro_name",
  63. label: "Borough Name",
  64. visible: true
  65. }, {
  66. fieldName: "shape_area",
  67. label: "Borough Area",
  68. visible: true,
  69. format: {
  70. digitSeparator: true,
  71. places: 0
  72. }
  73. }, {
  74. fieldName: "shape_leng",
  75. label: "Borough Length",
  76. visible: true,
  77. format: {
  78. digitSeparator: true,
  79. places: 0
  80. }
  81. }]
  82. }]
  83. };
  84. // Reference the popupTemplate instance in the
  85. // popupTemplate property of FeatureLayer
  86. var featureLayer = new FeatureLayer({
  87. url: "http://localhost:8080/geoserver/gsr/services/cite/FeatureServer/0",
  88. outFields: ["*"],
  89. popupTemplate: template
  90. });
  91. map.add(featureLayer);
  92. });
  93. require(["esri/config"], function (esriConfig) {
  94. esriConfig.request.corsEnabledServers.push("localhost:8080");
  95. });
  96. </script>
  97. </head>
  98. <body>
  99. <div id="viewDiv"></div>
  100. </body>
  101. </html>
  102. <!-- Esri®, ArcGIS® and ArcGIS Online® are trademarks, registered trademarks, or service marks of Esri in the United States, the European Community, or certain other jurisdictions. Other companies and products mentioned may be trademarks of their respective owners.-->