ArcGIS 在地图上添加标注

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="http://192.168.1.205:810/arcgis_js_api/library/3.9/3.9/js/dojo/dijit/themes/tundra/tundra.css"/>
    <link rel="stylesheet" type="text/css" href="http://192.168.1.205:810/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css" />
    <script type="text/javascript" src="http://192.168.1.205:810/arcgis_js_api/library/3.9/3.9/init.js"></script>
    <script type="text/javascript" src="dojo/jsapi_vsdoc10_v38.js"></script>
    <script type="text/javascript">
        dojo.require("esri.map");
        dojo.ready(function () {
            var MyMap = new esri.Map("MyMapDiv");
            var myTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://XXX/ArcGIS/rest/services/20130610_1454/MapServer");
            var point = new esri.geometry.Point(118.0605760000, 36.8424320000, MyMap.spatialReference);
            //地图首次加载显示的位置和放大级别
            MyMap.centerAndZoom(point, 8);
            MyMap.addLayer(myTiledMapServiceLayer);

            //创建图层
            var graphicLayer = new esri.layers.GraphicsLayer();
            //把图层添加到地图上
            MyMap.addLayer(graphicLayer);

            //设置标注的经纬度
            //方法一
            var pt = new esri.geometry.Point(118.0605760000, 36.8424320000, MyMap.spatialReference);
            //方法二
            //  var pt = new esri.geometry.geographicToWebMercator(new esri.geometry.Point({
            //    "x": 118.0605760000,
            //    "y": 36.8424320000,
            //    "spatialReference": { "wkid": 102113 }
            //            }));

            //设置标注显示的图标
            //var symbol = new esri.symbol.SimpleMarkerSymbol();
            var symbol = new esri.symbol.PictureMarkerSymbol("images/red.png", 25, 25);

            //要在模版中显示的参数
            var attr = { "address": "山东省淄博市张店区" };

            //创建模版
            var infoTemplate = new esri.InfoTemplate("标题", "地址:${address}");
            //创建图像
            var graphic = new esri.Graphic(pt, symbol, attr, infoTemplate);
            //把图像添加到刚才创建的图层上
            graphicLayer.add(graphic);

            //注册事件,注意事件名大小写敏感
            //鼠标在地图上移动地图坐标的事件
            dojo.connect(MyMap, "onMouseMove", showCoordinates);
            //鼠标按下后,拖动地图显示坐标的事件
            dojo.connect(MyMap, "onMouseDrag", showCoordinates);
        });

        //显示地图坐标
        function showCoordinates(evt)
        {
            var mp = evt.mapPoint;
            dojo.byId("info").innerHTML = "坐标:" + mp.x + " , " + mp.y;
        }
    </script>
</head>
<body>
<div id="MyMapDiv" style=" width:600px; height:500px; border:1px solid #000" class="MapClass"></div>
<p id="info"></p>
</body>
</html>

 

posted @ 2014-09-28 15:02  Liu66~  阅读(19318)  评论(0编辑  收藏  举报