SOSO地图API使用(一)在地图上画圆实现思路与代码
时间:2024-04-10 13:54:07
前言:最近在做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>
标签:soso地图api,画圆
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
js中函数声明与函数表达式
2024-04-25 13:08:35
使用Python读写及压缩和解压缩文件的示例
2023-08-30 17:42:52
Oracle的默认用户密码
2012-07-11 15:29:22
pip和pygal的安装实例教程 <font color=red>原创</font>
2021-05-22 18:35:30
![](https://img.aspxhome.com/file/2023/9/97589_0s.png)
Python中的Selenium异常处理
2021-08-28 04:15:23
![](https://img.aspxhome.com/file/2023/4/72264_0s.png)
Python lambda表达式用法实例分析
2022-06-05 12:32:34
图文详解Python中最神秘的一个魔法函数
2022-03-25 05:44:24
![](https://img.aspxhome.com/file/2023/7/104937_0s.jpg)
Mootools常用方法扩展(五)
2009-03-03 12:12:00
python3新特性函数注释Function Annotations用法分析
2023-08-09 20:15:29
python模块如何查看
2021-10-26 20:08:35
True or False,明明白白你的If语句流程
2008-01-25 19:00:00
深入理解JS的事件绑定、事件流模型
2024-04-22 22:44:44
![](https://img.aspxhome.com/file/2023/1/135561_0s.png)
利用Python实现简单的Excel统计函数
2021-09-27 09:21:09
![](https://img.aspxhome.com/file/2023/2/110072_0s.png)
python+appium自动化测试之如何控制App的启动和退出
2023-06-24 12:45:01
![](https://img.aspxhome.com/file/2023/0/82910_0s.jpg)
微信公众平台实现获取用户OpenID的方法
2023-11-17 05:55:56
基于np.arange与np.linspace细微区别(数据溢出问题)
2021-08-29 23:46:25
![](https://img.aspxhome.com/file/2023/0/115870_0s.png)
Python数据结构之图的应用示例
2021-06-02 21:59:27
![](https://img.aspxhome.com/file/2023/1/107801_0s.png)
Python sqlite3事务处理方法实例分析
2022-12-28 07:30:09
Python爬虫之线程池的使用
2021-04-08 20:01:01
![](https://img.aspxhome.com/file/2023/0/135130_0s.png)
关于keras多任务多loss回传的思考
2023-09-16 18:58:47
![](https://img.aspxhome.com/file/2023/5/83795_0s.png)