Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5.  
  6. <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  7. <title>Feature Layer - display results as an InfoWindow onHover</title>
  8.  
  9. <link rel="stylesheet" href="https://js.arcgis.com/3.15/dijit/themes/tundra/tundra.css">
  10. <link rel="stylesheet" href="https://js.arcgis.com/3.15/esri/css/esri.css">
  11. <style>
  12. html, body, #mapDiv {
  13. padding:0;
  14. margin:0;
  15. height:100%;
  16. }
  17. #mapDiv {
  18. position: relative;
  19. }
  20. #info {
  21. background: #fff;
  22. box-shadow: 0 0 5px #888;
  23. left: 1em;
  24. padding: 0.5em;
  25. position: absolute;
  26. top: 1em;
  27. z-index: 40;
  28. }
  29. </style>
  30.  
  31. <script src="https://js.arcgis.com/3.15/"></script>
  32. <script>
  33. var map, dialog;
  34. require([
  35. "esri/map", "esri/layers/FeatureLayer",
  36. "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol",
  37. "esri/renderers/SimpleRenderer", "esri/graphic", "esri/lang",
  38. "esri/Color", "dojo/number", "dojo/dom-style",
  39. "dijit/TooltipDialog", "dijit/popup", "dojo/domReady!"
  40. ], function(
  41. Map, FeatureLayer,
  42. SimpleFillSymbol, SimpleLineSymbol,
  43. SimpleRenderer, Graphic, esriLang,
  44. Color, number, domStyle,
  45. TooltipDialog, dijitPopup
  46. ) {
  47. map = new Map("mapDiv", {
  48. basemap: "streets",
  49. center: [-80.94, 33.646],
  50. zoom: 8,
  51. slider: false
  52. });
  53.  
  54. var southCarolinaCounties = new FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3", {
  55. mode: FeatureLayer.MODE_SNAPSHOT,
  56. outFields: ["NAME", "POP2000", "POP2007", "POP00_SQMI", "POP07_SQMI"]
  57. });
  58. southCarolinaCounties.setDefinitionExpression("STATE_NAME = 'South Carolina'");
  59.  
  60. var symbol = new SimpleFillSymbol(
  61. SimpleFillSymbol.STYLE_SOLID,
  62. new SimpleLineSymbol(
  63. SimpleLineSymbol.STYLE_SOLID,
  64. new Color([255,255,255,0.35]),
  65. 1
  66. ),
  67. new Color([125,125,125,0.35])
  68. );
  69. southCarolinaCounties.setRenderer(new SimpleRenderer(symbol));
  70. map.addLayer(southCarolinaCounties);
  71.  
  72. map.infoWindow.resize(245,125);
  73.  
  74. dialog = new TooltipDialog({
  75. id: "tooltipDialog",
  76. style: "position: absolute; width: 250px; font: normal normal normal 10pt Helvetica;z-index:100"
  77. });
  78. dialog.startup();
  79.  
  80. var highlightSymbol = new SimpleFillSymbol(
  81. SimpleFillSymbol.STYLE_SOLID,
  82. new SimpleLineSymbol(
  83. SimpleLineSymbol.STYLE_SOLID,
  84. new Color([255,0,0]), 3
  85. ),
  86. new Color([125,125,125,0.35])
  87. );
  88.  
  89. //close the dialog when the mouse leaves the highlight graphic
  90. map.on("load", function(){
  91. map.graphics.enableMouseEvents();
  92. map.graphics.on("mouse-out", closeDialog);
  93.  
  94. });
  95.  
  96. //listen for when the onMouseOver event fires on the countiesGraphicsLayer
  97. //when fired, create a new graphic with the geometry from the event.graphic and add it to the maps graphics layer
  98. southCarolinaCounties.on("mouse-over", function(evt){
  99. var t = "<b>${NAME}</b><hr><b>2000 Population: </b>${POP2000:NumberFormat}<br>"
  100. + "<b>2000 Population per Sq. Mi.: </b>${POP00_SQMI:NumberFormat}<br>"
  101. + "<b>2007 Population: </b>${POP2007:NumberFormat}<br>"
  102. + "<b>2007 Population per Sq. Mi.: </b>${POP07_SQMI:NumberFormat}";
  103.  
  104. var content = esriLang.substitute(evt.graphic.attributes,t);
  105. var highlightGraphic = new Graphic(evt.graphic.geometry,highlightSymbol);
  106. map.graphics.add(highlightGraphic);
  107.  
  108. dialog.setContent(content);
  109.  
  110. domStyle.set(dialog.domNode, "opacity", 0.85);
  111. dijitPopup.open({
  112. popup: dialog,
  113. x: evt.pageX,
  114. y: evt.pageY
  115. });
  116. });
  117.  
  118. function closeDialog() {
  119. map.graphics.clear();
  120. dijitPopup.close(dialog);
  121. }
  122.  
  123. });
  124. </script>
  125. </head>
  126. <body class="tundra">
  127. <div id="mapDiv">
  128. <div id="info">
  129. Hover over a county in South Carolina to get more information.
  130. </div>
  131. </div>
  132. </body>
  133. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement