zoukankan      html  css  js  c++  java
  • Arcgis for Javascript实现两个地图的联动

    今天在看天地图的时候,有一个多时相的地图显示功能,感觉非常好玩。作为技术控的我晚上十点下班到家便是快十一点了,本来应该是睡觉了。可是。激动地心情不能平静,哎,算了,本着不熬夜的程序猿不是好程序猿的原则。熬了会夜最终看到了想要的效果,便迫不及待的拿出来与大家分享,首先看看天地图的效果与我的效果:


    天地图多时相效果

    天地图多时相的链接:http://www.tianditu.cn/multidate/multidate.html?ll=116.38,39.92&l=11


    自己做的效果


    看完了效果,以下说说实现的详细功能。

    1、地图的联动:当地图1(2)的范围发生变化时。地图2(1)的地图也随之发生变化,且地图2(1)与地图1(2)是同样的显示范围。2、鼠标的联动:当鼠标在地图1(2)上移动时,在地图2(1)同样位置显示鼠标指针位置。


    上面,分析了功能,以下说说实现思路。

    1、地图联动:当地图1(2)范围发生变化时,获取地图1(2)的范围。并设置2(1)的范围为地图1(2)的范围;2、鼠标的联动:鼠标在地图1(2)上移动时。获取鼠标的地图点坐标。并在地图2(1)上显示鼠标。


    本实例中实现了地图1到地图2的联动,地图2到地图1的联动还没实现。兴许会继续更新。还望继续关注lzugis CSDN博客,希望给大家带来很多其它的分享。详细的实现代码例如以下:

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
        <title>Simple Map</title>
        <link rel="stylesheet" href="http://localhost/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css">
        <style>
            html, body, #map1,#map2 {
                height: 100%;
                margin: 0;
                padding: 0;
            }
            body {
                background-color: #FFF;
                overflow: hidden;
                font-family: "Trebuchet MS";
            }
            #map1,#map2{
                float:left;
                 49.5%;
            }
            #map1{
                border-right: 2px solid #999;
            }
        </style>
        <script src="http://localhost/arcgis_js_api/library/3.9/3.9/init.js"></script>
        <script>
            var map1,map2;
            require([
                "esri/map",
                "esri/layers/ArcGISTiledMapServiceLayer",
                "esri/layers/GraphicsLayer",
                "esri/graphic",
                "esri/symbols/PictureMarkerSymbol",
                "dojo/domReady!"],
            function(Map, Tiled, GraphicsLayer, Graphic, PictureMarkerSymbol) {
                map1 = new Map("map1",{logo:false});
                map2 = new Map("map2",{logo:false});
                var tiled1 = new Tiled("http://localhost:6080/arcgis/rest/services/chinamap/MapServer");
                var tiled2 = new Tiled("http://localhost:6080/arcgis/rest/services/chinamap/MapServer");
                var mouseLayer = new GraphicsLayer();
                map1.addLayer(tiled1);
                map2.addLayer(tiled2);
                map2.addLayer(mouseLayer);
                map1.setLevel(4);
                map2.setLevel(4);
                map1.on("extent-change",function(){
                    map2.setExtent(map1.extent);
                });
                map1.on("mouse-move",function(evt){
                    mouseLayer.clear();
                    var pms = new PictureMarkerSymbol("cursor.png",22,24);
                    var graphic = new Graphic(evt.mapPoint,pms);
                    mouseLayer.add(graphic);
                });
            });
        </script>
    </head>
    
    <body>
    <div id="map1"></div>
    <div id="map2"></div>
    </body>
    </html>



  • 相关阅读:
    忘记自己的密码了!
    MySQL ('root'@'%') does not exist的问题
    用视觉的差异和统一来表现界面信息(转)
    Localhost 本地mysql启动2013错误(windows系统下)
    修改SQL Server2005 sa密码方法
    .net中禁用TextBox和Input框的粘贴功能
    使用Visual Studio的搜索功能时间简单的代码量统计
    visifire3.6.4 以上版本去水印的办法
    网页设计的配色和排版(转)
    小米科技增设电商业务线,大家注意到没
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6813485.html
Copyright © 2011-2022 走看看