起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1685|回复: 1

[处理中3] 百度地图点聚合

[复制链接]

506

主题

1631

帖子

3387

积分

论坛元老

Rank: 8Rank: 8

积分
3387
QQ
发表于 2018-9-27 16:48:39 | 显示全部楼层 |阅读模式
参考百度地图的点聚合方法,需要引用两个js,我的百度地图异步加载的,这两个js要怎么引才能正常使用点聚合?
  1. <?xml version="1.0" encoding="utf-8"?>

  2. <div xmlns="http://www.w3.org/1999/xhtml" xid="window" class="window" component="$UI/system/components/justep/window/window"
  3.   design="device:m;">  
  4.   <div component="$UI/system/components/justep/model/model" xid="model" onParamsReceive="modelParamsReceive"/>  
  5.   <div id="allmap" style="width:100%;height:200px;"/>  
  6.   <style>body,html,#allmap { width: 100%; height: 100%; overflow: hidden; margin: 0; } #golist { display: none; } @media ( max-device-width : 780px) { #golist { display: block !important; } } .anchorBL{ display:none; } #r-result,#r-result table{ width:100%; }</style>  
  7.   <resource xid="resource">
  8.     <script type="text/javascript" src="http://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js"/>  
  9.     <script type="text/javascript" src="http://api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js"/>
  10.   </resource>
  11. </div>
