【ArcGIS for JavaScript】加载地图,并标注点

来源:互联网 发布:淘宝店标图片尺寸 编辑:程序博客网 时间:2024/06/05 07:24
[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2.   
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4.   
  5.     <head>  
  6.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  7.         <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />  
  8.         <script src="config.js" type="text/javascript"></script>  
  9.         <script src="gisapi/arcgisapi/library/3.16/3.16/init.js" type="text/javascript"></script>  
  10.         <link type="text/css" href="gisapi/arcgisapi/library/3.16/3.16/esri/css/esri.css" rel="stylesheet" />  
  11.         <link type="text/css" href="gisapi/arcgisapi/library/3.16/3.16/dijit/themes/tundra/tundra.css" rel="stylesheet" />  
  12.         <title>Map hello world</title>  
  13.         <style>  
  14.             html,  
  15.             body,  
  16.             #map {  
  17.                 height: 100%;  
  18.                 margin: 0;  
  19.                 padding: 0;  
  20.                 overflow: hidden;  
  21.             }  
  22.         </style>  
  23.         <script>  
  24.             var map;  
  25.             require(["esri/map",  
  26.                     "esri/SpatialReference",  
  27.                     "esri/geometry/Point",  
  28.                     "esri/geometry/Polygon",  
  29.                     "esri/geometry/Polyline",  
  30.                     "esri/geometry/Extent",  
  31.                     "esri/geometry/ScreenPoint",  
  32.                     "esri/layers/GraphicsLayer",  
  33.                     "esri/symbols/SimpleLineSymbol",  
  34.                     "esri/symbols/SimpleFillSymbol",  
  35.                     "esri/symbols/TextSymbol",  
  36.                     "esri/renderers/ClassBreaksRenderer",  
  37.                     "esri/graphic",  
  38.                     "esri/Color",  
  39.                     "esri/toolbars/draw",  
  40.                     "dojo/_base/connect",  
  41.                     "dojo/domReady!"  
  42.                 ],  
  43.                 function(Map, SpatialReference, Point, Polygon, Polyline, Extent, ScreenPoint, GraphicsLayer, SimpleLineSymbol, SimpleFillSymbol, TextSymbol, ClassBreaksRenderer, Graphic, Color, DrawTool, connect) {  
  44.                     map = new Map("map", {  
  45.                         zoom: 10,  
  46.                         force3DTransforms: true,  
  47.                         basemap: "national-geographic"  
  48.   
  49.                     });  
  50.                     //设置地图坐标系类型  
  51.                     var spatialReference = new SpatialReference(102100);  
  52.                     map.spatialReference = spatialReference;  
  53.                     //中心基于地图位置  
  54.                     map.centerAt(new Point(13366465, 3705414, new SpatialReference(102100)));  
  55.                     //创建图层  
  56.                     graphicLayer = new GraphicsLayer();  
  57.                     //把图层添加到地图上  
  58.                     map.addLayer(graphicLayer);  
  59.                     addMarker(13366465, 3705414);  
  60.                     map.on("click", function(e) {  
  61.                         addMarker(e.mapPoint.x, e.mapPoint.y);  
  62.                     });  
  63.                     map.showZoomSlider();  
  64.                 });  
  65.   
  66.             function addMarker(xx, yy) {  
  67.   
  68.                 //设置标注的经纬度  
  69.                 var pt = new esri.geometry.Point(xx, yy, map.spatialReference);  
  70.                 var symbol1 = new esri.symbol.PictureMarkerSymbol("images/site.png", 25, 25);  
  71.   
  72.                 //要在模版中显示的参数  
  73.                 var attr = {  
  74.                     "address": "山东省淄博市张店区"  
  75.                 };  
  76.   
  77.                 //创建模版  
  78.                 var infoTemplate = new esri.InfoTemplate("标题", "地址:${address}");  
  79.                 //创建图像  
  80.                 var graphic = new esri.Graphic(pt, symbol1, attr, infoTemplate);  
  81.                 //把图像添加到刚才创建的图层上  
  82.                 graphicLayer.add(graphic);  
  83.                 setMapCenter(xx, yy, map.getLevel());  
  84.             }  
  85.   
  86.             function setMapCenter(xx, yy, level) {  
  87.                 var point = new esri.geometry.Point(xx, yy, map.spatialReference);  
  88.                 map.centerAndZoom(point, level);  
  89.             }  
  90.         </script>  
  91.     </head>  
  92.   
  93.     <body>  
  94.         <div id="map" style="z-index:0;">  
  95.   
  96.         </div>  
  97.     </body>  
  98.   
  99. </html> 
0 0
原创粉丝点击