1

我已经使用 arcgis javascript api 示例在 web 上显示了我的地图。在示例中,它显示一个弹出窗口,但在我这边却没有。现在我想添加弹出窗口。我想当用户点击不同类型的土壤时会打开一个弹出窗口并显示图层的属性

<!DOCTYPE html>
<html>
  <head>
    <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>Create web map from JSON</title>

    <link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css"/>
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css" />
    <link rel="stylesheet" href="css/layout.css"/>

    <script src="https://js.arcgis.com/3.20/"></script>
    <script>
      require([
        "dojo/parser",
        "dojo/ready",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dojo/dom",
        "esri/map", 
        "esri/geometry/Extent",
        "esri/urlUtils",
        "esri/arcgis/utils",
        "esri/dijit/Legend",
        "esri/dijit/Scalebar",
        "dojo/domReady!"
      ], function(
        parser,
        ready,
        BorderContainer,
        ContentPane,
        dom,
        Map,
        Extent,
        urlUtils,
        arcgisUtils,
        Legend,
        Scalebar
      ) {
        ready(function(){

        parser.parse();

        var webmap = {};
        webmap.item = {
          "title":"Soil Map",
         "snippet": "This map shows the Soil types",
          "extent": [[73.94251383600005, 31.02571637300008],[74.05297753900004, 31.11529292900019]]
        };

        webmap.itemData = {
          "operationalLayers": [{
            "url": "http://localhost:6080/arcgis/rest/services/Soil_Maps/soil_map/MapServer",
            "visibility": true,
            "opacity": 0.75,
            "title": "Soil Survey Map",
            
          }],
          "baseMap": {
            "baseMapLayers": [{
              "opacity": 1,
              "visibility": true,
              "url": "https://services.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer"
              },{
              "isReference": true,
              "opacity": 1,
              "visibility": true,
              "url": "https://services.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer"
              }],
            "title": "World_Terrain_Base"
          },
          "version": "1.1"
        };

        dom.byId("title").innerHTML = webmap.item.title;
        dom.byId("subtitle").innerHTML = webmap.item.snippet;

        arcgisUtils.createMap(webmap,"map").then(function(response){


          var map = response.map;



          //add the scalebar 
          var scalebar = new Scalebar({
            map: map,
            scalebarUnit: "english"
          });

          //add the legend. Note that we use the utility method getLegendLayers to get 
          //the layers to display in the legend from the createMap response.
          var legendLayers = arcgisUtils.getLegendLayers(response); 
          var legendDijit = new Legend({
            map: map,
            layerInfos: legendLayers
          },"legend");
          legendDijit.startup();


        });


        });

      });

    </script>
  </head>

  <body class="claro">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'" style="width:100%; height:100%;">
      <div id="header" class="shadow roundedCorners" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">
        <div id="title"></div>
        <div id="subtitle"></div>
      </div>
      <div id="map" class="roundedCorners shadow" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
      <div id="rightPane" class="roundedCorners shadow" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'" >
        <div id="legend"></div>
      </div>
    </div>
  </body>
</html>

4

3 回答 3

1

始终建议我们应该使用 webmap/item id 而不是 webmap json。

一旦您能够获取 webmap id 或 item id,然后使用下面的代码,您就可以使用 webmap-

require([
        "dojo/parser",
        "dojo/ready",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dojo/dom",
        "esri/map",
        "esri/urlUtils",
        "esri/arcgis/utils",
        "esri/dijit/Legend",
        "esri/dijit/Scalebar",
        "dojo/domReady!"
      ], function(
        parser,
        ready,
        BorderContainer,
        ContentPane,
        dom,
        Map,
        urlUtils,
        arcgisUtils,
        Legend,
        Scalebar
      ) {
        ready(function(){

        parser.parse();


//***** change webmapid only
arcgisUtils.createMap("ef9c7fbda731474d98647bebb4b33c20","map").then(function(response){
          

          var map = response.map;



          //add the scalebar
          var scalebar = new Scalebar({
            map: map,
            scalebarUnit: "english"
          });

          //add the legend. Note that we use the utility method getLegendLayers to get
          //the layers to display in the legend from the createMap response.
          var legendLayers = arcgisUtils.getLegendLayers(response);
          var legendDijit = new Legend({
            map: map,
            layerInfos: legendLayers
          },"legend");
          legendDijit.startup();


        });


        });

      });
