码迷,mamicode.com
首页 > 其他好文 > 详细

Intro to popups

时间:2018-12-28 13:27:50      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:ice   erro   int   enter   zoom   response   any   arcgis   Locator   

技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
 <title>Intro to popups - 4.10</title>
 <link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
 <style>
     html,body,#viewDiv {
       padding: 0;
       margin: 0;
       height: 100%;
       width: 100%;
     }
     #instruction {
       z-index: 99;
       position: absolute;
       top: 15px;
       left: 50%;
       padding: 5px;
       margin-left: -175px;
       height: 20px;
       width: 350px;
       background: rgba(25, 25, 25, 0.8);
       color: white;
     }
 </style>
   <script src="https://js.arcgis.com/4.10/"></script>
   <script type="text/javascript">
    require([
     "esri/tasks/Locator",
     "esri/Map",
     "esri/views/MapView"
     ],function(
      Locator,
      Map,
      MapView
      )
     {
      // Set up a locator task using the world geocoding service
         var locatorTask = new Locator({
           url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"
         });
 
      var map = new Map({
       basemap:"streets-navigation-vector"
      });
      var view = new MapView({
       container:"viewDiv",
       map:map,
       center: [-116.3031, 43.6088],
           zoom: 12
      });
 
      view.popup.autoOpenEnabled = false;//这句话不加会出错

      view.on("click",function(event){//所有的操作都是在点击的事件的同时发生的,所以都要放在这个事件里面
       var lat = Math.round(event.mapPoint.latitude*1000)/1000;
       var lon = Math.round(event.mapPoint.longitude*1000)/1000;
       view.popup.open({
        title:"Reverse geocode:["+lon+","+lat+"]",
        location:event.mapPoint
       });
       // Display the popup
           // Execute a reverse geocode using the clicked location
           locatorTask.locationToAddress(event.mapPoint).then(function(response){
            view.popup.content = response.address;
           }).catch(function(error){
            view.popup.content = "no address was found for this location";
           })
      })
     })
   </script>
</head>
<body>
 <div id="viewDiv"></div>
   <div id="instruction">Click any location on the map to see its street address</div>
</body>
</html>

Intro to popups

标签:ice   erro   int   enter   zoom   response   any   arcgis   Locator   

原文地址:https://www.cnblogs.com/GIS-Yangol/p/10189868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!