2015-06-24 25 views
-6

您可以在下面的鏈接中找到該代碼。

Sample running Code

在infoTemplate ${NAME}顯示縣名。

我想添加一個顯示縣名的警告框。我可以創建一個警告框但不能顯示縣名。

我在做什麼錯?

+0

對上述問題的回答有助於我進一步工作。我想知道的主要事情是如何訪問縣名? – Santosh

+0

在問題中顯示相關代碼,而不僅僅是指向它的鏈接。 – Oka

+0

alert(「$ {NAME}」);/*這應顯示縣名,但它不適合我...... */ var infoTemplate = new InfoTemplate(「$ {NAME}」,「$ {*}」);/*它顯示縣名..... */ var featureLayer = new FeatureLayer(「http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3」,{ mode: FeatureLayer.MODE_SNAPSHOT, outFields:[「*」], infoTemplate:infoTemplate }); – Santosh

回答

0

我們可以訪問$ name中infotemplate外通過以下方式... 變種T = 「$ {NAME}


事件:」 + INC //字符串替換方法 VAR含量= esriLang.substitute( evt.graphic.attributes,T);

0

好吧,要顯示警報,您必須在該功能上附加單擊事件,或者您必須使用任何事件來傳播警報消息。 在上面的示例url中,我使用要素圖層單擊事件在警報中顯示「NAME」。

下面是工作代碼:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
     on iOS devices--> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"> 
    <title>Class Breaks Renderer</title> 

    <link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css"> 
    <style> 
     html, body, #map{ 
     height: 100%; 
     margin: 0; 
     padding: 0; 
     } 
    </style> 
    <script src="http://js.arcgis.com/3.13/"></script> 
    <script> 
     var map; 
     require([ 
     "esri/map", "esri/layers/FeatureLayer", 
     "esri/InfoTemplate", "esri/symbols/SimpleFillSymbol", 
     "esri/renderers/ClassBreaksRenderer", 
     "esri/Color", "dojo/dom-style", "dojo/on", "dojo/domReady!" 
     ], function(
     Map, FeatureLayer, 
     InfoTemplate, SimpleFillSymbol, 
     ClassBreaksRenderer, 
     Color, domStyle, on 
    ) { 
     map = new Map("map", { 
      basemap: "streets", 
      center: [-98.215, 38.382], 
      zoom: 7, 
      slider: false 
     }); 

     var symbol = new SimpleFillSymbol(); 
     symbol.setColor(new Color([150, 150, 150, 0.5])); 

     // Add five breaks to the renderer. 
     // If you have ESRI's ArcMap available, this can be a good way to determine break values. 
     // You can also copy the RGB values from the color schemes ArcMap applies, or use colors 
     // from a site like www.colorbrewer.org 
     // 
     // alternatively, ArcGIS Server's generate renderer task could be used 
     var renderer = new ClassBreaksRenderer(symbol, "POP07_SQMI"); 
     renderer.addBreak(0, 25, new SimpleFillSymbol().setColor(new Color([56, 168, 0, 0.5]))); 
     renderer.addBreak(25, 75, new SimpleFillSymbol().setColor(new Color([139, 209, 0, 0.5]))); 
     renderer.addBreak(75, 175, new SimpleFillSymbol().setColor(new Color([255, 255, 0, 0.5]))); 
     renderer.addBreak(175, 400, new SimpleFillSymbol().setColor(new Color([255, 128, 0, 0.5]))); 
     renderer.addBreak(400, Infinity, new SimpleFillSymbol().setColor(new Color([255, 0, 0, 0.5]))); 

     var infoTemplate = new InfoTemplate("${NAME}", "${*}"); 
     var featureLayer = new FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3", { 
      mode: FeatureLayer.MODE_SNAPSHOT, 
      outFields: ["*"], 
      infoTemplate: infoTemplate 
     }); 

     featureLayer.setDefinitionExpression("STATE_NAME = 'Kansas'"); 
     featureLayer.setRenderer(renderer); 
     map.addLayer(featureLayer); 
     on(featureLayer, "click", function(evt){ 
      alert(evt.graphic.attributes.NAME) 
     }); 
     }); 
    </script> 
    </head> 

    <body> 
    <div id="map"></div> 
    </body> 

</html> 

在這種代碼我以上特徵層點擊事件的示例代碼已經使用。

希望這將幫助你:)

讓我知道是否需要任何澄清!

+0

它適合你嗎? –

+0

我還沒有嘗試過,但我以不同的方式得到了.. – Santosh

+0

好吧然後... :) –