Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - places.js (Старый размер - 26172 | Новый - 0):
- 0. - var Places = {
- 1. -
- 2. - initPhotoMap: function(opts) {
- 3. - var map, isMapbox, isGoogle, CustomMarker, createMarker;
- 4. - if (!cur.iconLastNum) {
- 5. - cur.iconLastNum = 0;
- 6. - }
- 7. - if (opts.provider == 'mapbox') {
- 8. - cur.provider = 'mapbox';
- 9. - cur.providerId = 3;
- 10. - isMapbox = 1;
- 11. - if (!window.L || !window.L.mapbox) {
- 12. - var stat = ['mapbox.css', 'mapbox.js'];
- 13. - if (browser.msie && browser.version < 8) {
- 14. - stat.push('mapbox_ie.css');
- 15. - }
- 16. - stManager.add(stat, function() {
- 17. - Places.initPhotoMap(opts);
- 18. - });
- 19. - return false;
- 20. - }
- 21. - } else {
- 22. - cur.provider = 'google';
- 23. - cur.providerId = 2;
- 24. - isGoogle = 1;
- 25. - if (!window.google || !google.maps.OverlayView) {
- 26. - if (!opts.googleAttaced) {
- 27. - headNode.appendChild(ce('script', {
- 28. - type: 'text/javascript',
- 29. - src: (window.locProtocol || 'http:') + '//maps.google.com/maps/api/js?sensor=false&callback=gMapsInit&language='+(cur.vkLngCode || 'en')
- 30. - }));
- 31. - }
- 32. - window.gMapsInit = function() {
- 33. - Places.initPhotoMap(opts);
- 34. - delete window.gMapsInit;
- 35. - }
- 36. - return false;
- 37. - }
- 38. - }
- 39. - cur.photoMapOpts = opts;
- 40. -
- 41. - function unexpandPoint(point, sub) {
- 42. - if (!point.expanded) {
- 43. - return false;
- 44. - }
- 45. - if (!sub) {
- 46. - if (isMapbox) {
- 47. - map.addLayer(point.overlay);
- 48. - } else {
- 49. - point.overlay.setMap(map);
- 50. - }
- 51. - }
- 52. - point.expanded = false;
- 53. - var p = point.points;
- 54. - if (p) {
- 55. - for (i in p) {
- 56. - var subPoint = p[i];
- 57. - if (subPoint.overlay) {
- 58. - if (isMapbox) {
- 59. - map.removeLayer(subPoint.overlay);
- 60. - } else {
- 61. - subPoint.overlay.setMap(null);
- 62. - }
- 63. - unexpandPoint(subPoint, true)
- 64. - }
- 65. - }
- 66. - }
- 67. - }
- 68. -
- 69. - function expandPoint(point, possive) {
- 70. - if (point.diff && point.diff < 0.00002) {
- 71. - return false;
- 72. - }
- 73. - if (point.diff && point.diff <= (point.count + 1) * 0.000001) {
- 74. - return false;
- 75. - }
- 76. - var p = point.points;
- 77. - if (p) {
- 78. - if (point.expanded || possive) {
- 79. - return false;
- 80. - }
- 81. - var len = p.length;
- 82. - while (len--) {
- 83. - var subPoint = p[len];
- 84. - if (subPoint.overlay) {
- 85. - if (isMapbox) {
- 86. - map.addLayer(subPoint.overlay);
- 87. - } else {
- 88. - subPoint.overlay.setMap(map);
- 89. - }
- 90. - } else {
- 91. - if (isMapbox) {
- 92. - var pt = new L.LatLng(subPoint.lat, subPoint.lng);
- 93. - subPoint.overlay = createMarker(pt, map, subPoint.src, subPoint.count, subPoint.diff);
- 94. - subPoint.overlay.on('click', (pointClick).pbind(subPoint));
- 95. - } else {
- 96. - var pt = new google.maps.LatLng(subPoint.lat, subPoint.lng);
- 97. - subPoint.overlay = new CustomMarker(pt, map, subPoint.src, subPoint.count, subPoint.diff);
- 98. - google.maps.event.addListener(subPoint.overlay, 'click', (pointClick).pbind(subPoint));
- 99. - }
- 100. - }
- 101. - }
- 102. - if (isMapbox) {
- 103. - map.removeLayer(point.overlay);
- 104. - } else {
- 105. - point.overlay.setMap(null);
- 106. - }
- 107. - point.expanded = true;
- 108. - } else if (!point.loading) {
- 109. - point.loading = true;
- 110. - ajax.post('al_places.php', {
- 111. - act: 'a_get_points',
- 112. - diff: point.diff || opts.diffZone,
- 113. - lat: point.lat,
- 114. - lng: point.lng,
- 115. - uid: opts.uid
- 116. - }, {
- 117. - onDone: function(points) {
- 118. - point.points = points;
- 119. - expandPoint(point, possive);
- 120. - },
- 121. - onFail: function() {
- 122. - point.loading = false;
- 123. - }
- 124. - })
- 125. - }
- 126. - }
- 127. -
- 128. - function checkPointsReq(points, mapBounds) {
- 129. - if (!points) {
- 130. - return false;
- 131. - }
- 132. - for (i in points) {
- 133. - var point = points[i];
- 134. - if (point.count <= 1) {
- 135. - continue;
- 136. - }
- 137. - var diff = (point.diff * 15) || opts.diffZone;
- 138. - var inside = (point.lat + diff > mapBounds.neLat && point.lat - diff < mapBounds.swLat && point.lng + diff > mapBounds.neLng && point.lng - diff < mapBounds.swLng);
- 139. -
- 140. - if (!inside) {
- 141. - if (point.expanded) {
- 142. - unexpandPoint(point);
- 143. - }
- 144. - continue;
- 145. - }
- 146. - if (point.expanded) {
- 147. - checkPointsReq(point.points, mapBounds);
- 148. - } else if (inside) {
- 149. - expandPoint(point);
- 150. - } else if (point.expanded) {
- 151. - unexpandPoint(point);
- 152. - }
- 153. - }
- 154. - }
- 155. -
- 156. - function updateMapPoints() {
- 157. - checkPointsReq(opts.points, getMapBounds());
- 158. - }
- 159. -
- 160. - function zoomToPoint(point) {
- 161. - var mapBounds = map.getBounds();
- 162. - var ne = mapBounds.getNorthEast();
- 163. - var sw = mapBounds.getSouthWest();
- 164. - var zoom = map.getZoom();
- 165. - if (point.diff) {
- 166. - var needZoom = ((ne.lat() - sw.lat()) * 0.9) > point.diff * 2;
- 167. - } else {
- 168. - var needZoom = zoom < 17;
- 169. - }
- 170. - if (needZoom) {
- 171. - map.setZoom(zoom + 1)
- 172. - //zoomToPoint(point);
- 173. - setTimeout(zoomToPoint.pbind(point), 0)
- 174. - } else {
- 175. - updateMapPoints();
- 176. - }
- 177. - }
- 178. -
- 179. - function pointClick(point) {
- 180. - if (!opts.box) {
- 181. - showBox('al_places.php', {
- 182. - act: 'photos_box',
- 183. - lat: point.lat,
- 184. - lng: point.lng,
- 185. - diff: opts.diffZone,
- 186. - uid: opts.uid
- 187. - }, {
- 188. - stat: ['maps.js', 'places.js', 'places.css', 'ui_controls.js', 'ui_controls.css']
- 189. - });
- 190. - return false;
- 191. - }
- 192. - if (point.count == 1/* || point.diff < 0.0001*/ || true) {
- 193. - var photo = point.photo.split('_');
- 194. - if (point.overlay) {
- 195. - var elCont = ge('profile_map_icon_'+point.overlay.iconNum);
- 196. - var el = geByClass1('profile_map_first', elCont) || elCont;
- 197. - var cnt = geByClass1('profile_map_photo_count', el);
- 198. - if (cnt) {
- 199. - hide(cnt);
- 200. - }
- 201. - re('profile_map_photo_loader');
- 202. - var loader = ce('div', {id: 'profile_map_photo_loader'});
- 203. - el.appendChild(loader);
- 204. - }
- 205. - var diff = (point.diff || 0.000001);
- 206. - var list = 'map'+opts.uid+'_'+(point.lat - diff)+'_'+(point.lng - diff)+'_'+(point.lat + diff)+'_'+(point.lng + diff);
- 207. - return opts.showPlacePhoto(point.photo, list, {});
- 208. - }/* else if (opts.box) {
- 209. - map.panTo(new google.maps.LatLng(point.lat, point.lng));
- 210. - zoomToPoint(point);
- 211. - expandPoint(point, true);
- 212. - }*/
- 213. - return false;
- 214. - }
- 215. -
- 216. - function getMapBounds() {
- 217. - var mapBounds = map.getBounds();
- 218. - var ne = mapBounds.getNorthEast();
- 219. - var sw = mapBounds.getSouthWest();
- 220. - var zoom = map.getZoom();
- 221. - if (zoom < 3) {
- 222. - var res = {
- 223. - swLat: -90,
- 224. - swLng: -90,
- 225. - neLat: 90,
- 226. - neLng: 90
- 227. - };
- 228. - } else {
- 229. - if (isMapbox) {
- 230. - var res = {
- 231. - swLat: sw.lat,
- 232. - swLng: sw.lng,
- 233. - neLat: ne.lat,
- 234. - neLng: ne.lng
- 235. - };
- 236. - } else {
- 237. - var res = {
- 238. - swLat: sw.lat(),
- 239. - swLng: sw.lng(),
- 240. - neLat: ne.lat(),
- 241. - neLng: ne.lng()
- 242. - };
- 243. - }
- 244. - }
- 245. - return res;
- 246. - }
- 247. -
- 248. - function updatePhotosList() {
- 249. - var mapBounds = getMapBounds();
- 250. - ajax.post('al_places.php', {
- 251. - act: 'update_photos_list',
- 252. - uid: opts.uid,
- 253. - sw_lat: mapBounds.swLat,
- 254. - sw_lng: mapBounds.swLng,
- 255. - ne_lat: mapBounds.neLat,
- 256. - ne_lng: mapBounds.neLng
- 257. - }, {
- 258. - onDone: function(html) {
- 259. - ge('place_map_other').innerHTML = html;
- 260. - }
- 261. - })
- 262. - checkPointsReq(opts.points, mapBounds);
- 263. - }
- 264. -
- 265. - function setMapOpts(map) {
- 266. - if (opts.box) {
- 267. - cur.placeBoxMap = map;
- 268. - cur.placeBoxOpts = opts;
- 269. - } else {
- 270. - cur.placesPhotoMap = map;
- 271. - cur.placesPhotoOpts = opts;
- 272. - }
- 273. - }
- 274. -
- 275. - function onBoundsChanged(fast) {
- 276. - if (cur.editPhotosPlace) {
- 277. - fadeOut(ge('places_photo_hint_cont'), 200);
- 278. - }
- 279. - if (cur.mapMoveTimeout) {
- 280. - clearTimeout(cur.mapMoveTimeout);
- 281. - }
- 282. - cur.mapMoveTimeout = setTimeout(updateMapPoints, fast ? 0 : 200)
- 283. - if (firstTimeout) {
- 284. - firstTimeout = false;
- 285. - return false;
- 286. - }
- 287. - if (opts.box) {
- 288. - if (cur.mapMoveServerTimeout) {
- 289. - clearTimeout(cur.mapMoveServerTimeout);
- 290. - }
- 291. - cur.mapMoveServerTimeout = setTimeout(updatePhotosList, 500)
- 292. - }
- 293. - }
- 294. -
- 295. - function getIconHtml(imgSrc, cnt, diff, iconNum) {
- 296. - var html = '';
- 297. - if (cnt > 1 && diff) {
- 298. - html = '<span class="profile_map_photo_count">'+(cnt > 99 ? '99+' : cnt)+'</span>';
- 299. - }
- 300. - var len = Math.min(cnt - 1, 3);
- 301. - html = '<div'+(len ? '' : ' id="profile_map_icon_'+iconNum+'"')+' class="profile_map_photo profile_map_first" style="background: url('+imgSrc+') center center no-repeat;'+(len ? ' margin-left: -2px; margin-top: -4px;' : '')+'">'+html+'</div>';
- 302. - while(len--) {
- 303. - html = '<div'+(len ? '' : ' id="profile_map_icon_'+iconNum+'"')+' class="profile_map_photo"'+(len ? ' style="margin-left: -2px; margin-top: -4px;"' : '')+'>'+html+'</div>';
- 304. - }
- 305. - return html;
- 306. - }
- 307. -
- 308. - cur.editPhotosPlace = false;
- 309. -
- 310. - var firstTimeout = true;
- 311. - if (isMapbox) {
- 312. - createMarker = function(latlng, addToMap, src, count, diff) {
- 313. - var icon = new L.HtmlIcon({
- 314. - html: getIconHtml(src, count, diff, cur.iconLastNum)
- 315. - });
- 316. - cur.icon = icon;
- 317. - var m = new L.Marker(latlng, {
- 318. - draggable: false,
- 319. - icon: icon
- 320. - });
- 321. - if (addToMap) {
- 322. - map.addLayer(m);
- 323. - } else {
- 324. - map.removeLayer(m);
- 325. - }
- 326. - m.iconNum = cur.iconLastNum++;
- 327. - return m;
- 328. - }
- 329. - var mapboxApiId = 'vkmaps.map-an1xcr4f';
- 330. - var mapboxApiId_2x = 'vkmaps.map-40lc3e3w';
- 331. - if (opts.map) {
- 332. - map = opts.map;
- 333. - } else {
- 334. - map = L.mapbox.map(opts.cont, false, {zoomControl: false, scrollWheelZoom: false, touchZoom: false});
- 335. - L.mapbox.tileLayer(mapboxApiId,{
- 336. - detectRetina: true,
- 337. - retinaVersion: mapboxApiId_2x
- 338. - }).addTo(map);
- 339. -
- 340. - }
- 341. - setMapOpts(map);
- 342. -
- 343. - if (opts.bounds) {
- 344. - map.fitBounds([[opts.bounds.swlat, opts.bounds.swlng], [opts.bounds.nelat, opts.bounds.nelng]]);
- 345. - } else {
- 346. - if (!opts.lat && !opts.lng) {
- 347. - opts.lat = 30;
- 348. - }
- 349. - map.setView([opts.lat, opts.lng], 1)
- 350. - }
- 351. - if (!opts.nowheel) {
- 352. - map.on('moveend', onBoundsChanged.pbind(true));
- 353. - map.on('zoomend', onBoundsChanged.pbind(true));
- 354. - }
- 355. -
- 356. - if (opts.points) {
- 357. - var len = opts.points.length;
- 358. - while(len--) {
- 359. - var point = opts.points[len];
- 360. - var p = new L.LatLng(point.lat, point.lng);
- 361. - point.overlay = createMarker(p, point.points ? false : true, point.src, point.count, point.diff);
- 362. - point.overlay.on('click', (pointClick).pbind(point));
- 363. - if (point.points) {
- 364. - expandPoint(point);
- 365. - }
- 366. - }
- 367. - }
- 368. -
- 369. - map.on('click', (function(point) {
- 370. - if (!opts.box) {
- 371. - Places.showProfileBox(opts.uid);
- 372. - }
- 373. - }).bind(this));
- 374. - } else {
- 375. - CustomMarker = function(latlng, map, src, count, diff) {
- 376. - this.latlng = latlng;
- 377. - this.photoSrc = src;
- 378. - this.photoCount = count;
- 379. - this.photoDiff = diff;
- 380. - this.setMap(map);
- 381. - }
- 382. -
- 383. - CustomMarker.prototype = new google.maps.OverlayView();
- 384. -
- 385. - CustomMarker.prototype.draw = function() {
- 386. - var div = this.photoDiv;
- 387. - if (!div) {
- 388. -
- 389. - var div = se(getIconHtml(this.photoSrc, this.photoCount, this.photoDiff, cur.iconLastNum));
- 390. - this.photoDiv = div;
- 391. - this.iconNum = cur.iconLastNum++;
- 392. -
- 393. - google.maps.event.addDomListener(div, 'click', (function(event) {
- 394. - google.maps.event.trigger(this, 'click');
- 395. - return cancelEvent(event);
- 396. - }).bind(this));
- 397. -
- 398. - var panes = this.getPanes();
- 399. - panes.overlayImage.appendChild(div);
- 400. - }
- 401. -
- 402. - var point = this.getProjection().fromLatLngToDivPixel(this.latlng);
- 403. - if (point) {
- 404. - div.style.left = point.x + 'px';
- 405. - div.style.top = point.y + 'px';
- 406. - }
- 407. - };
- 408. -
- 409. - CustomMarker.prototype.remove = function() {
- 410. - if (this.photoDiv) {
- 411. - this.photoDiv.parentNode.removeChild(this.photoDiv);
- 412. - this.photoDiv = null;
- 413. - }
- 414. - };
- 415. -
- 416. - CustomMarker.prototype.getPosition = function() {
- 417. - return this.latlng;
- 418. - };
- 419. -
- 420. -
- 421. - var mapOpts = {
- 422. - center: new google.maps.LatLng(opts.lat, opts.lng),
- 423. - mapTypeId: google.maps.MapTypeId.ROADMAP,
- 424. - disableDefaultUI: true
- 425. - }
- 426. - if (opts.nowheel) {
- 427. - mapOpts.scrollwheel = false;
- 428. - mapOpts.disableDoubleClickZoom = true;
- 429. - }
- 430. - if (opts.map) {
- 431. - map = opts.map;
- 432. - } else {
- 433. - map = new google.maps.Map(ge(opts.cont), mapOpts);
- 434. - }
- 435. - setMapOpts(map);
- 436. -
- 437. - if (opts.bounds) {
- 438. - var sw = new google.maps.LatLng(opts.bounds.swlat, opts.bounds.swlng);
- 439. - var ne = new google.maps.LatLng(opts.bounds.nelat, opts.bounds.nelng);
- 440. - map.fitBounds(new google.maps.LatLngBounds(sw, ne));
- 441. - } else {
- 442. - if (!opts.lat && !opts.lng) {
- 443. - opts.lat = 30;
- 444. - }
- 445. - map.setCenter(new google.maps.LatLng(opts.lat, opts.lng));
- 446. - map.setZoom(1);
- 447. - }
- 448. -
- 449. - if (!opts.nowheel) {
- 450. - google.maps.event.addListener(map, 'bounds_changed', onBoundsChanged.pbind(false));
- 451. - }
- 452. -
- 453. - if (opts.points) {
- 454. - var len = opts.points.length;
- 455. - while(len--) {
- 456. - var point = opts.points[len];
- 457. - var p = new google.maps.LatLng(point.lat, point.lng);
- 458. - point.overlay = new CustomMarker(p, point.points ? null : map, point.src, point.count, point.diff);
- 459. - google.maps.event.addListener(point.overlay, 'click', (pointClick).pbind(point));
- 460. - if (point.points) {
- 461. - expandPoint(point);
- 462. - }
- 463. - }
- 464. - }
- 465. -
- 466. - google.maps.event.addDomListener(map, 'click', (function(point) {
- 467. - if (!opts.box) {
- 468. - Places.showProfileBox(opts.uid);
- 469. - }
- 470. - }).bind(this));
- 471. - }
- 472. - },
- 473. -
- 474. - showProfileBox: function(uid) {
- 475. - showBox('al_places.php', {
- 476. - act: 'photos_box',
- 477. - uid: uid
- 478. - }, {
- 479. - stat: ['maps.js', 'places.js', 'places.css', 'ui_controls.js', 'ui_controls.css']
- 480. - });
- 481. - return false;
- 482. - },
- 483. -
- 484. - setMarker: function(map, point) {
- 485. - cur.placeMarker = new vkMaps.Marker(point);
- 486. - cur.placeMarker.mousedown.addHandler(function() {
- 487. - });
- 488. - cur.placeMarker.dragend.addHandler(function(type, marker) {
- 489. - marker.update();
- 490. - Places.setPlaceStr(marker.location);
- 491. - });
- 492. - map.addMarkerWithData(cur.placeMarker, {
- 493. - draggable: true,
- 494. - icon: '/images/map/move.png',
- 495. - icon2x: '/images/map/move_2x.png',
- 496. - iconSize: [33, 32],
- 497. - iconAnchor: [16, 32],
- 498. - infoBubble: ''
- 499. - });
- 500. - },
- 501. -
- 502. - showMorePhotos: function(uid) {
- 503. - if (!cur.addPhotosOffset || cur.PlacesPhotosMoreBack) {
- 504. - return false;
- 505. - }
- 506. - var cont = ge('places_photo_more');
- 507. - cur.PlacesPhotosMoreBack = cont.innerHTML;
- 508. - ajax.post('al_places.php', {act: 'a_edit_photos', uid: uid, offset: cur.addPhotosOffset}, {
- 509. - onDone: function(html, offset, showmore) {
- 510. - cur.addPhotosOffset = offset;
- 511. - if (!showmore) {
- 512. - hide('places_photo_more');
- 513. - }
- 514. - var elsCont = ge('places_map_add_list');
- 515. - elsCont.appendChild(cf(html));
- 516. - cur.PlacesPhotosMoreBack = false;
- 517. - },
- 518. - showProgress: function() {
- 519. - cont.innerHTML = '<img src="/images/upload.gif">';
- 520. - },
- 521. - hideProgress: function() {
- 522. - cont.innerHTML = cur.PlacesPhotosMoreBack;
- 523. - }
- 524. - }, {stat: ['upload.js']})
- 525. - },
- 526. -
- 527. - addPhotos: function(obj, uid) {
- 528. - ajax.post('al_places.php', {act: 'a_edit_photos', uid: uid}, {
- 529. - onDone: function(html, js, offset) {
- 530. - hide('places_edit_step_0');
- 531. - show('places_edit_step_1');
- 532. - hide('places_edit_step_2');
- 533. - hide('places_edit_step_3');
- 534. - hide('place_map_cont');
- 535. - cur.addPhotosOffset = offset;
- 536. - cur.editPhotosPlace = true;
- 537. - cur.placesFixedBottom = false;
- 538. - var editCont = ge('place_map_edit');
- 539. - editCont.innerHTML = html;
- 540. - show(editCont);
- 541. - hide('place_map_other');
- 542. -
- 543. - /*var tt = ge('places_photo_hint_cont');
- 544. - if (tt) {
- 545. - fadeIn(tt, 100);
- 546. - } else {
- 547. - var mapCont = ge('place_map_cont');
- 548. - var tt = ce('div', {
- 549. - innerHTML: '<div class="places_photo_hint">'+getLang('places_select_position')+'</div><div id="places_photo_pointer"></div>',
- 550. - className: 'places_photo_hint_cont',
- 551. - id: 'places_photo_hint_cont'
- 552. - });
- 553. - mapCont.parentNode.insertBefore(tt, mapCont);
- 554. - var w = getSize(tt)[0];
- 555. - tt.style.marginLeft = intval((666 - w) / 2) + 'px';
- 556. - ge('places_photo_pointer').style.marginLeft = intval((w/2) - 10)+ 'px';
- 557. - }
- 558. - show('places_photos_save_panel');
- 559. - Places.setMarker(cur.vkmap.getCenter());*/
- 560. - cur.onPlaceScroll();
- 561. - if (js) {
- 562. - eval('(function() {'+js+'})();')
- 563. - }
- 564. - },
- 565. - showProgress: function() {
- 566. - lockButton(obj);
- 567. - },
- 568. - hideProgress: function() {
- 569. - unlockButton(obj);
- 570. - }
- 571. - })
- 572. - },
- 573. -
- 574. - step2: function() {
- 575. - hide('places_edit_step_0');
- 576. - show('places_edit_step_1');
- 577. - hide('places_edit_step_2');
- 578. - hide('places_edit_step_3');
- 579. - hide('place_map_cont');
- 580. - show('place_map_edit');
- 581. - hide('place_map_point');
- 582. - hide('place_map_other');
- 583. - cur.vkmap.removeMarker(cur.placeMarker);
- 584. - },
- 585. -
- 586. - cancelAdd: function() {
- 587. - cur.editPhotosPlace = false;
- 588. - show('places_edit_step_0');
- 589. - hide('places_edit_step_1');
- 590. - hide('places_edit_step_2');
- 591. - hide('places_edit_step_3');
- 592. - show('place_map_cont');
- 593. - hide('place_map_edit');
- 594. - hide('place_map_point');
- 595. - show('place_map_other');
- 596. - cur.vkmap.removeMarker(cur.placeMarker);
- 597. - },
- 598. -
- 599. - selectPhoto: function(pids, photoSrc, lat, lng) {
- 600. - cur.mapPids = pids;
- 601. - hide('places_edit_step_0');
- 602. - hide('places_edit_step_1');
- 603. - show('places_edit_step_2');
- 604. - hide('places_edit_step_3');
- 605. - hide('place_map_edit');
- 606. - show('place_map_point');
- 607. - var mapChoose = new vkMaps.VKMap('place_map_point_cont', {
- 608. - provider: cur.provider || 'google',
- 609. - providerId: cur.providerId || 2,
- 610. - lngcode: cur.vkLngCode,
- 611. - });
- 612. - cur.placesChooseMap = mapChoose;
- 613. - placeholderSetup(ge('place_map_point_search'), {back: true});
- 614. - var pCont = ge('place_map_point');
- 615. - var els = geByClass('places_map_preview', pCont);
- 616. - for (var i in els) {
- 617. - re(els[i]);
- 618. - }
- 619. - pCont.appendChild(ce('div', {
- 620. - innerHTML: '<div class="places_map_preview_cont"><img src="'+photoSrc+'" class="places_map_preview_img" align="center" /></div>',
- 621. - className: 'places_map_preview'
- 622. - }));
- 623. -
- 624. - mapChoose.addMapTypeControls();
- 625. - mapChoose.addControls({zoom: 'large', pan: false});
- 626. - if (!cur.lastSelectLat && !cur.lastSelectLng) {
- 627. - var lastPos = ls.get('last_map_pos');
- 628. - if (lastPos) {
- 629. - cur.lastSelectLat = lastPos[0];
- 630. - cur.lastSelectLng = lastPos[1];
- 631. - cur.lastSelectZoom = lastPos[2];
- 632. - }
- 633. - }
- 634. -
- 635. - var loc = cur.vkmap.getCenter();
- 636. - if (lat || lng) {
- 637. - var point = new vkMaps.LatLonPoint(lat, lng);
- 638. - mapChoose.setCenterAndZoom(point, 14);
- 639. - Places.setMarker(mapChoose, point);
- 640. - Places.setPlaceStr(point, true);
- 641. - } else {
- 642. - var point = new vkMaps.LatLonPoint(cur.lastSelectLat || loc.lat, cur.lastSelectLng || loc.lon);
- 643. - mapChoose.setCenterAndZoom(point, cur.lastSelectZoom || cur.vkmap.getZoom());
- 644. - }
- 645. -
- 646. - mapChoose.click.addHandler((function(eventType, map, place) {
- 647. - mapChoose.removeMarker(cur.placeMarker);
- 648. - Places.setMarker(mapChoose, place.location);
- 649. - Places.setPlaceStr(place.location);
- 650. -
- 651. - //fadeOut(ge('places_photo_hint_cont'), 200);
- 652. - }).bind(this));
- 653. - },
- 654. -
- 655. - setPlaceStr: function(loc, noRemember) {
- 656. - if (!noRemember) {
- 657. - cur.lastSelectLat = loc.lat;
- 658. - cur.lastSelectLng = loc.lon;
- 659. - cur.lastSelectZoom = Math.min(16, cur.placesChooseMap.getZoom());
- 660. - ls.set('last_map_pos', [cur.lastSelectLat, cur.lastSelectLng, cur.lastSelectZoom]);
- 661. - }
- 662. - vkMaps.load('yandex', function() {
- 663. - var geocoder = new vkMaps.Geocoder('yandex', function(place) {
- 664. - hide('places_edit_step_0');
- 665. - hide('places_edit_step_1');
- 666. - hide('places_edit_step_2');
- 667. - show('places_edit_step_3');
- 668. - cur.lastSelectedPlace = place;
- 669. - var placeInfo = [];
- 670. -
- 671. - if (place.place) {
- 672. - placeInfo.push(place.place);
- 673. - } else if (place.street) {
- 674. - placeInfo.push(place.street);
- 675. - } else if (place.region) {
- 676. - placeInfo.push(place.region);
- 677. - }
- 678. - if (place.locality) {
- 679. - placeInfo.push(place.locality);
- 680. - } else if (place.country) {
- 681. - placeInfo.push(place.country);
- 682. - }
- 683. - for (var i in placeInfo) {
- 684. - if (placeInfo[i].length > 26) {
- 685. - placeInfo[i] = placeInfo[i].substr(0, 24)+'..';
- 686. - }
- 687. - }
- 688. - var str = placeInfo.join(', ');
- 689. - ge('place_map_edit_add').innerHTML = getLang('places_add_to_point').replace('%s', str);
- 690. - });
- 691. - geocoder.geocode({lat: loc.lat, lon: loc.lon, language: cur.vkLngCode})
- 692. - });
- 693. - },
- 694. -
- 695. - searchPhotoPlace: function() {
- 696. - var str = val(ge('place_map_point_search'));
- 697. -
- 698. - vkMaps.load('yandex', function() {
- 699. - var geocoder = new vkMaps.Geocoder('yandex', function(place) {
- 700. - cur.placesChooseMap.setBounds(place.bounds)
- 701. - cur.placesChooseMap.removeMarker(cur.placeMarker);
- 702. - Places.setPlaceStr(place.point);
- 703. - Places.setMarker(cur.placesChooseMap, place.point);
- 704. - }, function() {
- 705. - notaBene('place_map_point_search');
- 706. - });
- 707. - geocoder.geocode({address: str, language: cur.vkLngCode})
- 708. - });
- 709. - },
- 710. -
- 711. - onEditScroll: function(resize) {
- 712. - var y = boxLayerWrap.scrollTop;
- 713. - var panel = ge('places_photos_save_buttons');
- 714. - if (!panel) return;
- 715. - var py = getXY(ge('places_photos_save_panel'), true)[1];
- 716. - if (!cur.boxPhotosBottomSize) {
- 717. - cur.boxPhotosBottomSize = getSize(panel);
- 718. - }
- 719. -
- 720. - var ph = cur.boxPhotosBottomSize[1];
- 721. -
- 722. - var wndHeight = window.innerHeight || document.documentElement.clientHeight;
- 723. -
- 724. - if (resize && !cur.placesFixedBottom && wndHeight - ph < py + 20) {
- 725. - boxLayerWrap.scrollTop += py + 20 - (wndHeight - ph);
- 726. - } else if (wndHeight - ph < py) {
- 727. - if (!cur.placesFixedBottom || resize) {
- 728. - cur.placesFixedBottom = true;
- 729. - setStyle(panel, {
- 730. - position: 'fixed',
- 731. - top: (wndHeight - ph) + 'px'
- 732. - });
- 733. - addClass(panel, 'places_panel_fixed');
- 734. - }
- 735. - } else {
- 736. - if (cur.placesFixedBottom || resize) {
- 737. - cur.placesFixedBottom = false;
- 738. - setStyle(panel, {
- 739. - position: 'static',
- 740. - top: '0px'
- 741. - });
- 742. - removeClass(panel, 'places_panel_fixed');
- 743. - }
- 744. - }
- 745. -
- 746. - if (resize && cur.placesFixedBottom) {
- 747. - setStyle(panel, {left: (getXY(curBox().bodyNode)[0] + 1)+'px'})
- 748. - }
- 749. - },
- 750. -
- 751. - savePhotos: function(btn, hash) {
- 752. - var loc = cur.placeMarker.location;
- 753. - var params = {act: 'save_photos_places', pids: cur.mapPids, lat: loc.lat, lng: loc.lon, hash: hash};
- 754. - if (cur.lastSelectedPlace) {
- 755. - var place = cur.lastSelectedPlace;
- 756. - extend(params, {
- 757. - geo_country: place.country,
- 758. - geo_locality: place.locality,
- 759. - geo_region: place.region,
- 760. - geo_street: place.street,
- 761. - geo_place: place.place,
- 762. - geo_lang: cur.vkLngCode,
- 763. - geo_code: place.countryCode
- 764. - });
- 765. - }
- 766. - ajax.post('al_places.php', params, {
- 767. - onDone: function() {
- 768. - //Places.cancelAdd();
- 769. - Places.updateBox();
- 770. - },
- 771. - showProgress: function() {
- 772. - lockButton(btn);
- 773. - },
- 774. - hideProgress: function() {
- 775. - unlockButton(btn);
- 776. - }
- 777. - })
- 778. - },
- 779. -
- 780. - updateBox: function() {
- 781. - var box = curBox();
- 782. - box.hide();
- 783. - showBox('al_places.php', {
- 784. - act: 'photos_box',
- 785. - add_more: '1',
- 786. - lat: cur.placeBoxOpts.lat,
- 787. - lng: cur.placeBoxOpts.lng,
- 788. - diff: cur.placeBoxOpts.diffZone,
- 789. - uid: cur.placeBoxOpts.uid
- 790. - });
- 791. - },
- 792. -
- 793. - checkHtml5Uploader: function() {
- 794. - return (window.XMLHttpRequest || window.XDomainRequest) && (window.FormData || window.FileReader && (window.XMLHttpRequest && XMLHttpRequest.sendAsBinary || window.ArrayBuffer && window.Uint8Array && (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)));
- 795. - },
- 796. -
- 797. - uploadPhotos: function(obj, ev) {
- 798. - if (ev && (ev.button == 2 || ev.ctrlKey)) {
- 799. - if (photos.checkHtml5Uploader()) {
- 800. - obj.href += '&html5=1';
- 801. - }
- 802. - return true;
- 803. - }
- 804. - if (cur.uplId !== undefined && window.Upload && Upload.checked && Upload.checked[cur.uplId] && Places.checkHtml5Uploader()) {
- 805. - ge('photos_upload_input').click();
- 806. - return false;
- 807. - }
- 808. - return true;
- 809. - },
- 810. -
- 811. - onPhotoUploadStart: function(info, res) {
- 812. - var label = ge('places_photo_upload_area_label');
- 813. - setStyle(label, {background: 'none', paddingLeft: '0px'});
- 814. - label.innerHTML = '<div id="places_ph_add_progress"><div id="places_add_p_line"><div id="places_add_p_inner"></div></div><div id="places_add_p_str"></div></div>';
- 815. - if (info.num === undefined) {
- 816. - info = res;
- 817. - }
- 818. - if (info.totalCount > 1) {
- 819. - ge('places_add_p_str').innerHTML = langNumeric(info.num ? info.num + 1 : 1, cur.lang['photos_add_uploading_num_X']).replace('{count}', info.totalCount);
- 820. - } else {
- 821. - ge('places_add_p_str').innerHTML = getLang('photos_add_uploading');
- 822. - }
- 823. - },
- 824. -
- 825. - onPhotoUploadProgress: function(ind, upl, need) {
- 826. - var inner = ge('places_add_p_inner');
- 827. - var w = (upl / need) * 175;
- 828. - var oldWidth = intval(inner.style.width);
- 829. - if (ind.totalCount > 1) {
- 830. - ge('places_add_p_str').innerHTML = langNumeric(ind.num + 1, cur.lang['photos_add_uploading_num_X']).replace('{count}', ind.totalCount);
- 831. - }
- 832. - if (w > oldWidth) {
- 833. - animate(inner, {width: w}, 200);
- 834. - }
- 835. - },
- 836. -
- 837. - onPhotoUploadComplete: function(info, res) {
- 838. - var params, i = info.ind !== undefined ? info.ind : info;
- 839. - try {
- 840. - params = eval('(' + res + ')');
- 841. - } catch(e) {
- 842. - params = q2ajx(res);
- 843. - }
- 844. - cur.savedPhotos = cur.savedPhotos || {mid: params.mid, gid: params.gid, aid: params.aid, server: params.server};
- 845. - cur.savedPhotos.photos = cur.savedPhotos.photos || [];
- 846. - cur.savedPhotos.photos.push({photo: params.photos, hash: params.hash});
- 847. - return;
- 848. - },
- 849. -
- 850. - onPhotoUploadCompleteAll: function(info) {
- 851. - var query = {act: 'done_add', context: 1, from: 'profile_map'}, k = 1;
- 852. -
- 853. - if (!cur.savedPhotos.photos) {
- 854. - return;
- 855. - }
- 856. - for (var j in (cur.savedPhotos.photos || [])) {
- 857. - query['photo'+k] = cur.savedPhotos.photos[j].photo;
- 858. - query['hash'+k] = cur.savedPhotos.photos[j].hash;
- 859. - k++;
- 860. - }
- 861. - delete cur.savedPhotos.photos;
- 862. - query = extend(query, cur.savedPhotos);
- 863. - ajax.post('/al_photos.php', query, {
- 864. - onDone: function(photos, hash, oid, photoPreview) {
- 865. - Places.selectPhoto(photos, photoPreview);
- 866. - },
- 867. - onFail: function(text) {
- 868. - setTimeout(showFastBox(getLang('global_error'), text).hide, __debugMode ? 30000 : 3000);
- 869. - }
- 870. - })
- 871. - },
- 872. -
- 873. - showPlaceTT: function(obj, text) {
- 874. - showTooltip(obj, {black: 1, text: text, center:1, shift:[0, 4, 0]});
- 875. - },
- 876. -
- 877. - showPhotoPlace: function(lat, lng) {
- 878. - var map = cur.placeBoxMap;
- 879. - map.setCenter(new google.maps.LatLng(lat, lng));
- 880. - map.setZoom(16);
- 881. - animate(boxLayerWrap, {scrollTop: 0}, 200);
- 882. - }
- 883. -
- 884. - }
- 885. -
- 886. - try{stManager.done('places.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment