SOSO地图API使用(一)在地图上画圆实现思路与代码
2018-10-12 14:00
447 查看
前言:最近在做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使用(一)在地图上画圆实现思路与代码
- 两行代码搞定iOS自定义HUD风格动画弹窗(支持选择记录) - SKChoosePopView的使用和实现思路
- Android 使用Intent传递数据的实现思路与代码
- 使用phantomjs实现highcharts等报表通过邮件发送(本文仅提供完整解决方案和实现思路,完全照搬不去整理代码无法马上得到效果)
- 春节期间小明使用微信收到很多个红包,非常开心。在查看领取红包记录时发现,某个红包金额出现的次数超过了红包总数的一半。请帮小明找到该红包金额。写出具体算法思路和代码实现,要求算法尽可能高效。
- 使用正则Regex来移除网页的EnableViewState实现思路及代码
- 使用正则Regex来移除网页的EnableViewState实现思路及代码
- 在程序中使用代码打开苹果自带的地图并实现导航
- 春节期间小明使用微信收到很多个红包,非常开心。在查看领取红包记录时发现,某个红包金额出现的次数超过了红包总数的一半。请帮小明找到该红包金额。写出具体算法思路和代码实现,要求算法尽可能高效。
- JS实现的客户端使用的播放器代码
- 使用vb.net代码实现图像水印技术
- ESC之ESC.wsf可以实现javascript的代码压缩附使用方法第1/5页
- 实现验证码控件代码验证控件,方便使用验证码(修改)
- 使用ArcGIS Engine来实现地图的点击查询并闪烁
- 使用ArcGIS Engine来实现地图的点击查询并闪烁
- C#实现使用HTTP管道的.NET远程代码示例
- 市面上所有号称"虚拟机","防火墙"的实时监控杀毒软件无一不是使用的IFSHOOK技术.但是同时也有一些朋友不断写MAIL给我打听如何实现读写的监控.下面给出用VTOOLSD写的代码.也就是所有实时杀毒软件的奥秘.同时,很多拦截文件操作的软件,例如对目录加
- 利用Micro3D和JSR-184使用相同代码实现旋转立方体的效果
- 使用J2ME技术实现简单的动画(附代码实现)
- 使用C#代码实现增加用户帐号