Guest User

Untitled

a guest
Jul 19th, 2018
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.59 KB | None | 0 0
  1. Uncaught TypeError: Cannot read property 'parentNode' of null
  2. at USGSOverlay.onRemove (add:695)
  3. at Iu.ug (overlay.js:4)
  4. at Ku (overlay.js:1)
  5. at Object.qk (overlay.js:5)
  6. at js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o:151
  7. at Object._.S (js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o:64)
  8. at USGSOverlay._.jg.map_changed (js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o:151)
  9. at Qc (js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o:51)
  10. at USGSOverlay._.m.set (js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o:124)
  11. at USGSOverlay.setMap (js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o:54)
  12.  
  13. {% block map_widget %}
  14. {% set lat = form.children.lat.vars.value %}
  15. {% set lng = form.children.lng.vars.value %}
  16. {% set zoom = form.children.zoom.vars.value %}
  17.  
  18. <div class="iframe-container">
  19. <div id="{{form.vars.id}}"></div>
  20. </div>
  21.  
  22. {{ form_row(form.lat) }}
  23. {{ form_row(form.lng) }}
  24. {{ form_row(form.zoom) }}
  25. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAKngEjzSoLW2g7nDnxedV0Bu08o"></script>
  26. <script src="{{ asset('admin/js/interact.min.js') }}"></script>
  27. <script>
  28.  
  29. var overlay;
  30. var globalMap;
  31.  
  32. USGSOverlay.prototype = new google.maps.OverlayView();
  33.  
  34. function initMap() {
  35. var lat = parseFloat('{{lat}}'.replace(/,/g, '.'));
  36. var lng = parseFloat('{{lng}}'.replace(/,/g, '.'));
  37. var styles = //тут код...
  38.  
  39. var map = new google.maps.Map(document.getElementById('{{form.vars.id}}'), {
  40. zoom: {{zoom}},
  41. center: { lat: lat, lng: lng },
  42. mapTypeId: 'satellite',
  43. styles: styles,
  44. markers: []
  45. });
  46.  
  47. google.maps.event.addDomListener(map, 'center_changed', function() {
  48. $('#{{form.children.lat.vars.id}}').val(map.getCenter().lat());
  49. $('#{{form.children.lng.vars.id}}').val(map.getCenter().lng());
  50. $('#{{form.children.lat.vars.id}}').change();
  51. $('#{{form.children.lng.vars.id}}').change();
  52. });
  53.  
  54. google.maps.event.addDomListener(map, 'zoom_changed', function() {
  55. $('#{{form.children.zoom.vars.id}}').val(map.getZoom());
  56. $('#{{form.children.zoom.vars.id}}').change();
  57. if(overlay){
  58. if(overlay.img && overlay.div_){
  59. overlay.div_.style.width = 'none';
  60. overlay.img.style.width = '100%';
  61. overlay.img.style.height = '100%';
  62. }
  63. }
  64. });
  65.  
  66. globalMap = map;
  67.  
  68. }
  69.  
  70.  
  71. /** @constructor */
  72. function USGSOverlay(bounds, image, map, id, fixed = true, floor = null, addingLine = null) {
  73. // Initialize all properties.
  74. this.bounds_ = bounds;
  75. this.startZoom = {{zoom}};
  76. this.image_ = image;
  77. this.map_ = map;
  78. this.id_ = id;
  79. this.listeners = {};
  80. this.data = {
  81. lat : '',
  82. lng : '',
  83. zoom : '',
  84. width : '',
  85. height : ''
  86. };
  87.  
  88. this.div_ = null;
  89. this.dragflag = false;
  90. this.img = null;
  91. this.fixed = fixed;
  92. this.floorId = floor;
  93.  
  94. this.creatingPath = false;
  95. this.pointFrom = null;
  96. this.paths = new google.maps.Polyline({
  97. strokeColor: '#000000',
  98. strokeOpacity: 1,
  99. strokeWeight: 3,
  100. map: map
  101. //editable: true
  102. //draggable: true
  103. });
  104. this.connections = [];
  105. this.lines = [];
  106. this.addingLine = addingLine;
  107. this.connectionData = {};
  108. this.connection = {};
  109.  
  110. // Explicitly call setMap on this overlay.
  111. this.setMap(map);
  112.  
  113. if(addingLine){
  114. this.creatingPath = true;
  115. }
  116. }
  117.  
  118. /**
  119. * onAdd is called when the map's panes are ready and the overlay has
  120. */
  121. USGSOverlay.prototype.onAdd = function() {
  122.  
  123. var div = document.createElement('div');
  124. div.style.position = 'absolute';
  125. div.style.opacity = 0.9;
  126.  
  127. div.style.outline = '2px solid #000000';
  128.  
  129.  
  130. // Create the img element and attach it to the div.
  131. var img = document.createElement('img');
  132. img.src = this.image_;
  133. img.style.width = '100%';
  134. img.style.height = '100%';
  135. img.style.position = 'absolute';
  136.  
  137. div.appendChild(img);
  138. this.img = img;
  139.  
  140. var me = this;
  141.  
  142. google.maps.event.addDomListener(img, 'mouseover', function() {
  143. if(!me.fixed){
  144. me.map_.setOptions({draggable:false});
  145. }
  146. });
  147.  
  148. google.maps.event.addDomListener(img, 'mouseout', function() {
  149. me.map_.setOptions({draggable:true});
  150. });
  151.  
  152. interact(img).draggable({
  153. onmove: window.dragMoveListener
  154. })
  155. .resizable({
  156. preserveAspectRatio: true,
  157. edges: { left: true, right: true, bottom: true, top: true }
  158. })
  159. .on('dragend', function(event){
  160.  
  161. var left = parseFloat(div.style.left, 10);
  162. var top = parseFloat(div.style.top, 10);
  163.  
  164. var x = (left + parseFloat(img.dataset.x, 10));
  165. var y = (top + parseFloat(img.dataset.y, 10));
  166.  
  167. div.style.left = x+'px';
  168. div.style.top = y+'px';
  169. img.style.webkitTransform = img.style.transform = 'translate(0px,0px)';
  170. img.dataset.x = 0;
  171. img.dataset.y = 0;
  172.  
  173. me.dragflag = true;
  174.  
  175. var rect = event.interactable.getRect();
  176. var point1 = new google.maps.Point(x, div.offsetHeight+y);
  177. var point2 = new google.maps.Point(x+div.offsetWidth, y);
  178. var overlayProjection = me.getProjection();
  179.  
  180. var sw = overlayProjection.fromDivPixelToLatLng(point1);
  181. var ne = overlayProjection.fromDivPixelToLatLng(point2);
  182. me.bounds_ = new google.maps.LatLngBounds(
  183. new google.maps.LatLng(sw.lat(), sw.lng()),
  184. new google.maps.LatLng(ne.lat(), ne.lng())
  185. );
  186. var point = new google.maps.Point(x, y);
  187. var latlng = overlayProjection.fromDivPixelToLatLng(point);
  188. me.changeOverlay(latlng, img);
  189. })
  190. .on('resizemove', function (event) {
  191. var target = event.target,
  192. x = (parseFloat(target.getAttribute('data-x')) || 0),
  193. y = (parseFloat(target.getAttribute('data-y')) || 0);
  194.  
  195. div.style.width = target.style.width = event.rect.width + 'px';
  196. div.style.height = target.style.height = event.rect.height + 'px';
  197.  
  198. // translate when resizing from top or left edges
  199. x += event.deltaRect.left;
  200. y += event.deltaRect.top;
  201.  
  202. target.setAttribute('data-x', x);
  203. target.setAttribute('data-y', y);
  204. me.map_.setOptions({draggable:true});
  205.  
  206. div.style.left += event.deltaRect.left + 'px';
  207. div.style.top += event.deltaRect.top + 'px';
  208. div.style.webkitTransform = div.style.transform = 'translate(' + x + 'px,' + y + 'px)';
  209.  
  210. var overlayProjection = me.getProjection();
  211. var point = new google.maps.Point(x, y);
  212. var latlng = overlayProjection.fromDivPixelToLatLng(point);
  213. me.dragflag = true;
  214. me.changeOverlay(latlng, img);
  215. })
  216. .on('resizeend', function (event) {
  217. var left = parseFloat(div.style.left, 10);
  218. var top = parseFloat(div.style.top, 10);
  219. var point1 = new google.maps.Point(left, div.offsetHeight + top);
  220. var point2 = new google.maps.Point(left + div.offsetWidth, top);
  221. var overlayProjection = me.getProjection();
  222.  
  223. var sw = overlayProjection.fromDivPixelToLatLng(point1);
  224. var ne = overlayProjection.fromDivPixelToLatLng(point2);
  225.  
  226. me.bounds_ = new google.maps.LatLngBounds(
  227. new google.maps.LatLng(sw.lat(), sw.lng()),
  228. new google.maps.LatLng(ne.lat(), ne.lng())
  229. );
  230.  
  231. var x = (left + parseFloat(img.dataset.x, 10));
  232. var y = (top + parseFloat(img.dataset.y, 10));
  233. var point = new google.maps.Point(x, y);
  234. var latlng = overlayProjection.fromDivPixelToLatLng(point);
  235. me.changeOverlay(latlng, img);
  236. });
  237.  
  238. this.div_ = div;
  239.  
  240. //var panes = this.getPanes();
  241. //panes.overlayLayer.appendChild(div);
  242. //panes.overlayMouseTarget.appendChild(div);
  243.  
  244. //if(this.fixed){
  245. this.toogleEdit();
  246. //}
  247.  
  248. };
  249.  
  250. USGSOverlay.prototype.draw = function() {
  251.  
  252. // We use the south-west and north-east
  253. // coordinates of the overlay to peg it to the correct position and size.
  254. // To do this, we need to retrieve the projection from the overlay.
  255. var overlayProjection = this.getProjection();
  256. // Retrieve the south-west and north-east coordinates of this overlay
  257. // in LatLngs and convert them to pixel coordinates.
  258. // We'll use these coordinates to resize the div.
  259. var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
  260. var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());
  261.  
  262. // Resize the image's div to fit the indicated dimensions.
  263. var div = this.div_;
  264. div.style.left = sw.x + 'px';
  265. div.style.top = ne.y + 'px';
  266. div.style.width = (ne.x - sw.x) + 'px';
  267. div.style.height = (sw.y - ne.y) + 'px';
  268.  
  269. //var overlayProjection = this.getProjection();
  270.  
  271. var point = new google.maps.Point(sw.x, ne.y);
  272. var latlng = overlayProjection.fromDivPixelToLatLng(point);
  273. this.onAdded(latlng, this.img);
  274.  
  275. //this.changeOverlay(this.bounds_.getCenter(), this.img);
  276. };
  277.  
  278. USGSOverlay.prototype.onRemove = function() {
  279. this.div_.parentNode.removeChild(this.div_);
  280. this.div_ = null;
  281. };
  282.  
  283. USGSOverlay.prototype.listeners = null;
  284. USGSOverlay.prototype.addEventListener = function(type, callback) {
  285. if (!(type in this.listeners)) {
  286. this.listeners[type] = [];
  287. }
  288. this.listeners[type].push(callback);
  289. };
  290.  
  291. USGSOverlay.prototype.removeEventListener = function(type, callback) {
  292. if (!(type in this.listeners)) {
  293. return;
  294. }
  295. var stack = this.listeners[type];
  296. for (var i = 0, l = stack.length; i < l; i++) {
  297. if (stack[i] === callback){
  298. stack.splice(i, 1);
  299. return;
  300. }
  301. }
  302. };
  303.  
  304. USGSOverlay.prototype.dispatchEvent = function(event) {
  305. if (!(event.type in this.listeners)) {
  306. return true;
  307. }
  308. var stack = this.listeners[event.type];
  309. event.target = this;
  310. for (var i = 0, l = stack.length; i < l; i++) {
  311. stack[i].call(this, event);
  312. }
  313. return !event.defaultPrevented;
  314. };
  315.  
  316. USGSOverlay.prototype.changeOverlay = function(latlng, img){
  317.  
  318. this.data.lat = latlng.lat();
  319. this.data.lng = latlng.lng();
  320. this.data.zoom = this.map_.getZoom();
  321.  
  322. if(img.width == 0){
  323. this.data.width = img.naturalWidth;
  324. }else{
  325. this.data.width = img.width;
  326. }
  327.  
  328. if(img.height == 0){
  329. this.data.height = img.naturalHeight;
  330. }else{
  331. this.data.height = img.height;
  332. }
  333.  
  334. var event = new Event('changed');
  335. this.dispatchEvent(event);
  336. };
  337.  
  338. USGSOverlay.prototype.onAdded = function(latlng, img) {
  339. this.data.lat = latlng.lat();
  340. this.data.lng = latlng.lng();
  341. this.data.zoom = this.map_.getZoom();
  342.  
  343. if(img.width == 0){
  344. this.data.width = img.naturalWidth;
  345. }else{
  346. this.data.width = img.width;
  347. }
  348.  
  349. if(img.height == 0){
  350. this.data.height = img.naturalHeight;
  351. }else{
  352. this.data.height = img.height;
  353. }
  354.  
  355. var event = new Event('added');
  356. this.dispatchEvent(event);
  357. };
  358.  
  359. USGSOverlay.prototype.drawConnections = function(points){
  360.  
  361. for (var i = 0; i < points.length; i++) {
  362. var point = points[i];
  363. this.createMarker(point[0], parseFloat(point[1]), parseFloat(point[2]), point.connections, point.icon);
  364. }
  365.  
  366. return null;
  367. };
  368.  
  369. USGSOverlay.prototype.createMarker = function(id, lat, lng, connections = null, image = null){
  370. var icon = null;
  371. if(image){
  372. icon = {
  373. url: image.url,
  374. size: new google.maps.Size(30, 30),
  375. scaledSize: new google.maps.Size(30, 30),
  376. anchor: new google.maps.Point(15, 30)
  377. };
  378. }else{
  379. icon = {
  380. url: "{{asset('admin/img/point_path.svg')}}",
  381. size: new google.maps.Size(20, 20),
  382. scaledSize: new google.maps.Size(20, 20),
  383. anchor: new google.maps.Point(10, 10)
  384. };
  385. }
  386. var marker = new google.maps.Marker({
  387. position: {lat: lat, lng: lng},
  388. icon: icon,
  389. map: this.map_,
  390. draggable: true,
  391. opacity: 1,
  392. id: id,
  393. connections: connections
  394. });
  395.  
  396. if(connections){
  397. for(var i = 0; i < connections.length; i++){
  398. var exists = false;
  399. for(var j = 0; j < this.connections.length; j++) {
  400. if (this.connections[j].id == connections[i].id) {
  401. exists = true;
  402. break;
  403. }
  404. }
  405.  
  406. if(!exists){
  407. this.connections.push(connections[i]);
  408.  
  409. var latlng1 = new google.maps.LatLng({lat: parseFloat(connections[i].from_lat), lng: parseFloat(connections[i].from_lng) });
  410. var latlng2 = new google.maps.LatLng({lat: parseFloat(connections[i].to_lat), lng: parseFloat(connections[i].to_lng)});
  411.  
  412. var line = createLine(this.map_, latlng1, latlng2, connections[i].from_id, connections[i].to_id, connections[i].id);
  413. this.lines.push(line);
  414. }
  415. }
  416. }
  417.  
  418. var me = this;
  419. marker.addListener('click', function(event){
  420. var currentId = this.get('id');
  421. currentPointId = currentId;
  422.  
  423. if(me.creatingPath){
  424.  
  425. me.pointFrom.setOptions({
  426. draggable: true,
  427. opacity: 1
  428. });
  429.  
  430. var pointTo = me.map_.getMarker(currentId);
  431. var distance = parseInt(google.maps.geometry.spherical.computeDistanceBetween( me.pointFrom.getPosition(), pointTo.getPosition() ));
  432.  
  433. me.connectionData = {
  434. fromId: me.pointFrom.get("id"),
  435. toId: currentId,
  436. distance: distance
  437. };
  438. $("#connection-distance").val(distance);
  439. $("#connection-create-btn").data('edit', 0);
  440. $("#connection-modal").modal('show');
  441. }else{
  442. $.ajax({
  443. url: '{{ path('admin_points_edit') }}/'+currentId,
  444. type: 'GET',
  445. dataType: 'html',
  446. data: { id: currentId },
  447. success:function(data){
  448. $("#point-modal").modal('show');
  449. var $data = $($.parseHTML(data));
  450. $data.find("#appbundle_point_floor").val(me.floorId);
  451. if($data.find("#appbundle_point_code").val()){
  452. $data.find("#appbundle_point_code_container").show();
  453. $data.find("#appbundle_point_code_buttons").css('display', 'inline-block');
  454. }
  455. $("#point-modal .modal-body").html($data);
  456.  
  457. $("#point-create-btn").hide();
  458. $("#point-edit-btn").show();
  459. $("#point-remove-btn").show();
  460. $("#point-modal").modal('show');
  461. }
  462. });
  463. }
  464. });
  465.  
  466.  
  467. marker.addListener('drag', function(event){
  468. var data = {
  469. id: this.get('id'),
  470. lat: this.position.lat(),
  471. lng: this.position.lng()
  472. };
  473.  
  474. for(var i = 0; i < me.lines.length; i++){
  475. if(data.id == me.lines[i].from){
  476. var latlng = new google.maps.LatLng({lat: data.lat, lng: data.lng});
  477. var paths = me.lines[i].getPath();
  478. paths.setAt(0, latlng);
  479. }
  480. if(data.id == me.lines[i].to){
  481. var latlng = new google.maps.LatLng({lat: data.lat, lng: data.lng});
  482. var paths = me.lines[i].getPath();
  483. paths.setAt(1, latlng);
  484. }
  485. }
  486.  
  487. });
  488.  
  489. marker.addListener('dragend', function(event){
  490. var data = {
  491. id: this.get('id'),
  492. lat: this.position.lat(),
  493. lng: this.position.lng(),
  494. };
  495.  
  496. $.ajax({
  497. url: '{{ path('admin_points_change_position') }}',
  498. type: 'POST',
  499. dataType: 'json',
  500. data: data,
  501. success:function(data){
  502. if(data !== 'ok'){
  503. alert("error");
  504. }
  505. }
  506. });
  507.  
  508. });
  509.  
  510. this.map_.markers.push(marker);
  511. this.map_.setOptions({draggable:true});
  512. };
  513.  
  514.  
  515. USGSOverlay.prototype.updateMarker = function(id, lat, lng, connections = null, image = null){
  516. var icon = null;
  517. if(image){
  518. icon = {
  519. url: image.url,
  520. size: new google.maps.Size(30, 30),
  521. scaledSize: new google.maps.Size(30, 30),
  522. anchor: new google.maps.Point(15, 30)
  523. };
  524. }else{
  525. icon = {
  526. url: "{{asset('admin/img/point_path.svg')}}",
  527. size: new google.maps.Size(20, 20),
  528. scaledSize: new google.maps.Size(20, 20),
  529. anchor: new google.maps.Point(10, 10)
  530. };
  531. }
  532. var marker = this.map_.getMarker(id);
  533. marker.setIcon(icon);
  534. };
  535.  
  536. USGSOverlay.prototype.createPath = function(point){
  537.  
  538. var marker = this.map_.getMarker(point);
  539. marker.setOptions({
  540. draggable: false,
  541. opacity: 0.8
  542. });
  543.  
  544. this.creatingPath = true;
  545. this.pointFrom = marker;
  546.  
  547. this.addingLine = createLine(this.map_, this.pointFrom.position, this.pointFrom.position, marker.id);
  548. google.maps.event.addListener(this.map_, 'mousemove', pathCreatorListener);
  549.  
  550. };
  551.  
  552. function pathCreatorListener(event){
  553. overlay.pathListener(event);
  554. }
  555.  
  556. USGSOverlay.prototype.pathListener = function(event){
  557. var paths = this.addingLine.getPath();
  558. paths.setAt(1, event.latLng);
  559. };
  560.  
  561.  
  562. USGSOverlay.prototype.toogleEdit = function() {
  563. var img = this.div_.getElementsByTagName('img')[0];
  564. var panes = this.getPanes();
  565.  
  566. if(this.fixed){
  567. panes.overlayLayer.appendChild(this.div_);
  568. //this.div_.style.borderStyle = 'none';
  569. //this.div_.style.borderWidth = '0px';
  570. this.div_.style.outline = '0px solid #000000';
  571. this.fixed = true;
  572. interact(img).draggable(false);
  573. }else{
  574. panes.overlayMouseTarget.appendChild(this.div_);
  575. //this.div_.style.borderStyle = 'solid';
  576. //this.div_.style.borderWidth = '1px';
  577. this.div_.style.outline = '2px solid #000000';
  578. this.fixed = false;
  579. interact(img).draggable(true);
  580. }
  581. }
  582.  
  583. USGSOverlay.prototype.removePoint = function(id) {
  584. var marker = this.map_.getMarker(id);
  585.  
  586. if(marker.connections){
  587.  
  588. for(var i = 0; i < marker.connections.length; i++){
  589. for(var j = 0; j < this.connections.length; j++) {
  590. if (this.connections[j].id == marker.connections[i].id) {
  591. var connectionToRemove = this.connections[j];
  592. this.connections.splice(j, 1);
  593. for(var k = 0; k < this.lines.length; k++){
  594. //var line = this.lines[k];
  595. if(this.lines[k].id == connectionToRemove.id){
  596. this.lines[k].setMap(null);
  597. this.lines.splice(k, 1);
  598. }
  599. }
  600.  
  601. }
  602. }
  603. }
  604.  
  605. }
  606.  
  607. marker.setMap(null);
  608. };
  609.  
  610. USGSOverlay.prototype.createConnection = function(data) {
  611. if(this.pointFrom){
  612. var pointFrom = this.pointFrom;
  613. }else{
  614. var pointFrom = this.map_.getMarker(data.fromId);
  615. }
  616. var pointTo = this.map_.getMarker(data.toId);
  617. var me = this;
  618. $.ajax({
  619. url: '{{path('admin_points_connect')}}',
  620. type: 'POST',
  621. dataType: 'json',
  622. data: {
  623. pointA: data.fromId,
  624. pointB: data.toId,
  625. distance: data.distance
  626. },
  627. success:function(id){
  628.  
  629. var line = createLine(me.map_, pointFrom.getPosition(), pointTo.getPosition(), data.fromId, data.toId, id);
  630. me.lines.push(line);
  631. if(!pointFrom.connections){
  632. pointFrom.connections = []
  633. }
  634. if(!pointTo.connections){
  635. pointTo.connections = []
  636. }
  637.  
  638. pointFrom.connections.push({
  639. distance: data.distance,
  640. from_id: data.fromId,
  641. from_lat: pointFrom.getPosition().lat(),
  642. from_lng: pointFrom.getPosition().lng(),
  643. id: id,
  644. to_id: data.toId,
  645. to_lat: pointTo.getPosition().lat(),
  646. to_lng: pointTo.getPosition().lng()
  647. });
  648.  
  649. pointTo.connections.push({
  650. distance: data.distance,
  651. from_id: data.fromId,
  652. from_lat: pointFrom.getPosition().lat(),
  653. from_lng: pointFrom.getPosition().lng(),
  654. id: id,
  655. to_id: data.toId,
  656. to_lat: pointTo.getPosition().lat(),
  657. to_lng:pointTo.getPosition().lng()
  658. });
  659.  
  660. google.maps.event.clearListeners(me.map_, 'mousemove');
  661. me.pointFrom = null;
  662. me.addingLine.setMap(null);
  663. me.addingLine = null;
  664. me.creatingPath = false;
  665.  
  666. me.connections.push({
  667. distance: data.distance,
  668. from_id: data.fromId,
  669. from_lat: pointFrom.getPosition().lat(),
  670. from_lng: pointFrom.getPosition().lng(),
  671. id: id,
  672. to_id: data.toId,
  673. to_lat: pointTo.getPosition().lat(),
  674. to_lng: pointTo.getPosition().lng()
  675. });
  676. }
  677. });
  678. };
  679.  
  680. USGSOverlay.prototype.updateConnection = function(data) {
  681. var me = this;
  682. var distance = data.distance;
  683. $.ajax({
  684. url: '{{path('admin_points_connect_update')}}',
  685. type: 'POST',
  686. dataType: 'json',
  687. data: data,
  688. success:function(id){
  689. for(var i = 0; i < me.connections.length; i++) {
  690. if (me.connections[i].id == id) {
  691. me.connections[i].distance = distance;
  692. }
  693. }
  694. }
  695. });
  696. };
  697.  
  698. USGSOverlay.prototype.removeConnection = function(data) {
  699. var me = this;
  700. var id = data.id;
  701. $.ajax({
  702. url: '{{path('admin_points_connect_remove')}}',
  703. type: 'POST',
  704. dataType: 'json',
  705. data: data,
  706. success:function(response){
  707.  
  708. for(var i = 0; i < me.connections.length; i++) {
  709. if (me.connections[i].id == id) {
  710.  
  711. me.connections.splice(i, 1);
  712. for(var j = 0; j < me.lines.length; j++){
  713. if(me.lines[j].id == id){
  714. me.lines[j].setMap(null);
  715. me.lines.splice(j, 1);
  716. }
  717. }
  718.  
  719. }
  720. }
  721.  
  722. }
  723. });
  724.  
  725. };
  726.  
  727. USGSOverlay.prototype.cancelCreateConnection = function() {
  728. google.maps.event.clearListeners(this.map_, 'mousemove');
  729. this.pointFrom = null;
  730. if(this.addingLine){
  731. this.addingLine.setMap(null);
  732. this.addingLine = null;
  733. }
  734. this.creatingPath = false;
  735. };
  736.  
  737. USGSOverlay.prototype.clearConnections = function() {
  738. for(var i = 0; i < this.lines.length; i++){
  739. this.lines[i].setMap(null);
  740. }
  741. this.lines = [];
  742. this.connections = [];
  743. };
  744.  
  745. function dragMoveListener (event) {
  746. var target = event.target,
  747. // keep the dragged position in the data-x/data-y attributes
  748. x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
  749. y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
  750.  
  751. // translate the element
  752. target.style.webkitTransform =
  753. target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
  754.  
  755. // update the posiion attributes
  756. target.setAttribute('data-x', x);
  757. target.setAttribute('data-y', y);
  758. }
  759. window.dragMoveListener = dragMoveListener;
  760. google.maps.event.addDomListener(window, 'load', initMap);
  761.  
  762. google.maps.Map.prototype.clearMarkers = function() {
  763. for(var i=0; i < this.markers.length; i++){
  764. this.markers[i].setMap(null);
  765. }
  766. this.markers = new Array();
  767. };
  768.  
  769. google.maps.Map.prototype.getMarker = function(id) {
  770. for(var i=0; i < this.markers.length; i++){
  771. if(this.markers[i].id == id){
  772. return this.markers[i];
  773. }
  774. //this.markers[i].setMap(null);
  775. }
  776. return null;
  777. };
  778.  
  779. function createLine(map, latlng1, latlng2, from_id, to_id, id) {
  780.  
  781. var line = new google.maps.Polyline({
  782. strokeColor: '#000000',
  783. strokeOpacity: 1,
  784. strokeWeight: 3,
  785. path: [latlng1, latlng2]
  786. });
  787.  
  788. line.from = from_id;
  789. line.to = to_id;
  790. line.id = id;
  791.  
  792. google.maps.event.addListener(line, 'click', function(h) {
  793. $("#connection-create-btn").data('edit', 1);
  794. $("#connection-create-btn").data('connection', id);
  795. $("#connection-remove-btn").show();
  796.  
  797. for (var i = 0; i < overlay.connections.length; i++) {
  798. if (overlay.connections[i].id == id){
  799. $("#connection-distance").val(overlay.connections[i].distance);
  800. break;
  801. }
  802. }
  803. $("#connection-modal").modal('show');
  804. });
  805.  
  806. line.setMap(map);
  807.  
  808. return line;
  809. }
  810.  
  811. </script>
Add Comment
Please, Sign In to add comment