arcgis api for js 4.x弹出框popuptemplate

 

案例一

let illigalMessage = {
      title: "违建核查",
      id: 'illigalMessage',
      image: './src/assets/img/edit.png'
    }
let illigalWordMessage = {
      title: "图斑整治情况",
      id: 'illigalWordMessage',
      image: './src/assets/img/illigalWordMessage.png'
    }
let historyMessage = {
      title: "批转历史记录",
      id: 'history',
      image: './src/assets/img/history.png'
    }
// 以上为按钮编辑
let template = {
      title: '违建信息',
      content: [{
          type: 'fields',
          fieldInfos: [
            {
              fieldName: 'ZJMC',
              label: '所属镇'
            },
            {
              fieldName: 'TBBM',
              label: '图斑编号'
            },
            {
              fieldName: 'QQZT',
              label: '建筑状态'
            },
            {
              fieldName: 'XZCMC',
              label: '所属村'
            },
            {
              fieldName: 'ZDMJ',
              label: '面积',
              format: {
                places: 2,
                digitSeparator: true
              }
            },
            {
              fieldName: 'expression/illigalExpression'
            }
          ]
      }],
      expressionInfos: [{
        name: "illigalExpression",
        title: "是否核查",
        expression: `
          return Decode($feature.STATE,1,"已核查",0,"未核查","更新状态请刷新")
        `
      }],
      actions: [illigalMessage, illigalWordMessage, historyMessage]
    }

先编辑完按钮,然后加入popuptemplate的action中就行。

使用:

mainMap.view.popup.on("trigger-action",async function (event) {
    if (event.action.id === "illigalMessage") {
        // 业务代码
    }
 
}

监听trigger-action变化就行。

三、如果想把原来的zoom to按钮给去除,只需要加上 featureLayer.popupTemplate.overwriteActions = true

案例二 

  1. <head>

  2. <meta charset="UTF-8">

  3. <title>要素服务</title>

  4. <link type="text/css" rel="stylesheet" href="http://localhost/arcgis/esri/css/main.css"/>

  5. <link type="text/css" rel="stylesheet" href="css/index.css"/>

  6. <script>

  7. //高亮显示只能在WebGL渲染时才能生效,该功能目前处于beta阶段

  8. var dojoConfig = {

  9. has: {

  10. "esri-featurelayer-webgl": 1

  11. }

  12. }

  13. </script>

  14. <script src="http://localhost/arcgis/"></script>

  15. </head>

  16. <body>

  17. <div id="viewDiv"></div>

  18.  
  19. <script>

  20. require(["esri/Map", "esri/views/MapView", "esri/config", "esri/layers/FeatureLayer", "dojo/domReady"], function (Map, MapView, esriConfig, FeatureLayer) {

  21. esriConfig.request.corsEnabledServers.push("localhost:6443");//设置地图服务器已允许跨域

  22. esriConfig.request.corsEnabledServers.push("localhost:63342");

  23. var map = new Map({

  24. // basemap: "streets"//ESRI提供的底 图

  25. basemap: "dark-gray"

  26. });

  27. //二维视图,并初始化视图位置

  28. var view = new MapView({

  29. container: "viewDiv",

  30. map: map,

  31. extent: {

  32. xmin: 111.27418783887504,

  33. ymin: 27.65361115167269,

  34. xmax: 119.18589568326072,

  35. ymax: 30.663629324047992,

  36. spatialReference: 4326

  37. }

  38. });

  39. //乡镇级属性模版

  40. var popupTemplate = {

  41. title: "乡镇数据",

  42. content: [{

  43. type: "fields",

  44. fieldInfos: [{

  45. fieldName: "name",

  46. label: "行政单位名称",

  47. format: {

  48. places: 0,

  49. digitSeparator: true

  50. }

  51. }, {

  52. fieldName: "code",

  53. label: "行政单位代码",

  54. format: {

  55. places: 0,

  56. digitSeparator: true

  57. }

  58. }, {

  59. fieldName: "supercode",

  60. label: "上级行政单位代码",

  61. format: {

  62. places: 0,

  63. digitSeparator: true

  64. }

  65. }, {

  66. fieldName: "level",

  67. label: "行政单位等级",

  68. format: {

  69. places: 0,

  70. digitSeparator: true

  71. }

  72. }]

  73. }]

  74. };

  75. var town = new FeatureLayer({

  76. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/0",

  77. outFields: ["*"],

  78. popupTemplate: popupTemplate

  79. });//乡镇级数据

  80. popupTemplate.title = "县级数据";

  81. var county = new FeatureLayer({

  82. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/1",

  83. outFields: ["*"],

  84. popupTemplate: popupTemplate

  85. });//县级数据

  86. popupTemplate.title = "市级数据";

  87. var city = new FeatureLayer({

  88. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/2",

  89. outFields: ["*"],

  90. popupTemplate: popupTemplate

  91. });//市级数据

  92. popupTemplate.title = "省级数据";

  93. var province = new FeatureLayer({

  94. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/3",

  95. outFields: ["*"],

  96. popupTemplate: popupTemplate

  97. });//省级数据

  98. map.add(town);

  99. map.add(county);

  100. map.add(city);

  101. map.add(province);

  102. //点击视窗进行碰撞检测,检测点击的目标graphic

  103. view.on("click", function (evt) {

  104. view.hitTest(evt).then(function (response) {

  105. var result = response.results[0];

  106. if (result && result.graphic) {

  107. console.log(result);

  108. var graphic = result.graphic;

  109. //自定义高亮

  110. //这里的几何图形是面状,配置graphic的symbol为fillSymbol

  111. graphic.symbol = {

  112. type: "simple-fill",

  113. color: "red",

  114. outline: {

  115. color: [128, 128, 128, 0.5],

  116. width: "0.5px"

  117. }

  118. };

  119. view.graphics.removeAll();//清除上一次点击目标

  120. view.graphics.add(graphic);//添加新的点击目标

  121. }

  122. })

  123. });

  124. })

  125. </script>

  126. </body>

  127. </html>

二维模式效果图:

三维模式代码:

 
  1. <!DOCTYPE html>

  2. <html lang="en">

  3. <head>

  4. <meta charset="UTF-8">

  5. <title>要素服务</title>

  6. <link type="text/css" rel="stylesheet" href="http://localhost/arcgis/esri/css/main.css"/>

  7. <link type="text/css" rel="stylesheet" href="css/index.css"/>

  8. <script src="http://localhost/arcgis/init.js"></script>

  9. </head>

  10. <body>

  11. <div id="viewDiv"></div>

  12. <script>

  13. require(["esri/Map", "esri/views/SceneView", "esri/config", "esri/layers/FeatureLayer", "dojo/domReady"], function (Map, SceneView, esriConfig, FeatureLayer) {

  14. esriConfig.request.corsEnabledServers.push("localhost:6443");//设置地图服务器已允许跨域

  15. esriConfig.request.corsEnabledServers.push("localhost:63342");

  16. var map = new Map({

  17. basemap: "dark-gray"

  18. });

  19. //二维视图,并初始化视图位置

  20. var view = new SceneView({

  21. container: "viewDiv",

  22. map: map,

  23. extent: {

  24. xmin: 111.27418783887504,

  25. ymin: 27.65361115167269,

  26. xmax: 119.18589568326072,

  27. ymax: 30.663629324047992,

  28. spatialReference: 4326

  29. }

  30. });

  31. //乡镇级属性模版

  32. var popupTemplate = {

  33. title: "乡镇数据",

  34. content: [{

  35. type: "fields",

  36. fieldInfos: [{

  37. fieldName: "name",

  38. label: "行政单位名称",

  39. format: {

  40. places: 0,

  41. digitSeparator: true

  42. }

  43. }, {

  44. fieldName: "code",

  45. label: "行政单位代码",

  46. format: {

  47. places: 0,

  48. digitSeparator: true

  49. }

  50. }, {

  51. fieldName: "supercode",

  52. label: "上级行政单位代码",

  53. format: {

  54. places: 0,

  55. digitSeparator: true

  56. }

  57. }, {

  58. fieldName: "level",

  59. label: "行政单位等级",

  60. format: {

  61. places: 0,

  62. digitSeparator: true

  63. }

  64. }]

  65. }]

  66. };

  67. var town = new FeatureLayer({

  68. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/0",

  69. outFields: ["*"],

  70. popupTemplate: popupTemplate

  71. });//乡镇级数据

  72. popupTemplate.title = "县级数据";

  73. var county = new FeatureLayer({

  74. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/1",

  75. outFields: ["*"],

  76. popupTemplate: popupTemplate

  77. });//县级数据

  78. popupTemplate.title = "市级数据";

  79. var city = new FeatureLayer({

  80. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/2",

  81. outFields: ["*"],

  82. popupTemplate: popupTemplate

  83. });//市级数据

  84. popupTemplate.title = "省级数据";

  85. var province = new FeatureLayer({

  86. url: "https://localhost:6443/arcgis/rest/services/jiangxi/FeatureServer/3",

  87. outFields: ["*"],

  88. popupTemplate: popupTemplate

  89. });//省级数据

  90. map.add(town);

  91. map.add(county);

  92. map.add(city);

  93. map.add(province);

  94. })

  95. </script>

  96. </body>

  97. </html>

三维模式效果图:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值