来自 澳门新葡亰 2019-09-29 09:32 的文章
当前位置: 澳门新葡亰app > 澳门新葡亰 > 正文

澳门新葡亰app地图的初始化,地图的初始化

地图的初始化
1、添加引用地图的API文件: <script src="" type="text/javascript"></script>
2、网站初始化加载事件: window.onload = function () { var map = new sogou.maps.Map(document.getElementById("map_canvas"), {}); }
创建一个id为map_canvas的div,自定义div样式,网站运行时地图自动加载;

地图的初始化
1、添加引用地图的API文件: <script src="" type="text/javascript"></script>
2、网站初始化加载事件: window.onload = function () { var map = new sogou.maps.Map(document.getElementById("map_canvas"), {}); }
创建一个id为map_canvas的div,自定义div样式,网站运行时地图自动加载;

具体代码如下

具体代码如下

澳门新葡亰官网APP 1澳门新葡亰官网APP 2

澳门新葡亰官网APP 3澳门新葡亰官网APP 4

<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <style type="text/css">html {height: auto;}body {height: auto;margin: 0;padding: 0;}#map_canvas {width:1000px;height: 500px;position: absolute;}@media print {#map_canvas {height: 950px;}}</style>    <script src="http://api.go2map.com/maps/js/api_v2.5.1.js" type="text/javascript"></script>    <script>        window.onload = function () {            var map = new sogou.maps.Map(document.getElementById("map_canvas"), {});        }     </script></head><body>    <form id="form1" runat="server">    <div id="map_canvas"></div>    </form></body></html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
html {height: auto;}
body {height: auto;margin: 0;padding: 0;}
#map_canvas {width:1000px;height: 500px;position: absolute;}
@media print {#map_canvas {height: 950px;}}
</style>

    <script src="http://api.go2map.com/maps/js/api_v2.5.1.js" type="text/javascript"></script>
    <script>
        window.onload = function () {
            var map = new sogou.maps.Map(document.getElementById("map_canvas"), {});

        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="map_canvas"></div>
    </form>
</body>
</html>

View Code

View Code

指定显示莫城市地图

指定显示莫城市地图

关键代码:

关键代码:

澳门新葡亰官网APP 5澳门新葡亰官网APP 6

澳门新葡亰官网APP 7澳门新葡亰官网APP 8

 window.onload = function () {  var myOptions = { zoom: 10,center: new sogou.maps.Point(12956000, 4824875) };//城市坐标,本坐标为北京坐标 var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);  } 
 window.onload = function () { 
 var myOptions = { zoom: 10,center: new sogou.maps.Point(12956000, 4824875) };//城市坐标,本坐标为北京坐标
 var map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions); 
 } 

澳门新葡亰官网APP,View Code

View Code

地图属性了解

地图属性了解

列举一下常用的一些属性比如:地图的移动、地图类型转换、跳转到指定城市

列举一下常用的一些属性比如:地图的移动、地图类型转换、跳转到指定城市

具体代码如下

澳门新葡亰app,具体代码如下

澳门新葡亰官网APP 9澳门新葡亰官网APP 10

澳门新葡亰官网APP 11澳门新葡亰官网APP 12

<html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title></title>    <style type="text/css">html {height: auto;}body {height: auto;margin: 0;padding: 0;}#map_canvas {width:1000px;height: 500px;position: absolute;}@media print {#map_canvas {height: 950px;}}</style>    <script src="http://api.go2map.com/maps/js/api_v2.5.1.js" type="text/javascript"></script>    <script>        var map;//创建全局变量               window.onload = function () {             var myOptions = { zoom: 10, center: new sogou.maps.Point(12956000, 4824875) };//指定城市            map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);//创建地图         }              //setMapTypeId方法示例        function setMapTypeId {             //设置地图类型,如:            //sogou.maps.MapTypeId.ROADMAP 普通地图            //sogou.maps.MapTypeId.SATELLITE 卫星地图            //sogou.maps.MapTypeId.HYBRID 卫星和路网混合地图            //map.setMapTypeId(sogou.maps.MapTypeId.HYBRID)            switch  {                case 1: map.setMapTypeId(sogou.maps.MapTypeId.ROADMAP); break; //普通地图                case 2: map.setMapTypeId(sogou.maps.MapTypeId.SATELLITE); break; //卫星地图                case 3: map.setMapTypeId(sogou.maps.MapTypeId.HYBRID); break; //卫星和路网混合地图            }        }        //panBy方法示例地图手动移动        function panBy {            map.panBy        }        //setOptions方法示例显示指定地区        function setOptions() {            //同时设置地图中心、级别、类型            map.setOptions({ center: new sogou.maps.Point(13522000, 3641093), zoom: 12, mapTypeId: sogou.maps.MapTypeId.ROADMAP })        }        //setCenter方法示例 显示指定的地区 a、b为地图坐标,C为地图级别        function setCenter {            map.setCenter(new sogou.maps.Point        }        //fitBounds方法示例 跳转到指定的范围内        function fitBounds() {            //设置一个故宫附近的范围            var bounds = new sogou.maps.Bounds(12955101, 4824738, 12958355, 4827449);            //将地图设置为可全部显示这个范围            //注:不是设置bounds为这个值,而是调整到合适的位置            map.fitBounds        }    </script></head><body>    <form id="form1" runat="server">    <input value="普通地图" onclick="setMapTypeId"  type="button"/>    <input value="卫星地图" onclick="setMapTypeId" type="button"/>    <input value="卫星和路网混合地图" onclick="setMapTypeId" type="button"/>    <input value="向左移动" onclick="panBy" type="button"/>    <input value="向右移动" onclick="panBy" type="button"/>    <input value="向上移动" onclick="panBy" type="button"/>    <input value="向下移动" onclick="panBy" type="button"/>    <input value="向左上移动" onclick="panBy" type="button"/>     <input value="上海" onclick="setOptions()" type="button"/>    <input value="天津" onclick="setCenter(13046000,4714250,10)" type="button"/>      <input value="故宫" onclick="fitBounds()" type="button"/>    <div id="map_canvas" ></div>    </form></body></html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
html {height: auto;}
body {height: auto;margin: 0;padding: 0;}
#map_canvas {width:1000px;height: 500px;position: absolute;}
@media print {#map_canvas {height: 950px;}}
</style>

    <script src="http://api.go2map.com/maps/js/api_v2.5.1.js" type="text/javascript"></script>
    <script>
        var map;//创建全局变量

        window.onload = function () { 
            var myOptions = { zoom: 10, center: new sogou.maps.Point(12956000, 4824875) };//指定城市
            map = new sogou.maps.Map(document.getElementById("map_canvas"), myOptions);//创建地图 

        }


         //setMapTypeId方法示例
        function setMapTypeId(num) { 
            //设置地图类型,如:
            //sogou.maps.MapTypeId.ROADMAP 普通地图
            //sogou.maps.MapTypeId.SATELLITE 卫星地图
            //sogou.maps.MapTypeId.HYBRID 卫星和路网混合地图
            //map.setMapTypeId(sogou.maps.MapTypeId.HYBRID)
            switch (num) {
                case 1: map.setMapTypeId(sogou.maps.MapTypeId.ROADMAP); break; //普通地图
                case 2: map.setMapTypeId(sogou.maps.MapTypeId.SATELLITE); break; //卫星地图
                case 3: map.setMapTypeId(sogou.maps.MapTypeId.HYBRID); break; //卫星和路网混合地图
            }
        }
        //panBy方法示例地图手动移动
        function panBy(a, b) {
            map.panBy(a, b)
        }
        //setOptions方法示例显示指定地区
        function setOptions() {
            //同时设置地图中心、级别、类型
            map.setOptions({ center: new sogou.maps.Point(13522000, 3641093), zoom: 12, mapTypeId: sogou.maps.MapTypeId.ROADMAP })
        }
        //setCenter方法示例 显示指定的地区 a、b为地图坐标,C为地图级别
        function setCenter(a, b, c) {
            map.setCenter(new sogou.maps.Point(a, b), c)
        }
        //fitBounds方法示例 跳转到指定的范围内
        function fitBounds() {
            //设置一个故宫附近的范围
            var bounds = new sogou.maps.Bounds(12955101, 4824738, 12958355, 4827449);
            //将地图设置为可全部显示这个范围
            //注:不是设置bounds为这个值,而是调整到合适的位置
            map.fitBounds(bounds)
        }



    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input value="普通地图" onclick="setMapTypeId(1)"  type="button"/>
    <input value="卫星地图" onclick="setMapTypeId(2)" type="button"/>
    <input value="卫星和路网混合地图" onclick="setMapTypeId(3)" type="button"/>
    <input value="向左移动" onclick="panBy(200,0)" type="button"/>
    <input value="向右移动" onclick="panBy(-200,0)" type="button"/>
    <input value="向上移动" onclick="panBy(0,200)" type="button"/>
    <input value="向下移动" onclick="panBy(0,-200)" type="button"/>
    <input value="向左上移动" onclick="panBy(200,200)" type="button"/> 
    <input value="上海" onclick="setOptions()" type="button"/>
    <input value="天津" onclick="setCenter(13046000,4714250,10)" type="button"/>
      <input value="故宫" onclick="fitBounds()" type="button"/>
    <div id="map_canvas" ></div>
    </form>
</body>
</html>

View Code

View Code

地图描点属性

 地图描点属性

地图上很重要的属性,给地图添加描点,是常用的方法属性,

地图上很重要的属性,给地图添加描点,是常用的方法属性,

搜狗API提供两种描点填写形式默认描点和动态添加描点

搜狗API提供两种描点填写形式默认描点和动态添加描点

默认描点添加:

默认描点添加:

澳门新葡亰官网APP 13澳门新葡亰官网APP 14

澳门新葡亰官网APP 15澳门新葡亰官网APP 16

  var location = new sogou.maps.Point(12956000, 4824875); //指定描点位置var map = new sogou.maps.Map(document.getElementById("map_canvas"), {});//初始化地图 var marker = new sogou.maps.Marker({                position: location,//描点坐标                title: "描点",//描点名称                label: { visible: true, align: "BOTTOM" },//描点显示形式                map: map,             });//添加描点到地图
  var location = new sogou.maps.Point(12956000, 4824875); //指定描点位置
var map = new sogou.maps.Map(document.getElementById("map_canvas"), {});//初始化地图
 var marker = new sogou.maps.Marker({
                position: location,//描点坐标
                title: "描点",//描点名称
                label: { visible: true, align: "BOTTOM" },//描点显示形式
                map: map, 
            });//添加描点到地图

View Code

View Code

动态描点添加

动态描点添加

澳门新葡亰官网APP 17澳门新葡亰官网APP 18

澳门新葡亰官网APP 19澳门新葡亰官网APP 20

  window.onload = function () {         //初始化地图            map = new sogou.maps.Map(document.getElementById("map_canvas"), {});//为地图添加点击事件 sogou.maps.event.addListener(map, 'click', function (event) {                var marker1 = new sogou.maps.Marker({                position: event.point,                 map: map            });            });         }
  window.onload = function () { 
        //初始化地图
            map = new sogou.maps.Map(document.getElementById("map_canvas"), {});
//为地图添加点击事件
 sogou.maps.event.addListener(map, 'click', function (event) {
                var marker1 = new sogou.maps.Marker({
                position: event.point, 
                map: map
            });
            }); 
        }

View Code

View Code

根据两描点测距

根据两描点测距

澳门新葡亰官网APP 21澳门新葡亰官网APP 22

澳门新葡亰官网APP 23澳门新葡亰官网APP 24

//获取类的唯一示例        function getInstance {            a.hasOwnProperty("_instance") || (a._instance = new a);            return a._instance        } //两点相连        function Lines(myLatlng, myPoint) {             var convertor = getInstance(sogou.maps.Convertor);            var distance = convertor.distance(myLatlng, myPoint);            //两点链接            var line = new sogou.maps.Polyline({                path: [myLatlng, myPoint],                strokeColor: "#FF0000",                strokeOpacity: 1.0,                strokeWeight: 1,                title: parseInt + "米",                map: map            });         }
//获取类的唯一示例
        function getInstance(a) {
            a.hasOwnProperty("_instance") || (a._instance = new a);
            return a._instance
        }
 //两点相连
        function Lines(myLatlng, myPoint) { 
            var convertor = getInstance(sogou.maps.Convertor);
            var distance = convertor.distance(myLatlng, myPoint);
            //两点链接
            var line = new sogou.maps.Polyline({
                path: [myLatlng, myPoint],
                strokeColor: "#FF0000",
                strokeOpacity: 1.0,
                strokeWeight: 1,
                title: parseInt(distance) + "米",
                map: map
            }); 
        }

View Code

View Code

根据上述属性做了一个小的模块,地图上动态测距代码如下:

根据上述属性做了一个小的模块,地图上动态测距代码如下:

澳门新葡亰官网APP 25澳门新葡亰官网APP 26

澳门新葡亰官网APP 27澳门新葡亰官网APP 28

<html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title></title>    <style type="text/css">html {height: auto;}body {height: auto;margin: 0;padding: 0;}#map_canvas {width:1000px;height: 500px;position: absolute;}@media print {#map_canvas {height: 950px;}}</style>    <script src="http://api.go2map.com/maps/js/api_v2.5.1.js" type="text/javascript"></script>    <script>        var map;var num;var Listener;        //获取类的唯一示例        function getInstance {            a.hasOwnProperty("_instance") || (a._instance = new a);            return a._instance        }        window.onload = function () {         //初始化地图            map = new sogou.maps.Map(document.getElementById("map_canvas"), {});         }        function AddCj() {            var mypointh; var myPoint;            num = 0;            //为地图添加点击事件、点击后显示当前坐标并添加点击描点            Listener = sogou.maps.event.addListener(map, 'click', function (event) {                if (num == 0) {                    mypointh = myPoint = event.point; //获取点击位置的坐标                  }                else {                    myPoint = mypointh;                    mypointh = event.point; //获取点击位置的坐标                  }                Lines(mypointh, myPoint);                num++;            });        }        function DelCj() {            sogou.maps.event.removeListener        }        //两点相连        function Lines(myLatlng, myPoint) {             var convertor = getInstance(sogou.maps.Convertor);            var distance = convertor.distance(myLatlng, myPoint);            //两点链接            var line = new sogou.maps.Polyline({                path: [myLatlng, myPoint],                strokeColor: "#FF0000",                strokeOpacity: 1.0,                strokeWeight: 1,                title: parseInt + "米",                map: map            });            placeMarker(myLatlng, parseInt);        }        //动态添加描点,根据指定的坐标创建描点        function placeMarker(location,jl) {            var clickedLocation = location;            var marker1 = new sogou.maps.Marker({                position: location,                title: jl+"米",                label:{visible:true,align:"BOTTOM"},                map: map            });        }        function Mapclear() {            num = 0;            map.clearAll();        }    </script></head><body>    <form id="form1" runat="server">    <input type="button" value="测距" onclick="AddCj()" />    <input type="button" value="取消测距" onclick="DelCj()" />    <input type="button" value="清空" onclick="Mapclear()" />     <div id="map_canvas" ></div>    </form></body></html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
html {height: auto;}
body {height: auto;margin: 0;padding: 0;}
#map_canvas {width:1000px;height: 500px;position: absolute;}
@media print {#map_canvas {height: 950px;}}
</style>

    <script src="http://api.go2map.com/maps/js/api_v2.5.1.js" type="text/javascript"></script>
    <script>
        var map;var num;var Listener;
        //获取类的唯一示例
        function getInstance(a) {
            a.hasOwnProperty("_instance") || (a._instance = new a);
            return a._instance
        }

        window.onload = function () { 
        //初始化地图
            map = new sogou.maps.Map(document.getElementById("map_canvas"), {}); 
        }
        function AddCj() {
            var mypointh; var myPoint;
            num = 0;
            //为地图添加点击事件、点击后显示当前坐标并添加点击描点
            Listener = sogou.maps.event.addListener(map, 'click', function (event) {
                if (num == 0) {
                    mypointh = myPoint = event.point; //获取点击位置的坐标  
                }
                else {
                    myPoint = mypointh;
                    mypointh = event.point; //获取点击位置的坐标  
                }
                Lines(mypointh, myPoint);
                num++;
            });
        }
        function DelCj() {
            sogou.maps.event.removeListener(Listener)
        }

        //两点相连
        function Lines(myLatlng, myPoint) { 
            var convertor = getInstance(sogou.maps.Convertor);
            var distance = convertor.distance(myLatlng, myPoint);
            //两点链接
            var line = new sogou.maps.Polyline({
                path: [myLatlng, myPoint],
                strokeColor: "#FF0000",
                strokeOpacity: 1.0,
                strokeWeight: 1,
                title: parseInt(distance) + "米",
                map: map
            });
            placeMarker(myLatlng, parseInt(distance));
        }


        //动态添加描点,根据指定的坐标创建描点
        function placeMarker(location,jl) {
            var clickedLocation = location;
            var marker1 = new sogou.maps.Marker({
                position: location,
                title: jl+"米",
                label:{visible:true,align:"BOTTOM"},
                map: map
            });
        }

        function Mapclear() {
            num = 0;
            map.clearAll();
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input type="button" value="测距" onclick="AddCj()" />
    <input type="button" value="取消测距" onclick="DelCj()" />
    <input type="button" value="清空" onclick="Mapclear()" /> 
    <div id="map_canvas" ></div>
    </form>
</body>
</html>

View Code

View Code

 

本文由澳门新葡亰app发布于澳门新葡亰,转载请注明出处:澳门新葡亰app地图的初始化,地图的初始化

关键词: