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 相关文章推荐
Javascript !!的作用
Dec 04 Javascript
jQuery EasyUI API 中文文档 - ValidateBox验证框
Oct 06 Javascript
学习从实践开始之jQuery插件开发 菜单插件开发
May 03 Javascript
jquery Mobile入门—外部链接切换示例代码
Jan 08 Javascript
中止javascript执行的方法
Feb 14 Javascript
jQuery学习笔记之jQuery中的$
Jan 19 Javascript
Node.js刷新session过期时间的实现方法推荐
May 18 Javascript
[原创]jquery判断元素内容是否为空的方法
May 04 jQuery
详解JavaScript 中 if / if...else...替换方式
Jul 15 Javascript
微信小程序实现元素渐入渐出动画效果封装方法
May 18 Javascript
Vue程序调试的方法
Jun 17 Javascript
js实现无缝轮播图插件封装
Jul 31 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
Ping服务的php实现方法,让网站快速被收录
2012/02/04 PHP
PHP代码维护,重构变困难的4种原因分析
2016/01/25 PHP
php实现常见图片格式的水印和缩略图制作(面向对象)
2016/06/15 PHP
功能强大的PHP POST提交数据类
2016/07/15 PHP
php版微信公众平台开发之验证步骤实例详解
2016/09/23 PHP
PHP数组实际占用内存大小原理解析
2020/12/11 PHP
屏蔽鼠标右键、Ctrl+n、shift+F10、F5刷新、退格键 的javascript代码
2007/04/01 Javascript
讨论javascript(一)工厂方式 js面象对象的定义方法
2009/12/15 Javascript
jQuery+jqmodal弹出窗口实现代码分明
2010/06/14 Javascript
40款非常棒的jQuery 插件和制作教程(系列一)
2011/10/26 Javascript
使用js声明数组,对象在jsp页面中(获得ajax得到json数据)
2013/11/05 Javascript
Javascript数组与字典用法分析
2014/12/13 Javascript
JavaScript中Cookie操作实例
2015/01/09 Javascript
JavaScript数组的栈方法与队列方法详解
2016/05/26 Javascript
微信小程序中吸底按钮适配iPhone X方案
2017/11/29 Javascript
vue favicon设置以及动态修改favicon的方法
2018/12/21 Javascript
ios中视频的最后一桢问题解决
2019/05/14 Javascript
[15:35]教你分分钟做大人:天怒法师
2014/10/30 DOTA
Python模拟百度登录实例详解
2016/01/20 Python
Python简单检测文本类型的2种方法【基于文件头及cchardet库】
2016/09/18 Python
python http基本验证方法
2018/12/26 Python
使用python画社交网络图实例代码
2019/07/10 Python
django自带serializers序列化返回指定字段的方法
2019/08/21 Python
python RC4加密操作示例【测试可用】
2019/09/26 Python
基于python实现查询ip地址来源
2020/06/02 Python
Pytorch mask-rcnn 实现细节分享
2020/06/24 Python
用Python自动清理电脑内重复文件,只要10行代码(自动脚本)
2021/01/09 Python
详解CSS3+JS完美实现放大镜模式
2020/12/03 HTML / CSS
加拿大女包品牌:Matt & Nat
2017/05/12 全球购物
英国最大的美妆产品在线零售商之一:Beauty Bay
2017/09/29 全球购物
一个精品风格的世界:Atterley
2019/05/01 全球购物
编程实现去掉XML的重复结点
2014/05/28 面试题
写求职信有什么意义
2014/02/17 职场文书
聚美优品广告词改编
2014/03/14 职场文书
CSS3中Animation实现简单的手指点击动画的示例
2021/07/15 HTML / CSS
Mysql 一主多从的部署
2022/05/20 MySQL