SOSO地圖API使用(一)在地圖上畫(huà)圓實(shí)現(xiàn)思路與代碼
前言:最近在做SOSO地圖相關(guān)開(kāi)發(fā),遇到相關(guān)畫(huà)圓知識(shí),特此簡(jiǎn)單記錄下來(lái)。
1.在頁(yè)面中添加SOSO地圖API引用,引用腳本:
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>;
2.新建一個(gè)地圖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.創(chuàng)建一個(gè)圓形對(duì)象:
var circle=new soso.maps.Circle({
map:map,
center:center,
radius:1000,
fillColor:"#00f",
fillOpacity:0.3,
strokeWeight:2
});
5.為了美觀,再給圓形設(shè)置一個(gè)中心點(diǎn),代碼如下:
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//用來(lái)指定圖標(biāo)的錨點(diǎn),默認(rèn)為圖標(biāo)中心的位置,可以指定圖標(biāo)的位置,默認(rèn)是和圖片的左上角對(duì)齊的。
, new soso.maps.Point(0, 0)//指定使用圖片的哪一部分,相對(duì)圖片左上角的像素坐標(biāo)
, 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.完成上面的編碼后,得到一個(gè)如下圖樣子的圓形

<!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//用來(lái)指定圖標(biāo)的錨點(diǎn),默認(rèn)為圖標(biāo)中心的位置
, new soso.maps.Point(0, 0)//指定使用圖片的哪一部分,相對(duì)圖片左上角的像素坐標(biāo)
, 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>
相關(guān)文章
微信小程序搜索框樣式并實(shí)現(xiàn)跳轉(zhuǎn)到搜索頁(yè)面(小程序搜索功能)
這篇文章主要介紹了微信小程序搜索框樣式并實(shí)現(xiàn)跳轉(zhuǎn)到搜索頁(yè)面(小程序搜索功能),需要的朋友可以參考下2020-03-03js處理php輸出時(shí)間戳對(duì)不上號(hào)的解決方法
JS時(shí)間戳為13位,包含3位毫秒的,而PHP只有10位不包含毫秒的,這就是為什么對(duì)不上號(hào)原因,處理方法如下2014-06-06css值轉(zhuǎn)換成數(shù)值請(qǐng)拋棄parseInt
絕大多數(shù)人喜歡用parseInt()把css中的字符串值轉(zhuǎn)換成數(shù)值2011-10-10基于Bootstrap框架實(shí)現(xiàn)圖片切換
這篇文章主要介紹了基于Bootstrap框架實(shí)現(xiàn)圖片切換的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03Js之軟鍵盤(pán)實(shí)現(xiàn)(js源碼)
Js之軟鍵盤(pán)實(shí)現(xiàn)(js源碼)...2007-01-01JavaScript實(shí)現(xiàn)彈窗效果代碼分析
本文主要介紹了JavaScript實(shí)現(xiàn)彈窗效果的代碼分析,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-03-03