1. 对于Graphic对象,在初始化Graphic对象时设置popupTemplate属性,即可实现点击Graphic时显示弹窗。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Intro to SceneView - Create a 3D map</title>
<style type="text/css">
html, body, .map-container { margin: 0; padding: 0; width: 100%; height: 100%; overflow-x: hidden; overflow-y: hidden; position: relative; }
#map-container .esri-popup__main-container { width: 480px; }
#map-container .esri-popup__header { border-bottom: 1px solid #a9a9a9; }
#map-container .esri-popup__content { margin: 0; }
#map-container .esri-popup__content > div { display: block; width: 450px; margin: 0 15px; }
#map-container .popup-con-title { margin: 1.2em 0; font-weight: bold; }
#map-container .popup-con-con { width: 450px; margin-bottom: 1em; }
</style>
</head>
<body>
<div class="map-container" id="map-container"></div>
<link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
<script src="https://js.arcgis.com/4.5/"></script>
<script type="text/javascript">
require(["esri/Map", "esri/views/SceneView", "esri/Graphic", "dojo/domReady!"], function (Map, SceneView, Graphic) {
_map = new Map({
"basemap": "satellite",
"ground": "world-elevation"
});
_view = new SceneView({
"map": _map,
"container": "map-container"
});
//_view.ui.empty("top-left"); //清空左上角区域按钮 var lng = 116.46, lat = 39.92;
_view.then(function () {
_view.goTo({ "zoom": 11, "tilt": 45, "center": [lng, lat] });
var g = new Graphic({
"geometry": { "type": "point", "latitude": lat, "longitude": lng, "spatialReference": { "wkid": 4326 } },
"symbol": { "type": "simple-marker", "color": [226, 119, 40], },
"attributes": { "id": 1, "name": "名称XXXXX", "value": "结果YYYYY" },
"popupTemplate": {
"title": "信息提示",
"content": "<p class='popup-con-title'>这是一个模拟火情点</p>"
+ "<div class='popup-con-con'>"
+ "<div>坐标位置.经度:" + lng + "</div>"
+ "<div>坐标位置.纬度:" + lat + "</div>"
+ "<div>还可以显示其他的属性信息,并且这些信息可以自定义布局</div>"
+ "</div>"
}
});
_view.graphics.add(g);
});
});
</script>
</body>
</html>

2. 上面设置Graphic的popupTemplate属性只有在点击对象时才会显示弹窗。如果有这样一个需求,点击页面上某个按钮显示弹窗,则需要采用SceneView对象的popup属性来实现。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Intro to SceneView - Create a 3D map</title>
<style type="text/css">
html, body, .map-container { margin: 0; padding: 0; width: 100%; height: 100%; overflow-x: hidden; overflow-y: hidden; position: relative; }
#map-container .esri-popup__main-container { width: 480px; }
#map-container .esri-popup__header { border-bottom: 1px solid #a9a9a9; }
#map-container .esri-popup__content { margin: 0; }
#map-container .esri-popup__content > div { display: block; width: 450px; margin: 0 15px; }
#map-container .popup-con-title { margin: 1.2em 0; font-weight: bold; }
#map-container .popup-con-con { width: 450px; margin-bottom: 1em; }
.btn-container { position: absolute; top: 25px; right: 25px; }
</style>
</head>
<body>
<div class="map-container" id="map-container"></div>
<div class="btn-container">
<button id="btn-show">显示弹窗</button>
</div>
<link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
<script src="https://js.arcgis.com/4.5/"></script>
<script type="text/javascript">
require(["esri/Map", "esri/views/SceneView", "esri/Graphic", "dojo/domReady!"], function (Map, SceneView, Graphic) {
_map = new Map({
"basemap": "satellite",
"ground": "world-elevation"
});
_view = new SceneView({
"map": _map,
"container": "map-container"
});
//_view.ui.empty("top-left"); //清空左上角区域按钮 var lng = 116.46, lat = 39.92;
_view.then(function () {
_view.goTo({ "zoom": 11, "tilt": 45, "center": [lng, lat] });
var g = new Graphic({
"geometry": { "type": "point", "latitude": lat, "longitude": lng, "spatialReference": { "wkid": 4326 } },
"symbol": { "type": "simple-marker", "color": [226, 119, 40], },
"attributes": { "id": 1, "name": "名称XXXXX", "value": "结果YYYYY" }
});
_view.graphics.add(g);
dojo.connect(dojo.byId("btn-show"), "onclick", function () {
console.info(g);
_view.popup.visible = false;
_view.popup.title = g.attributes.name;
_view.popup.location = g.geometry;
_view.popup.content =
"<p class='popup-con-title'>这是一个模拟火情点</p>"
+ "<div class='popup-con-con'>"
+ "<div>坐标位置.经度:" + g.geometry.x + "</div>"
+ "<div>坐标位置.纬度:" + g.geometry.y + "</div>"
+ "<div>还可以显示其他的属性信息,并且这些信息可以自定义布局</div>"
+ "</div>";
_view.popup.visible = true;
});
});
});
</script>
</body>
</html>

3.当页面中存在对Graphic连线或移动等其他操作,此时需要暂时禁用Graphic弹窗。当未进行此操作时,要显示弹窗。需要SceneView对象的popup属性和hitTest函数配合来使用。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Intro to SceneView - Create a 3D map</title>
<style type="text/css">
html, body, .map-container { margin: 0; padding: 0; width: 100%; height: 100%; overflow-x: hidden; overflow-y: hidden; position: relative; }
#map-container .esri-popup__main-container { width: 480px; }
#map-container .esri-popup__header { border-bottom: 1px solid #a9a9a9; }
#map-container .esri-popup__content { margin: 0; }
#map-container .esri-popup__content > div { display: block; width: 450px; margin: 0 15px; }
#map-container .popup-con-title { margin: 1.2em 0; font-weight: bold; }
#map-container .popup-con-con { width: 450px; margin-bottom: 1em; }
.btn-container { position: absolute; top: 25px; right: 25px; color:#fff }
</style>
</head>
<body>
<div class="map-container" id="map-container"></div>
<div class="btn-container">
<input type="checkbox" id="chk_disable"/>禁用弹窗
</div>
<link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
<script src="https://js.arcgis.com/4.5/"></script>
<script type="text/javascript">
require(["esri/Map", "esri/views/SceneView", "esri/Graphic", "dojo/domReady!"], function (Map, SceneView, Graphic) {
_map = new Map({
"basemap": "satellite",
"ground": "world-elevation"
});
_view = new SceneView({
"map": _map,
"container": "map-container"
});
//_view.ui.empty("top-left"); //清空左上角区域按钮 var lng = 116.46, lat = 39.92;
_view.then(function () {
_view.goTo({ "zoom": 5, "tilt": 5, "center": [lng, lat] });
var g = new Graphic({
"geometry": { "type": "point", "latitude": lat, "longitude": lng, "spatialReference": { "wkid": 4326 } },
"symbol": { "type": "simple-marker", "color": [226, 119, 40], },
"attributes": { "id": 1, "name": "名称XXXXX", "value": "结果YYYYY" }
});
_view.graphics.add(g);
_view.on("click", function (event) {
_view.hitTest({ x: event.x, y: event.y }).then(function (response) {
if (document.getElementById("chk_disable").checked) {
return;
}
var gCurr = response.results[0].graphic;
_view.popup.open();
_view.popup.title = gCurr.attributes.name;
_view.popup.location = gCurr.geometry;
_view.popup.content =
"<p class='popup-con-title'>这是一个模拟火情点</p>"
+ "<div class='popup-con-con'>"
+ "<div>坐标位置.经度:" + gCurr.geometry.x + "</div>"
+ "<div>坐标位置.纬度:" + gCurr.geometry.y + "</div>"
+ "<div>还可以显示其他的属性信息,并且这些信息可以自定义布局</div>"
+ "</div>";
_view.popup.visible = true;
});
});
});
});
</script>
</body>
</html>

最新文章

  1. sass1:
  2. jquery选择器使用说明
  3. QT 常用控件一
  4. SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、&lt;jpa:repositories&gt;)
  5. 李洪强iOS开发支付集成之支付宝支付
  6. 随机提取N条记录[多种数据库方法]
  7. Linux学习之路:shell变量(一)
  8. ES6笔记-字符串方法
  9. Android AlarmManager实现不间断轮询服务
  10. 大数据Lambda架构
  11. MYsql优化where子句
  12. 修改Elasticsearch的settings
  13. 【整理】Java 10新特性总结
  14. js/jquery禁止页面回退
  15. IC 设计中DFT的Boundary Scan功能
  16. 第11月第18天 RACSequence
  17. win 7 下合并多个表格
  18. C# [method Modifiers] abstract virtual override new
  19. master分支合并
  20. BZOJ3998:[TJOI2015]弦论——题解

热门文章

  1. (转)xshell无法在vim中复制黏贴
  2. python3 打印九九乘法表
  3. POJ 2406 Power Strings KMP求周期
  4. 18、x264编码在zedboard上的实现(软编码)
  5. [Angular2] @Ngrx/store and @Ngrx/effects learning note
  6. boost::asio的http client应用笔记
  7. css3-7 如何让页面元素水平垂直都居中(元素定位要用css定位属性)
  8. ajax实现注册用户名时动态显示用户名是否已经被注册(1、ajax可以实现我们常见的注册用户名动态判断)(2、jquery里面的ajax也是类似我们这样封装了的函数)
  9. TF-IDF计算方法和基于图迭代的TextRank
  10. php计算两个坐标直线距离