SOSO地圖API使用(一)在地圖上畫圓實現思路與代碼

來源:互聯網
上載者:User

前言:最近在做SOSO地圖相關開發,遇到相關畫圓知識,特此簡單記錄下來。
1.在頁面中添加SOSO地圖API引用,引用指令碼

複製代碼 代碼如下:<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>;

2.建立一個地圖DIV容器,如下複製代碼 代碼如下:<div style="width:603px;height:300px" id="container"></div>

3.初始化地圖複製代碼 代碼如下: var center=new soso.maps.LatLng(22.540551,113.934593);
var map=new soso.maps.Map(document.getElementById("container"),{
center:center,
zoomLevel:14
});

4.建立一個圓形對象複製代碼 代碼如下: var circle=new soso.maps.Circle({
map:map,
center:center,
radius:1000,
fillColor:"#00f",
fillOpacity:0.3,
strokeWeight:2
});

5.為了美觀,再給圓形設定一個中心點,代碼如下複製代碼 代碼如下: var marker = new soso.maps.Marker({
position: center,
map: map
});
var anchor = new soso.maps.Point(0, 0),
size = new soso.maps.Size(27, 35),
icon = new soso.maps.MarkerImage('http://s.map.soso.com/themes/default/img/centermarker.png'
, size//指定使用圖片部分的大小
, anchor//用來指定表徵圖的錨點,預設為表徵圖中心的位置,可以指定表徵圖的位置,預設是和圖片的左上方對齊的。
, new soso.maps.Point(0, 0)//指定使用圖片的哪一部分,相對圖片左上方的像素座標
, new soso.maps.Size(27, 35)//指定圖片的原始大小
, new soso.maps.Size(-12, -30));//向左偏12px,向上偏30px
marker.setIcon(icon);
var decor = new soso.maps.MarkerDecoration({
content: '',
margin: new soso.maps.Size(0, -4),
align: soso.maps.ALIGN.CENTER,
marker: marker
});

6.完成上面的編碼後,得到一個如樣子的圓形
7.具體代碼如下複製代碼 代碼如下: <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SOSOMap</title>
<style type="text/css">
*{
margin:0px;
padding:0px;
}
body, button, input, select, textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
#info{
width:603px;
padding-top:3px;
overflow:hidden;
}
.btn{
width:190px;
}
</style>
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>
<script type="text/javascript">
function init(){
var center=new soso.maps.LatLng(22.540551,113.934593);
var map=new soso.maps.Map(document.getElementById("container"),{
center:center,
zoomLevel:14
});
var circle=new soso.maps.Circle({
map:map,
center:center,
radius:1000,
fillColor:"#00f",
fillOpacity:0.3,
strokeWeight:2
});
var marker = new soso.maps.Marker({
position: center,
map: map
});
var anchor = new soso.maps.Point(0, 0),
size = new soso.maps.Size(27, 35),
icon = new soso.maps.MarkerImage('http://s.map.soso.com/themes/default/img/centermarker.png'
, size//指定使用圖片部分的大小
, anchor//用來指定表徵圖的錨點,預設為表徵圖中心的位置
, new soso.maps.Point(0, 0)//指定使用圖片的哪一部分,相對圖片左上方的像素座標
, new soso.maps.Size(27, 35)//指定圖片的原始大小
, new soso.maps.Size(-12, -30));//向左偏12px,向上偏30px
marker.setIcon(icon);
var decor = new soso.maps.MarkerDecoration({
content: '',
margin: new soso.maps.Size(0, -4),
align: soso.maps.ALIGN.CENTER,
marker: marker
});
var path1=[
center
];
var polyline = new soso.maps.Polyline({
path: path1,
strokeColor: '#000000',
strokeWeight: 5,
strokeOpacity: 1,
editable:false,
map: map
});
/*
soso.maps.Event.addListener(map,'zoomlevel_changed',function() {
circle.setMap(null);console.log(map);
circle.setMap(map);
});
*/
}
window.onload=init;
</script>
</head>
<body onload="init()">
<div style="width:603px;height:300px" id="container"></div>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.