SOSO地图API使用(一)在地图上画圆实现思路与代码


Posted in Javascript onJanuary 15, 2013

前言:最近在做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.完成上面的编码后,得到一个如下图样子的圆形
SOSO地图API使用(一)在地图上画圆实现思路与代码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>
Javascript 相关文章推荐
pjblog中的UBBCode.js
Apr 25 Javascript
通过url查找a元素并点击
Apr 09 Javascript
angularjs自定义ng-model标签的属性
Jan 21 Javascript
前端性能优化及技巧
May 06 Javascript
prototype与__proto__区别详细介绍
Jan 09 Javascript
vue.js+Element实现表格里的增删改查
Jan 18 Javascript
node.js 核心http模块,起一个服务器,返回一个页面的实例
Sep 11 Javascript
JavaScript中利用Array filter() 方法压缩稀疏数组
Feb 24 Javascript
如何提升vue.js中大型数据的性能
Jun 21 Javascript
vue.js 2.0实现简单分页效果
Jul 29 Javascript
layer弹出层扩展主题的方法
Sep 11 Javascript
vue-cli单页面预渲染seo-prerender-spa-plugin操作
Aug 10 Javascript
script的async属性以非阻塞的模式加载脚本
Jan 15 #Javascript
javascript真的不难-回顾一下基础知识
Jan 15 #Javascript
jQuery使用动态渲染表单功能完成ajax文件下载
Jan 15 #Javascript
jsvascript图像处理—(计算机视觉应用)图像金字塔
Jan 15 #Javascript
使用Post提交时须将空格转换成加号的解释
Jan 14 #Javascript
javascript函数以及基础写法100多条实用整理
Jan 13 #Javascript
window.requestAnimationFrame是什么意思,怎么用
Jan 13 #Javascript
You might like
PHP和Shell实现检查SAMBA与NFS Server是否存在
2015/01/07 PHP
PHP简单实现图片格式转换(jpg转png,gif转png等)
2019/10/30 PHP
prototype 1.5相关知识及他人笔记
2006/12/16 Javascript
javascript写的日历类(基于pj)
2010/12/28 Javascript
一个基于jQuery的树型插件(OrangeTree)使用介绍
2012/05/03 Javascript
同时使用n个window onload加载实例介绍
2013/04/25 Javascript
js使浏览器窗口最大化实现代码(适用于IE)
2013/08/07 Javascript
javascript模拟枚举的简单实例
2014/03/06 Javascript
JS判断字符串长度的5个方法(区分中文和英文)
2014/03/18 Javascript
JavaScript异步编程Promise模式的6个特性
2014/04/03 Javascript
javascript实现表格排序 编辑 拖拽 缩放
2015/01/02 Javascript
js获取当前年月日-YYYYmmDD格式的实现代码
2016/06/01 Javascript
HTML Table 空白单元格补全的简单实现
2016/10/13 Javascript
基于Javascript倒计时效果
2016/12/22 Javascript
JS Select下拉框(支持输入模糊查询)
2017/02/04 Javascript
jquery平滑滚动到顶部插件使用详解
2017/05/08 jQuery
JQuery Ajax动态加载Table数据的实例讲解
2018/08/09 jQuery
JavaScript Math对象和调试程序的方法分析
2019/05/13 Javascript
layui加载表格,绑定新增,编辑删除,查看按钮事件的例子
2019/09/06 Javascript
[03:55]2014DOTA2国际邀请赛 Fnatic经理采访赢DK在情理之中
2014/07/10 DOTA
[00:35]DOTA2上海特级锦标赛 Newbee战队宣传片
2016/03/03 DOTA
python编程实现希尔排序
2017/04/13 Python
python机器学习实战之树回归详解
2017/12/20 Python
Python自定义装饰器原理与用法实例分析
2018/07/16 Python
python模块导入的细节详解
2018/12/10 Python
Pandas统计重复的列里面的值方法
2019/01/30 Python
python之pyqt5通过按钮改变Label的背景颜色方法
2019/06/13 Python
俄罗斯小米家用电器、电子产品和智能家居商店:Poood.ru
2020/04/03 全球购物
教学个人的自我评价分享
2014/02/16 职场文书
主要负责人任命书
2014/06/06 职场文书
职工小家建设活动方案
2014/08/25 职场文书
2014年英语教师工作总结
2014/12/03 职场文书
庆祝教师节活动总结
2015/03/23 职场文书
安全教育主题班会教案
2015/08/12 职场文书
小学英语教学经验交流材料
2015/11/02 职场文书
教你怎么用Python处理excel实现自动化办公
2021/04/30 Python