leadorStreetView.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /**
  2. * [ONEMAP.M.mod]
  3. * @return {[object]}
  4. */
  5. define(['html!templates/leadorStreetView',
  6. 'css!styles/leadorStreetView'],
  7. function(tplLayout){
  8. /**
  9. * 模块数据 用于数据存储和外部调用
  10. * @type {Object}
  11. * 数据存放
  12. */
  13. var modValue = {
  14. /**
  15. * 默认配置信息
  16. * @type {Object}
  17. * @default
  18. * {
  19. * stationID:0, //地点id
  20. * yaw:0, //视角
  21. * pitch:0
  22. * }
  23. */
  24. options:{
  25. stationID:0,
  26. yaw:0,
  27. pitch:0
  28. },
  29. /**
  30. * 当前的地点坐标
  31. * @type {Object}
  32. * @default {}
  33. * @private
  34. */
  35. currentPoint:{},
  36. /**
  37. * 需要添加的新坐标
  38. * @type {Object}
  39. * @default {}
  40. * @private
  41. */
  42. beAddPoint:{},
  43. //图层
  44. featureGroup:null,
  45. mapBound:null
  46. };
  47. /**
  48. * 模块界面样式 例如:宽,高
  49. * @type {Object}
  50. */
  51. var styles = {};
  52. /**
  53. * 模块状态,用于存储模块的状态 例如:收起,关闭
  54. * @type {Object}
  55. */
  56. var status = {
  57. initialized:false
  58. };
  59. /**
  60. * 查询参数
  61. * @type {Object}
  62. */
  63. var options = {};
  64. /**
  65. * 初始化并订阅事件
  66. * @return {[type]} [description]
  67. */
  68. function init(){
  69. if(!status.initialized){
  70. status.initialized = true;
  71. setLayout();
  72. subscribe();
  73. }
  74. }
  75. /**
  76. * 设置界面
  77. */
  78. function setLayout(){
  79. $('body').append(tplLayout);
  80. setTimeout(function(){
  81. buildLeadorSwf();
  82. },1000);
  83. modValue.featureGroup = map23DControl.group({
  84. action: 'add'
  85. });
  86. bindEvent();
  87. getCurrentAreaData();
  88. $(window).resize(function() {
  89. layoutResize();
  90. });
  91. }
  92. /**
  93. * 创建路径swf
  94. */
  95. function buildLeadorSwf(){
  96. var flashPlayerInfo = flashChecker();
  97. if(flashPlayerInfo && flashPlayerInfo.v > 10){
  98. /** 配置 **/
  99. var more = {};
  100. more.flashvars = {};
  101. LeadorStreetView.useHash = false;
  102. /** 设置服务信息 **/
  103. more.flashvars.TrueVisionSeverUrl = onemapUrlConfig.leadorStreetBaseUrl;
  104. more.flashvars.Port = onemapUrlConfig.leadorStreetPort;
  105. more.flashvars.DataName = onemapUrlConfig.leadorStreetDataName;
  106. more.flashvars.TrueVisionImageUrl = onemapUrlConfig.leadorStreetImageUrl;
  107. more.flashvars.UIUrl = map23DConfig.map23DAssetsUrl+"/scripts/vendor/leadorStreet/IShowChinaTVUIBJ.swf";
  108. more.flashvars.LogoUrl = map23DConfig.map23DAssetsUrl+"/scripts/vendor/leadorStreet/ld-logo.png";
  109. /** 绑定DIV **/
  110. LeadorStreetView.bindingDIV("leadorStreetPointViewSwf",null,more);
  111. LeadorStreetView.showFullScreenUI(false);
  112. }else {
  113. if(document.all){
  114. var flashPlayerLink = map23DConfig.map23DAssetsUrl+"/soft/flashplayer_winax.exe";
  115. }else {
  116. var flashPlayerLink = map23DConfig.map23DAssetsUrl+"/soft/flashplayer_win.exe";
  117. }
  118. var installFlashHtml = '<div class="install-flash-player">' +
  119. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  120. '<a href="'+flashPlayerLink+'"><img src="'+onemapUrlConfig.siteUrl+'/images/layout/get_flash.png"/><span>Adobe Flash Player 11</span></a>' +
  121. '</div>';
  122. document.getElementById('leadorStreetPointViewSwf').innerHTML = installFlashHtml;
  123. }
  124. };
  125. /**
  126. * 检查flash
  127. */
  128. function flashChecker(){
  129. var hasFlash = 0;
  130. var flashVersion =0;
  131. try{
  132. if(document.all){
  133. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  134. if(swf){
  135. hasFlash = 1;
  136. VSwf = swf.GetVariable('$version');
  137. flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
  138. }
  139. }else {
  140. if(navigator.plugins && navigator.plugins.length > 0){
  141. var swf = navigator.plugins["Shockwave Flash"];
  142. }
  143. if(swf){
  144. hasFlash = 1;
  145. var words = swf.description.split(" ");
  146. for(var i=0;i<words.length; i++){
  147. if(isNaN(parseInt(words[i]))) continue;
  148. flashVersion = parseInt(words[i]);
  149. }
  150. }
  151. }
  152. }catch (e) {
  153. }
  154. return {
  155. f:hasFlash,
  156. v:flashVersion
  157. };
  158. };
  159. /**
  160. * 获取当前区域的定点数据信息
  161. * @type {Function}
  162. * @private
  163. */
  164. function getCurrentAreaData(option){
  165. if(!status.initialized){
  166. $('body').append(tplLayout);
  167. setTimeout(function(){
  168. buildLeadorSwf();
  169. },1000);
  170. modValue.featureGroup = map23DControl.group({
  171. action: 'add'
  172. });
  173. bindEvent();
  174. status.initialized = true;
  175. }
  176. //modValue.featureGroup.clearLayers();
  177. if(option==='hide'){
  178. map23DControl.group({
  179. action:'cleanAll',
  180. guid:modValue.featureGroup
  181. })
  182. modValue.currentPoint = null;
  183. modValue.currentPoint = {};
  184. return false;
  185. }
  186. if(map2DViewer.hide2D){
  187. var mapZoom = map23DData.view.zoom;
  188. }else{
  189. var mapZoom = map2DViewer.map.getZoom();
  190. }
  191. //性能优化 小于14的比例图下不显示
  192. if(mapZoom < 14){
  193. map23DControl.group({
  194. action:'cleanAll',
  195. guid:modValue.featureGroup
  196. })
  197. modValue.currentPoint = null;
  198. modValue.currentPoint = {};
  199. return false;
  200. }
  201. modValue.mapBound = map2DViewer.map.getBounds();
  202. for(var oldPoint in modValue.featureGroup._layers){
  203. if(!modValue.mapBound.contains(modValue.featureGroup._layers[oldPoint]._latlng)){
  204. delete modValue._currentPoint[modValue.featureGroup._layers[oldPoint].pId];
  205. modValue.featureGroup.removeLayer(modValue.featureGroup._layers[oldPoint]);
  206. }
  207. }
  208. $.ajax({
  209. type:"get",
  210. dataType:'jsonp',
  211. jsonp:'callback',
  212. url:onemapUrlConfig.leadorStreetPointUrl+'/panoramic_data/?lat_lt='+modValue.mapBound.getNorthWest().lat+'&lon_lt='+modValue.mapBound.getNorthWest().lng+'&lat_rb='+modValue.mapBound.getSouthEast().lat+'&lon_rb='+modValue.mapBound.getSouthEast().lng,
  213. beforeSend:ONEMAP.V.loading.load(),
  214. success:function(data){
  215. modValue.beAddPoint = {};
  216. for(var i = 0,l = data.data.length; i<l;i++){
  217. var pointInfo = data.data[i];
  218. if(modValue.mapBound.contains(L.latLng(pointInfo.lat,pointInfo.lon))){
  219. if(!modValue.currentPoint.hasOwnProperty(pointInfo.StationID)){
  220. modValue.beAddPoint[pointInfo.StationID] = pointInfo;
  221. }
  222. modValue.currentPoint[pointInfo.StationID] = pointInfo;
  223. }
  224. }
  225. setPointMarker();
  226. },
  227. completer:ONEMAP.V.loading.loaded()
  228. });
  229. };
  230. /**
  231. * 在地图上显示当前区域的实景点
  232. * @type {Function}
  233. * @private
  234. */
  235. function setPointMarker(){
  236. for(var point in modValue.beAddPoint){
  237. var guid = map23DControl.buildGuid('sjmarker23D');
  238. var guid = map23DControl.marker({
  239. action:'add',
  240. guid:guid,
  241. groupId:modValue.featureGroup,
  242. geojson:{
  243. "properties":{
  244. title:modValue.beAddPoint[point].Address,
  245. iconUrl: map23DConfig.map23DAssetsUrl+'/images/layout/marker-panoramic.png',
  246. iconSize: [28, 30],
  247. iconAnchor: [14, 30],
  248. popupAnchor: [28, -30]
  249. },
  250. "geometry":{
  251. "coordinates":[modValue.beAddPoint[point].lon-0.0063,modValue.beAddPoint[point].lat-0.0014]
  252. }
  253. }
  254. })
  255. map23DData.markers[guid].pId = point;
  256. map2DViewer.markers[guid].on('click',function(e){
  257. var curMarkerData = map23DData.markers[e.target.guid];
  258. loadStreetView({stationID:curMarkerData.pId,yaw:"280",pitch:"15",address:this.address});
  259. })
  260. map2DViewer.markers[guid].on('onmouseover',function(){
  261. })
  262. }
  263. };
  264. /**
  265. * 设置模态窗口的大小和显示内容
  266. * @type {Function}
  267. * @param options {Object} 参数 {stationID,yaw,pitch}
  268. */
  269. function loadStreetView(options){
  270. modValue.options.stationID = options.stationID;
  271. modValue.options.yaw = options.yaw;
  272. modValue.options.pitch = options.pitch;
  273. $("#leadorStreetPointViewModal").css({width:$("#mapHolder").width(),height:$("#mapHolder").height()})
  274. $("#leadorStreetPointViewModal .modal-body").css({height:$("#mapHolder").height()-80});
  275. $("#leadorStreetPointViewModal").show();
  276. setTimeout(function(){
  277. LeadorStreetView.loadStreetViewByID(modValue.options.stationID);
  278. LeadorStreetView.setStreetViewAngle({yaw: modValue.options.yaw, pitch: modValue.options.pitch});
  279. },300);
  280. };
  281. /**
  282. * 界面事件绑定
  283. * @return {[type]} [description]
  284. */
  285. function bindEvent(){
  286. $("#leadorStreetPointViewModal .btn.close").bind('click',function(){
  287. $("#leadorStreetPointViewModal").hide();
  288. });
  289. }
  290. /**
  291. * 界面重置
  292. * @return {[type]} [description]
  293. */
  294. function layoutResize(){
  295. $("#leadorStreetPointViewModal").css({width:$("#mapHolder").width(),height:$("#mapHolder").height()})
  296. $("#leadorStreetPointViewModal .modal-body").css({height:$("#mapHolder").height()-80});
  297. }
  298. /**
  299. * 注册订阅
  300. * @type {Function}
  301. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  302. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  303. */
  304. function subscribe(){
  305. ONEMAP.C.publisher.subscribe(getCurrentAreaData, 'pointShijing');
  306. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  307. map2DViewer.map.on('leadorStreetView:on',remove);
  308. map2DViewer.map.on('leadorStreetView:off',getCurrentAreaData);
  309. PubSub.subscribe('map3D.featureClick',function(msg,options){
  310. if(options.feature.name.split('_')[0] == 'sjmarker23D'){
  311. markerData = map23DData.markers[options.feature.name];
  312. loadStreetView({stationID:markerData.pId,yaw:"280",pitch:"15",address:markerData.geojson.properties
  313. .title});
  314. }
  315. })
  316. }
  317. /**
  318. * 监听数据推送
  319. * @type {Function}
  320. */
  321. function publish() {
  322. //推送
  323. map2DViewer.map.fire('leadorStreetViewPoint:on');
  324. ONEMAP.C.publisher.publish('',
  325. 'leadorStreetViewOn'
  326. );
  327. }
  328. /**
  329. * 取消订阅
  330. * @type {Function}
  331. * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  332. */
  333. function unSubscribe(){}
  334. /**
  335. * 模块移除
  336. * @return {[type]} [description]
  337. */
  338. function remove(){
  339. if(status.initialized){
  340. unSubscribe();
  341. modValue.currentPoint = null;
  342. modValue.beAddPoint = null;
  343. map23DControl.group({
  344. action:'remove',
  345. guid:modValue.featureGroup
  346. })
  347. ONEMAP.C.publisher.publish('',
  348. 'leadorStreetViewOff'
  349. );
  350. modValue.currentPoint = {};
  351. modValue.beAddPoint = {};
  352. LeadorStreetView.removeBinding();
  353. $("#leadorStreetPointViewModal").remove();
  354. status.initialized = false;
  355. map2DViewer.map.fire('leadorStreetViewPoint:off');
  356. }
  357. //取消订阅
  358. unSubscribe();
  359. }
  360. return ONEMAP.M.mod = {
  361. init:init,
  362. layoutResize:layoutResize,
  363. remove:remove
  364. }
  365. });