百度地图聚合

前端之家收集整理的这篇文章主要介绍了百度地图聚合前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一、牛人们的想法
下面是我参考的有关的博客,下面将一一列举
4.百度地图官网上已经有JS版的标注物聚合实例与原文件,建议看百度地图上的代码,规范且函数注释明确。
二、我的思路
1.下面以一个流程图来表述我的想法。
2.下面贴出代码
[html] view plain copy
  1. <spanstyle="font-family:KaiTi_GB2312;">spanstyle="font-size:18px;">//cluster聚合器类
  2. packagecom.zhl.map;
  3. importjava.util.ArrayList;
  4. importjava.util.List;
  5. importandroid.graphics.Bitmap;
  6. importandroid.graphics.Point;
  7. importandroid.graphics.drawable.BitmapDrawable;
  8. importandroid.util.Log;
  9. importandroid.view.LayoutInflater;
  10. importandroid.view.View;
  11. importandroid.widget.TextView;
  12. importbaidumapsdk.demo.R;
  13. importcom.baidu.mapapi.cloud.Bounds;
  14. importcom.baidu.mapapi.map.MapView;
  15. importcom.baidu.mapapi.map.OverlayItem;
  16. importcom.baidu.mapapi.utils.DistanceUtil;
  17. importcom.baidu.platform.comapi.basestruct.GeoPoint;
  18. importcom.zhl.activity.MarkerClusterActivity;
  19. importcom.zhl.util.MapUtils;
  20. publicclassCluster{
  21. privateMarkerClusterActivitymMarkCluster;
  22. privateMapViewmMapView;
  23. privateintmMinClusterSize;
  24. privateBooleanisAverageCenter;
  25. privateintmGridSize;
  26. privatedoublemDistance;
  27. privateListClusterMarker>mMarkers;
  28. publicCluster(MarkerClusterActivitymarkCluster,MapViewmapView
  29. ,intminClusterSize,BooleanisAverageCenter
  30. ,intmGridSize,doublemDistance){
  31. this.mMarkCluster=markCluster;
  32. this.mMapView=mapView;
  33. this.mMinClusterSize=minClusterSize;
  34. this.isAverageCenter=isAverageCenter;
  35. this.mGridSize=mGridSize;
  36. this.mDistance=mDistance;
  37. mMarkers=newArrayList>();
  38. }
  39. publicListOverlayItem>createCluster(List>markerList){
  40. this.mMarkers.clear();
  41. List>itemList=newArrayList>();
  42. for(inti=0;imarkerList.size();i++){
  43. addCluster(markerList.get(i));
  44. }
  45. for(inti=0;imMarkers.size();i++){
  46. ClusterMarkercm=mMarkers.get(i);
  47. setClusterDrawable(cm);
  48. OverlayItemoi=newOverlayItem(cm.getmCenter(),cm.getTitle(),cm.getSnippet());
  49. oi.setMarker(cm.getMarker());
  50. itemList.add(oi);
  51. returnitemList;
  52. privatevoidaddCluster(OverlayItemmarker){
  53. GeoPointmarkGeo=marker.getPoint();
  54. if(mMarkers.size()==0){
  55. ClusterMarkerclusterMarker=newClusterMarker(marker.getPoint(),marker.getTitle(),marker.getSnippet());
  56. clusterMarker.setMarker(marker.getMarker());
  57. clusterMarker.AddMarker(marker,isAverageCenter);
  58. Boundsbound=newBounds(markGeo.getLatitudeE6(),markGeo.getLongitudeE6(),markGeo.getLatitudeE6(),markGeo.getLongitudeE6());
  59. bound=MapUtils.getExtendedBounds(mMapView,bound,mGridSize);
  60. clusterMarker.setmGridBounds(bound);
  61. mMarkers.add(clusterMarker);
  62. }else{
  63. ClusterMarkerclusterContain=null;
  64. doubledistance=mDistance;
  65. mMarkers.size();i++){
  66. ClusterMarkerclusterMarker=mMarkers.get(i);
  67. GeoPointcenter=clusterMarker.getmCenter();
  68. doubled=DistanceUtil.getDistance(center,marker.getPoint());
  69. if(ddistance){
  70. distance=d;
  71. clusterContain=clusterMarker;
  72. if(clusterContain==null||!isMarkersInCluster(markGeo,clusterContain.getmGridBounds())){
  73. clusterMarker.AddMarker(marker,isAverageCenter);
  74. Boundsbound=newBounds(markGeo.getLatitudeE6(),markGeo.getLongitudeE6());bound=MapUtils.getExtendedBounds(mMapView,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> mMarkers.add(clusterMarker);
  75. }else{
  76. clusterContain.AddMarker(marker,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> privatevoidsetClusterDrawable(ClusterMarkerclusterMarker){
  77. ViewdrawableView=LayoutInflater.from(mMarkCluster).inflate(
  78. R.layout.drawable_mark,null);
  79. TextViewtext=(TextView)drawableView.findViewById(R.id.drawble_mark);
  80. intmarkNum=clusterMarker.getmMarkers().size();
  81. if(markNum>=2){
  82. text.setText(markNum+"");
  83. 11){
  84. text.setBackgroundResource(R.drawable.m0);
  85. }elseif(markNum>10&&markNum21){
  86. text.setBackgroundResource(R.drawable.m1);
  87. >20&&markNum31){
  88. text.setBackgroundResource(R.drawable.m2);
  89. >30&&markNum41){
  90. text.setBackgroundResource(R.drawable.m3);
  91. text.setBackgroundResource(R.drawable.m4);
  92. Bitmapbitmap=MapUtils.convertViewToBitmap(drawableView);
  93. clusterMarker.setMarker(newBitmapDrawable(bitmap));
  94. privateBooleanisMarkersInCluster(GeoPointmarkerGeo,Boundsbound){
  95. if(markerGeo.getLatitudeE6()>bound.leftBottom.getLatitudeE6()
  96. &&markerGeo.getLatitudeE6()bound.rightTop.getLatitudeE6()
  97. &&markerGeo.getLongitudeE6()>bound.rightTop.getLongitudeE6()
  98. &&markerGeo.getLongitudeE6()bound.leftBottom.getLongitudeE6()){
  99. returntrue;
  100. returnfalse;
  101. }</span>

3.工程demo代码下载,地图标注物聚合.zip
4.下面是程序的实例图片

原文链接:https://www.f2er.com/javaschema/285766.html

猜你在找的设计模式相关文章