InfoWindowLite未显示

时间:2015-06-29 16:21:16

标签: javascript arcgis infowindow esri arcgis-js-api

我正在尝试在地图上实现InfoWindowLite Javascript函数。但是,其他一切都在工作,即图例,比例尺,功能层。 以下是供参考的代码:

<!DOCTYPE html>
<html>
<head>
    <!-- add in meta elements -->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Map</title>
    <!-- reference styles -->
    <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css">
    <!-- reference arcGIS javascript -->
    <script src="http://js.arcgis.com/3.9/"></script>
    <style>
        html, body {
            height: 97%;
            width: 98%;
            margin: 1%;
        }

        #rightPane {
            width: 20%;
        }

        #legendPane {
            border: solid #97DCF2 1px;
        }
    </style>
    <!-- javascript -->
    <script>
     var map;
     require([
     "esri/map", "esri/dijit/InfoWindowLite",
     "esri/InfoTemplate", "esri/layers/FeatureLayer", "esri/dijit/Legend",
     "dojo/_base/array", "dojo/parser", "esri/dijit/Scalebar",
     "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
    "dijit/layout/AccordionContainer",  "dojo/dom-construct", "dojo/domReady!"
     ], function(
     Map, InfoWindowLite, InfoTemplate, FeatureLayer, Legend,
     arrayUtils, parser,  Scalebar, domConstruct
     ) {
     parser.parse();
     map = new Map("map", {
     basemap:"topo",
     center: [-98.416, 39.781],
     zoom: 6
     });

      // scalebar
      var scalebar = new Scalebar({
          map: map,
          // "dual" displays both miles and kilmometers
          // "english" is the default, which displays miles
          // use "metric" for kilometers
          scalebarUnit: "dual", attachTo:"bottom-center"

        });

     // feature layer
    var featureLayer = new
     FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3", {
     mode: FeatureLayer.MODE_ONDEMAND,
     outFields:["STATE_NAME", "SUB_REGION", "STATE_ABBR"]
     });
     map.addLayer(featureLayer);


     //add the legend
     map.on("layers-add-result", function (evt) {
     var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {
     return {layer:layer.layer, title:layer.layer.name};
     });
     if (layerInfo.length > 0) {
     var legendDijit = new Legend({
     map: map,
     layerInfos: layerInfo
     }, "legendDiv");
     legendDijit.startup();
     }
     });
     map.addLayers([featureLayer]);


     var legendFeature = new
    FeatureLayer("http://www.onemap.sg/ArcGIS/rest/services/TOC/MapServer/6", {
     mode: FeatureLayer.MODE_ONDEMAND,
     outFields:["*"]
     });

     // infoWindow
     var infoWindow = new InfoWindowLite(null, domConstruct.create("div", null, null,
    map.root));
     infoWindow.startup();
     map.setInfoWindow(infoWindow);
     var template = new InfoTemplate();
    template.setTitle("<b>State name ${STATE_NAME} - State abbr ${STATE_ABBR}</b>");
    template.setContent("${SUB_REGION} is in district ${STATE_NAME}.");

    map.infoWindow.resize(200,75);
     });

      function init() {
     dojo.connect(map,"onLoad", function(map) {map.infoWindow.resize(200, 90);} );
     dojo.connect(map, "onClick", addPoint);
     }
     function addPoint(evt) {
     map.infoWindow.setTitle("Coordinates");
     map.infoWindow.setContent("lat/lon : " + evt.mapPoint.y + ", " + evt.mapPoint.x);
     map.infoWindow.show(evt.screenPoint,map.getInfoWindowAnchor(evt.screenPoint));
     }
     dojo.addOnLoad(init);
    </script>

</head>

<body class="claro">
    <div id="content" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:true" style="width: 100%; height: 100%; margin: 0;">
        <div id="rightPane" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'">
            <div data-dojo-type="dijit/layout/AccordionContainer">
                <div data-dojo-type="dijit/layout/ContentPane" id="legendPane" data-dojo-props="title:'Legend', selected:true">
                    <div id="legendDiv"></div>
                </div>
                <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="title:'Pane 2'">
                    This pane could contain tools or additional content
                </div>
            </div>
        </div>
        <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" style="overflow:hidden;">

        </div>

    </div>
</body>
</html>

我想也许代码所在的顺序就是它没有出现的原因。但是当我在//infoWindow//legend之前的代码移动"GET /admin/login/?next=/admin/ HTTP/1.1" 500 553 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36" 等其他函数之前,当我在chrome中运行它时,其他函数将不会显示。

1 个答案:

答案 0 :(得分:0)

好吧,我在上面的代码段中发现了一些小错误。以下是详细信息。

你忘记添加&#34; BorderContainer,ContentPane,AccordionContainer,&#34;在domConstruct之前。

以下是工作代码:

iPhone-4s, 8.4
iPhone-5, 8.4
iPhone-5s, 8.4
iPhone-6-Plus, 8.4
iPhone-6, 8.4
iPad-2, 8.4
iPad-Retina, 8.4
iPad-Air, 8.4
Resizable-iPhone, 8.4
Resizable-iPad, 8.4

只要您点击地图,就会显示infopopup。

希望这会对你有所帮助:)。