复制代码


  1. define(function(require) {
  2.         var $ = require("jquery");
  3.         var justep = require("$UI/system/lib/justep");
  4.         var _this, index, map, getLongitude, getLatitude, getProvince, getCity, getParam, getCurrent, firstProvince, currPoint, pointTo;
  5.         var Model = function() {
  6.                 _this = this;
  7.                 index = 0;
  8.                 map = null;
  9.                 getLongitude = null;
  10.                 getLatitude = null;
  11.                 getProvince = null;
  12.                 getCity = null;
  13.                 getParam = null;
  14.                 getCurrent = null;
  15.                 firstProvince = null;
  16.                 currPoint = null;
  17.                 pointTo = null;
  18.                 this.callParent();
  19.         };

  20.         /* 异步加载百度地图 */
  21.         Model.prototype.loadMap = function(event) {
  22.                 window.init = function() {
  23.                         // 创建百度地图实例
  24.                         map = new BMap.Map("allmap", {
  25.                                 enableMapClick : false
  26.                         });

  27.                         // 绘制地图
  28.                         _this.setMap();

  29.                 };

  30.                 // 请求参数中ak为百度地图浏览器端密钥
  31.                 require([ "http://api.map.baidu.com/api?v=2.0&ak=我的秘钥&callback=init" ], function() {
  32.                         if (!(window.BMap && window.BMap.apiLoad)) {
  33.                                 window.init();
  34.                         }
  35.                 });
  36.         };

  37.         /* 绘制地图 */
  38.         Model.prototype.setMap = function() {
  39.                 if (getLongitude && getLatitude)
  40.                         currPoint = new BMap.Point(getLongitude, getLatitude);
  41.                 else {
  42.                         var curr = getCurrent.split(",");
  43.                         currPoint = new BMap.Point(curr[0], curr[1]);
  44.                 }

  45.                 if (pointTo) {
  46.                         var to = pointTo.split(",");
  47.                         var point = new BMap.Point(to[0], to[1]);
  48.                         // 绘制地图
  49.                         map.centerAndZoom(point, 15);
  50.                 } else if (firstProvince && !pointTo) {
  51.                         map.centerAndZoom(currPoint, 15);
  52.                 } else {
  53.                         // 绘制地图
  54.                         map.centerAndZoom(getProvince, 15);
  55.                 }

  56.                 map.setCurrentCity(getProvince);

  57.                 // 右上角、仅包含缩放按钮的控件参数
  58.                 var top_right_navigation = new BMap.NavigationControl({
  59.                         // 控件位置为右上角
  60.                         anchor : BMAP_ANCHOR_TOP_RIGHT,
  61.                         type : BMAP_NAVIGATION_CONTROL_ZOOM
  62.                 // 缩放控件type类型:
  63.                 // BMAP_NAVIGATION_CONTROL_SMALL:仅包含平移和缩放按钮;
  64.                 // BMAP_NAVIGATION_CONTROL_PAN:仅包含平移按钮;
  65.                 // BMAP_NAVIGATION_CONTROL_ZOOM:仅包含缩放按钮 ;
  66.                 });
  67.                 // 添加控件
  68.                 map.addControl(top_right_navigation);
  69.                 // 启用滚轮放大缩小
  70.                 map.enableScrollWheelZoom(true);
  71.                 // 开启拖拽
  72.                 map.enableDragging();

  73.                 // 标注当前地点
  74.                 _this.addCurrent(currPoint);

  75.                 // 标注经销商服务站
  76.                 _this.addMarker();
  77.         };

  78.         /* 标注当前地点 */
  79.         Model.prototype.addCurrent = function(currPoint) {
  80.                 if (currPoint) {
  81.                         var myIcon = new BMap.Icon(require.toUrl("$UI/society/img/current.png"), new BMap.Size(32, 32));
  82.                         var currMark = new BMap.Marker(currPoint, {
  83.                                 icon : myIcon
  84.                         });
  85.                         var opts = {
  86.                                 offset : new BMap.Size(-10, -20)
  87.                         // 设置文本偏移量
  88.                         };
  89.                         var label = new BMap.Label("当前位置", opts); // 创建文本标注对象
  90.                         label.setStyle({
  91.                                 color : "#333333",
  92.                                 borderColor : "#333333",
  93.                                 fontSize : "12px",
  94.                                 height : "20px",
  95.                                 maxWidth : "53px",
  96.                                 lineHeight : "15px",
  97.                                 fontFamily : "微软雅黑"
  98.                         });
  99.                         map.addOverlay(currMark);
  100.                         currMark.setLabel(label);
  101.                         currMark.addEventListener("click", function() {
  102.                                 setTimeout(function() {
  103.                                         map.panTo(currPoint);
  104.                                 }, 400);
  105.                                 setTimeout(function() {
  106.                                         map.setZoom(15);
  107.                                 }, 300);
  108.                         });
  109.                 }
  110.         };

  111.         /* 标注经销商服务站 */
  112.         Model.prototype.addMarker = function() {
  113.                 if (!getParam)
  114.                         return;
  115.                 var markers = new Array();
  116.                 for (var i = 0; i < getParam.length; i++) {
  117.                         var point = getParam[i]['fLonLat'].split(",");
  118.                         var marker = new BMap.Marker(new BMap.Point(point[0], point[1]));
  119.                         markers.push(marker);
  120.                         map.addOverlay(marker);
  121.                         var name = getParam[i]['fName'];
  122.                         name = '<br><div>' + name + '</div>';
  123.                         addClickHandler(name, marker);
  124.                         function addClickHandler(content, marker) {
  125.                                 marker.addEventListener("click", function(e) {
  126.                                         var p = e.target;
  127.                                         var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  128.                                         var infoWindow = new BMap.InfoWindow(content); // 创建信息窗口对象
  129.                                         map.openInfoWindow(infoWindow, point); // 开启信息窗口
  130.                                 });
  131.                         }
  132.                 }
  133.                  //添加聚合效果
  134.                  var markerClusterer = new BMapLib.MarkerClusterer(map, {
  135.                  markers : markers
  136.                  });
  137.         };

  138.         /* 接收参数事件 */
  139.         Model.prototype.modelParamsReceive = function(event) {
  140.                 getProvince = event.data.province;
  141.                 getCity = event.data.city;
  142.                 if (event.data.param)
  143.                         getParam = $.parseJSON(event.data.param);
  144.                 getLongitude = event.data.longitude;
  145.                 getLatitude = event.data.latitude;
  146.                 getCurrent = event.data.current;
  147.                 firstProvince = event.data.isFirPro;
  148.                 pointTo = event.data.pointTo;

  149.                 // 异步加载百度地图
  150.                 this.loadMap();
  151.         };

  152.         return Model;
  153. });
复制代码




22222222.png

53

主题

928

帖子

1730

积分

金牌会员

Rank: 6Rank: 6

积分
1730
发表于 2018-9-28 08:55:00 | 显示全部楼层
http://bbs.wex5.com/forum.php?mo ... d=187890&extra=   我这里分享过···· 还有demo
承接wex5开发web项目、微信页面等;
低费用进行零散功能开发(java、JS、微信各种接口、阿里云接口等)
QQ:459349489
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-9-24 07:23 , Processed in 0.072609 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表