<link rel="stylesheet" href="https://js.arcgis.com/3.20/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
    <link rel="stylesheet" href="https://developers.arcgis.com/javascript/3/samples/ags_createwebmapid/css/layout.css">

    <script src="https://js.arcgis.com/3.20/"></script>
    <body class="claro">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'" style="width:100%; height:100%;">

      <div id="map" class="roundedCorners shadow" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
      <div id="rightPane" class="roundedCorners shadow" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'" >
        <div id="legend"></div>
      </div>
    </div>
  </body>

注意:-根据其中的注释更新代码

希望这会帮助你:)

于 2017-06-09T22:40:12.487 回答
0

您误用了“esri/urlUtils”模块,它主要提供实用方法来处理来自 ArcGIS.com 的内容。因此,您不能使用其 createMap 方法通过本地 arcgis 服务器地图服务创建地图,而应通过 arcgis.com 发布您的业务图层,并获取地图项 id 。请参阅如何通过 csv 或 featurelayer 发布托管要素图层

1.使用“esri/urlUtils”模块创建地图

您可以使用“esri/urlUtils”模块的 creatMap 方法使用 json 或 itemid 创建地图。

1)通过json创建web地图,完整代码见
developers.arcgis.com/javascript/3/jssamples/ags_createwebmapitem.html

webmap.itemData = {
                "operationalLayers": [{
                    "url": "xxx",// your map service goes here
                    "visibility": true,
                    "opacity": 0.75,
                    "title": "Soil Survey Map",
                    "itemId": "xx"//your map item id in arcgis.com
      }],...

注意:JSON 应包含您在 arcgis.com 中的业务层项目 ID

2)通过itemid创建web地图(推荐),完整代码见
developers.arcgis.com/javascript/3/jssamples/ags_createwebmapid.html

            ready(function () {

            parser.parse();

            //if accessing webmap from a portal outside of ArcGIS Online, uncomment and replace path with portal URL
            //arcgisUtils.arcgisUrl = "https://pathto/portal/sharing/content/items";
            arcgisUtils.createMap("ef9c7fbda731474d98647bebb4b33c20", "map").then(function (response) {
                //update the app
                dom.byId("title").innerHTML = response.itemInfo.item.title;
                dom.byId("subtitle").innerHTML = response.itemInfo.item.snippet;

                var map = response.map;



                //add the scalebar
                var scalebar = new Scalebar({
                    map: map,
                    scalebarUnit: "english"
                });

                //add the legend. Note that we use the utility method getLegendLayers to get
                //the layers to display in the legend from the createMap response.
                var legendLayers = arcgisUtils.getLegendLayers(response);
                var legendDijit = new Legend({
                    map: map,
                    layerInfos: legendLayers
                }, "legend");
                legendDijit.startup();
            });
        });

2.添加弹窗,部分示例见developers.arcgis.com/javascript/3/jssamples/#search/Popup

如果你有很多地图要显示,你应该使用 featurelayer 向地图添加数据。详细信息请参阅 ags js api 文档。

于 2017-06-23T14:48:06.733 回答
0

好吧,正如我在代码片段中看到的那样,webmap json 不包含 infowindow/popup 配置设置,因为我认为它在您的示例中不可见。

但是推荐的方法是创建一个在线 esri 网络地图,它将为您处理所有这些复杂问题。并在 webmap 中添加您的 esri 地图服务器。之后配置图层的弹出窗口。

创建网络地图的过程非常简单,以下是执行此操作的步骤-

  1. 选择底图
  2. 添加图层
  3. 改变风格
  4. 配置弹出窗口
  5. 保存地图
  6. 分享网络地图

源网络地图:- http://doc.arcgis.com/en/arcgis-online/reference/what-is-web-map.htm

源步骤:- http://doc.arcgis.com/en/arcgis-online/get-started/get-started-with-maps.htm

如果您需要更多信息,请告诉我,我会相应更新。

希望这会帮助你:)

于 2017-06-09T22:26:08.430 回答