WME Utils - Google Link Enhancer

Adds some extra WME functionality related to Google place links.

当前为 2023-03-11 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/39208/1160225/WME%20Utils%20-%20Google%20Link%20Enhancer.js

  1. // ==UserScript==
  2. // @name WME Utils - Google Link Enhancer
  3. // @namespace WazeDev
  4. // @version 2023.03.11.001
  5. // @description Adds some extra WME functionality related to Google place links.
  6. // @author MapOMatic, WazeDev group
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @license GNU GPLv3
  9. // ==/UserScript==
  10.  
  11. /* global OpenLayers */
  12. /* global W */
  13. /* global google */
  14.  
  15. // /* eslint-disable */
  16. /* eslint-disable no-unused-vars */
  17. class GoogleLinkEnhancer {
  18. #DISABLE_CLOSED_PLACES = false; // Set to TRUE if the feature needs to be temporarily disabled, e.g. during the COVID-19 pandemic.
  19. #EXT_PROV_ELEM_QUERY = 'wz-list-item.external-provider';
  20. #EXT_PROV_ELEM_EDIT_QUERY = 'wz-list-item.external-provider-edit';
  21. #EXT_PROV_ELEM_CONTENT_QUERY = 'div.external-provider-content';
  22. #LINK_CACHE_NAME = 'gle_link_cache';
  23. #LINK_CACHE_CLEAN_INTERVAL_MIN = 1; // Interval to remove old links and save new ones.
  24. #LINK_CACHE_LIFESPAN_HR = 6; // Remove old links when they exceed this time limit.
  25.  
  26. #linkCache;
  27. #enabled = false;
  28. #disableApiUntil = null; // When a serious API error occurs (OVER_QUERY_LIMIT, REQUEST_DENIED), set this to a time in the future.
  29. #mapLayer = null;
  30. #distanceLimit = 400; // Default distance (meters) when Waze place is flagged for being too far from Google place.
  31. // Area place is calculated as #distanceLimit + <distance between centroid and furthest node>
  32. #showTempClosedPOIs = true;
  33. #placesService;
  34. #linkObserver;
  35. #modeObserver;
  36. #searchResultsObserver;
  37. #lzString;
  38. #cacheCleanIntervalID;
  39. #originalHeadAppendChildMethod;
  40. #ptFeature;
  41. #lineFeature;
  42. #timeoutID;
  43. strings = {
  44. permClosedPlace: 'Google indicates this place is permanently closed.\nVerify with other sources or your editor community before deleting.',
  45. tempClosedPlace: 'Google indicates this place is temporarily closed.',
  46. multiLinked: 'Linked more than once already. Please find and remove multiple links.',
  47. linkedToThisPlace: 'Already linked to this place',
  48. linkedNearby: 'Already linked to a nearby place',
  49. linkedToXPlaces: 'This is linked to {0} places',
  50. badLink: 'Invalid Google link. Please remove it.',
  51. tooFar: 'The Google linked place is more than {0} meters from the Waze place. Please verify the link is correct.'
  52. };
  53.  
  54. /* eslint-enable no-unused-vars */
  55. constructor() {
  56. const attributionElem = document.createElement('div');
  57. this.#placesService = new google.maps.places.PlacesService(attributionElem);
  58. this.#initLZString();
  59. const STORED_CACHE = localStorage.getItem(this.#LINK_CACHE_NAME);
  60. try {
  61. this.#linkCache = STORED_CACHE ? $.parseJSON(this.#lzString.decompressFromUTF16(STORED_CACHE)) : {};
  62. } catch (ex) {
  63. if (ex.name === 'SyntaxError') {
  64. // In case the cache is corrupted and can't be read.
  65. this.#linkCache = {};
  66. console.warn('GoogleLinkEnhancer:', 'An error occurred while loading the stored cache. A new cache was created.');
  67. } else {
  68. throw ex;
  69. }
  70. }
  71. if (this.#linkCache === null || this.#linkCache.length === 0) this.#linkCache = {};
  72.  
  73. this.#initLayer();
  74.  
  75. // NOTE: Arrow functions are necessary for calling methods on object instances.
  76. // This could be made more efficient by only processing the relevant places.
  77. W.model.events.register('mergeend', null, () => { this.#processPlaces(); });
  78. W.model.venues.on('objectschanged', () => { this.#processPlaces(); });
  79. W.model.venues.on('objectsremoved', () => { this.#processPlaces(); });
  80. W.model.venues.on('objectsadded', () => { this.#processPlaces(); });
  81.  
  82. // Watch for ext provider elements being added to the DOM, and add hover events.
  83. this.#linkObserver = new MutationObserver(mutations => {
  84. mutations.forEach(mutation => {
  85. for (let idx = 0; idx < mutation.addedNodes.length; idx++) {
  86. const nd = mutation.addedNodes[idx];
  87. if (nd.nodeType === Node.ELEMENT_NODE) {
  88. const $el = $(nd);
  89. const $subel = $el.find(this.#EXT_PROV_ELEM_QUERY);
  90. if ($el.is(this.#EXT_PROV_ELEM_QUERY)) {
  91. this.#addHoverEvent($el);
  92. this.#formatLinkElements();
  93. } else if ($subel.length) {
  94. for (let i = 0; i < $subel.length; i++) {
  95. this.#addHoverEvent($($subel[i]));
  96. }
  97. this.#formatLinkElements();
  98. }
  99. if ($el.is(this.#EXT_PROV_ELEM_EDIT_QUERY)) {
  100. this.#searchResultsObserver.observe($el.find('wz-autocomplete[placeholder="Search for a place"]')[0].shadowRoot, { childList: true, subtree: true });
  101. }
  102. }
  103. }
  104. for (let idx = 0; idx < mutation.removedNodes.length; idx++) {
  105. const nd = mutation.removedNodes[idx];
  106. if (nd.nodeType === Node.ELEMENT_NODE) {
  107. const $el = $(nd);
  108. if ($el.is(this.#EXT_PROV_ELEM_EDIT_QUERY)) {
  109. this.#searchResultsObserver.disconnect();
  110. }
  111. }
  112. }
  113. });
  114. });
  115.  
  116. // Watch for Google place search result list items being added to the DOM
  117. const that = this;
  118. this.#searchResultsObserver = new MutationObserver(mutations => {
  119. mutations.forEach(mutation => {
  120. for (let idx = 0; idx < mutation.addedNodes.length; idx++) {
  121. const nd = mutation.addedNodes[idx];
  122. if (nd.nodeType === Node.ELEMENT_NODE && $(nd).is('wz-menu-item.simple-item')) {
  123. $(nd).mouseenter(() => {
  124. // When mousing over a list item, find the Google place ID from the list that was stored previously.
  125. // Then add the point/line to the map.
  126. that.#addPoint($(nd).attr('item-id'));
  127. }).mouseleave(() => {
  128. // When leaving the list item, remove the point.
  129. that.#destroyPoint();
  130. });
  131. }
  132. }
  133. });
  134. });
  135.  
  136. // Watch the side panel for addition of the sidebar-layout div, which indicates a mode change.
  137. this.#modeObserver = new MutationObserver(mutations => {
  138. mutations.forEach(mutation => {
  139. for (let idx = 0; idx < mutation.addedNodes.length; idx++) {
  140. const nd = mutation.addedNodes[idx];
  141. if (nd.nodeType === Node.ELEMENT_NODE && $(nd).is('.sidebar-layout')) {
  142. this.#observeLinks();
  143. break;
  144. }
  145. }
  146. });
  147. });
  148.  
  149. // This is a special event that will be triggered when DOM elements are destroyed.
  150. /* eslint-disable wrap-iife, func-names, object-shorthand */
  151. (function($) {
  152. $.event.special.destroyed = {
  153. remove: function(o) {
  154. if (o.handler && o.type !== 'destroyed') {
  155. o.handler();
  156. }
  157. }
  158. };
  159. })(jQuery);
  160. /* eslint-enable wrap-iife, func-names, object-shorthand */
  161.  
  162. // In case a place is already selected on load.
  163. const selFeatures = W.selectionManager.getSelectedFeatures();
  164. if (selFeatures.length && selFeatures[0].model.type === 'venue') {
  165. this.#formatLinkElements();
  166. }
  167. }
  168.  
  169. #initLayer() {
  170. this.#mapLayer = new OpenLayers.Layer.Vector('Google Link Enhancements.', {
  171. uniqueName: '___GoogleLinkEnhancements',
  172. displayInLayerSwitcher: true,
  173. styleMap: new OpenLayers.StyleMap({
  174. default: {
  175. strokeColor: '${strokeColor}',
  176. strokeWidth: '${strokeWidth}',
  177. strokeDashstyle: '${strokeDashstyle}',
  178. pointRadius: '15',
  179. fillOpacity: '0'
  180. }
  181. })
  182. });
  183.  
  184. this.#mapLayer.setOpacity(0.8);
  185. W.map.addLayer(this.#mapLayer);
  186. }
  187.  
  188. enable() {
  189. if (!this.#enabled) {
  190. this.#modeObserver.observe($('.edit-area #sidebarContent')[0], { childList: true, subtree: false });
  191. this.#observeLinks();
  192. // Watch for JSONP callbacks. JSONP is used for the autocomplete results when searching for Google links.
  193. this.#addJsonpInterceptor();
  194. // Note: Using on() allows passing "this" as a variable, so it can be used in the handler function.
  195. $('#map').on('mouseenter', null, this, GoogleLinkEnhancer.#onMapMouseenter);
  196. $(window).on('unload', null, this, GoogleLinkEnhancer.#onWindowUnload);
  197. W.model.venues.on('objectschanged', this.#formatLinkElements, this);
  198. this.#processPlaces();
  199. this.#cleanAndSaveLinkCache();
  200. this.#cacheCleanIntervalID = setInterval(() => this.#cleanAndSaveLinkCache(), 1000 * 60 * this.#LINK_CACHE_CLEAN_INTERVAL_MIN);
  201. this.#enabled = true;
  202. }
  203. }
  204.  
  205. disable() {
  206. if (this.#enabled) {
  207. this.#modeObserver.disconnect();
  208. this.#linkObserver.disconnect();
  209. this.#searchResultsObserver.disconnect();
  210. this.#removeJsonpInterceptor();
  211. $('#map').off('mouseenter', GoogleLinkEnhancer.#onMapMouseenter);
  212. $(window).off('unload', null, this, GoogleLinkEnhancer.#onWindowUnload);
  213. W.model.venues.off('objectschanged', this.#formatLinkElements, this);
  214. if (this.#cacheCleanIntervalID) clearInterval(this.#cacheCleanIntervalID);
  215. this.#cleanAndSaveLinkCache();
  216. this.#enabled = false;
  217. }
  218. }
  219.  
  220. // The distance (in meters) before flagging a Waze place that is too far from the linked Google place.
  221. // Area places use distanceLimit, plus the distance from the centroid of the AP to its furthest node.
  222. get distanceLimit() {
  223. return this.#distanceLimit;
  224. }
  225.  
  226. set distanceLimit(value) {
  227. this.#distanceLimit = value;
  228. this.#processPlaces();
  229. }
  230.  
  231. get showTempClosedPOIs() {
  232. return this.#showTempClosedPOIs;
  233. }
  234.  
  235. set showTempClosedPOIs(value) {
  236. this.#showTempClosedPOIs = value;
  237. this.#processPlaces();
  238. }
  239.  
  240. static #onWindowUnload(evt) {
  241. evt.data.#cleanAndSaveLinkCache();
  242. }
  243.  
  244. #cleanAndSaveLinkCache() {
  245. if (!this.#linkCache) return;
  246. const now = new Date();
  247. Object.keys(this.#linkCache).forEach(id => {
  248. const link = this.#linkCache[id];
  249. // Bug fix:
  250. if (link.location) {
  251. link.loc = link.location;
  252. delete link.location;
  253. }
  254. // Delete link if older than X hours.
  255. if (!link.ts || (now - new Date(link.ts)) > this.#LINK_CACHE_LIFESPAN_HR * 3600 * 1000) {
  256. delete this.#linkCache[id];
  257. }
  258. });
  259. localStorage.setItem(this.#LINK_CACHE_NAME, this.#lzString.compressToUTF16(JSON.stringify(this.#linkCache)));
  260. // console.log('link cache count: ' + Object.keys(this.#linkCache).length, this.#linkCache);
  261. }
  262.  
  263. static #distanceBetweenPoints(x1, y1, x2, y2) {
  264. return Math.sqrt(((x1 - x2) ** 2) + ((y1 - y2) ** 2));
  265. }
  266.  
  267. #isLinkTooFar(link, venue) {
  268. if (link.loc) {
  269. const linkPt = new OpenLayers.Geometry.Point(link.loc.lng, link.loc.lat);
  270. linkPt.transform(W.Config.map.projection.remote, W.map.getProjectionObject());
  271. let venuePt;
  272. let distanceLim;
  273. if (venue.isPoint()) {
  274. venuePt = venue.geometry.getCentroid();
  275. distanceLim = this.distanceLimit;
  276. } else {
  277. const bounds = venue.geometry.getBounds();
  278. const center = bounds.getCenterLonLat();
  279. venuePt = { x: center.lon, y: center.lat };
  280. distanceLim = GoogleLinkEnhancer.#distanceBetweenPoints(center.lon, center.lat, bounds.right, bounds.top) + this.distanceLimit;
  281. }
  282. const distance = GoogleLinkEnhancer.#distanceBetweenPoints(linkPt.x, linkPt.y, venuePt.x, venuePt.y);
  283. return distance > distanceLim;
  284. }
  285. return false;
  286. }
  287.  
  288. #processPlaces() {
  289. return; // Disabled until we can find a fix.
  290. try {
  291. if (this.#enabled) {
  292. const that = this;
  293. // Get a list of already-linked id's
  294. const existingLinks = GoogleLinkEnhancer.#getExistingLinks();
  295. this.#mapLayer.removeAllFeatures();
  296. const drawnLinks = [];
  297. W.model.venues.getObjectArray().forEach(venue => {
  298. const promises = [];
  299. venue.attributes.externalProviderIDs.forEach(provID => {
  300. const id = provID.attributes.uuid;
  301.  
  302. // Check for duplicate links
  303. const linkInfo = existingLinks[id];
  304. if (linkInfo.count > 1) {
  305. const geometry = venue.isPoint() ? venue.geometry.getCentroid() : venue.geometry.clone();
  306. const width = venue.isPoint() ? '4' : '12';
  307. const color = '#fb8d00';
  308. const features = [new OpenLayers.Feature.Vector(geometry, {
  309. strokeWidth: width, strokeColor: color
  310. })];
  311. const lineStart = geometry.getCentroid();
  312. linkInfo.venues.forEach(linkVenue => {
  313. if (linkVenue !== venue
  314. && !drawnLinks.some(dl => (dl[0] === venue && dl[1] === linkVenue) || (dl[0] === linkVenue && dl[1] === venue))) {
  315. features.push(
  316. new OpenLayers.Feature.Vector(
  317. new OpenLayers.Geometry.LineString([lineStart, linkVenue.geometry.getCentroid()]),
  318. {
  319. strokeWidth: 4,
  320. strokeColor: color,
  321. strokeDashstyle: '12 12'
  322. }
  323. )
  324. );
  325. drawnLinks.push([venue, linkVenue]);
  326. }
  327. });
  328. that.#mapLayer.addFeatures(features);
  329. }
  330.  
  331. // Get Google link info, and store results for processing.
  332. promises.push(that.#getLinkInfoAsync(id));
  333. });
  334.  
  335. // Process all results of link lookups and add a highlight feature if needed.
  336. Promise.all(promises).then(results => {
  337. let strokeColor = null;
  338. let strokeDashStyle = 'solid';
  339. if (!that.#DISABLE_CLOSED_PLACES && results.some(res => res.permclosed)) {
  340. if (/^(\[|\()?(permanently )?closed(\]|\)| -)/i.test(venue.attributes.name)
  341. || /(\(|- |\[)(permanently )?closed(\)|\])?$/i.test(venue.attributes.name)) {
  342. strokeDashStyle = venue.isPoint() ? '2 6' : '2 16';
  343. }
  344. strokeColor = '#F00';
  345. } else if (results.some(res => that.#isLinkTooFar(res, venue))) {
  346. strokeColor = '#0FF';
  347. } else if (!that.#DISABLE_CLOSED_PLACES && that.#showTempClosedPOIs && results.some(res => res.tempclosed)) {
  348. if (/^(\[|\()?(temporarily )?closed(\]|\)| -)/i.test(venue.attributes.name)
  349. || /(\(|- |\[)(temporarily )?closed(\)|\])?$/i.test(venue.attributes.name)) {
  350. strokeDashStyle = venue.isPoint() ? '2 6' : '2 16';
  351. }
  352. strokeColor = '#FD3';
  353. } else if (results.some(res => res.notFound)) {
  354. strokeColor = '#F0F';
  355. }
  356. if (strokeColor) {
  357. const style = {
  358. strokeWidth: venue.isPoint() ? '4' : '12',
  359. strokeColor,
  360. strokeDashStyle
  361. };
  362. const geometry = venue.isPoint() ? venue.geometry.getCentroid() : venue.geometry.clone();
  363. that.#mapLayer.addFeatures([new OpenLayers.Feature.Vector(geometry, style)]);
  364. }
  365. });
  366. });
  367. }
  368. } catch (ex) {
  369. console.error('PIE (Google Link Enhancer) error:', ex);
  370. }
  371. }
  372.  
  373. #cacheLink(id, link) {
  374. link.ts = new Date();
  375. this.#linkCache[id] = link;
  376. // console.log('link cache count: ' + Object.keys(this.#linkCache).length, this.#linkCache);
  377. }
  378.  
  379. #getLinkInfoAsync(placeId) {
  380. return new Promise(resolve => {
  381. let link = this.#linkCache[placeId];
  382. if (!link) {
  383. const request = {
  384. placeId,
  385. fields: ['geometry', 'business_status']
  386. };
  387. this.#placesService.getDetails(request, (place, requestStatus) => {
  388. link = {};
  389. if (requestStatus === google.maps.places.PlacesServiceStatus.OK) {
  390. const loc = place.geometry.location;
  391. link.loc = { lng: loc.lng(), lat: loc.lat() };
  392. if (place.business_status === 'CLOSED_PERMANENTLY') {
  393. link.permclosed = true;
  394. } else if (place.business_status === 'CLOSED_TEMPORARILY') {
  395. link.tempclosed = true;
  396. }
  397. this.#cacheLink(placeId, link);
  398. } else if (requestStatus === google.maps.places.PlacesServiceStatus.NOT_FOUND) {
  399. link.notfound = true;
  400. this.#cacheLink(placeId, link);
  401. } else if (this.#disableApiUntil) {
  402. link.apiDisabled = true;
  403. } else {
  404. link.error = requestStatus;
  405. // res.errorMessage = json.error_message;
  406. this.#disableApiUntil = Date.now() + 10 * 1000; // Disable api calls for 10 seconds.
  407. console.error(`${GM_info.script.name}, Google Link Enhancer disabled for 10 seconds due to API error.`, link);
  408. }
  409. resolve(link);
  410. });
  411. } else {
  412. resolve(link);
  413. }
  414. });
  415. }
  416.  
  417. // _getLinkInfoAsync(id) {
  418. // const link = this.#linkCache[id];
  419. // if (link) {
  420. // return Promise.resolve(link);
  421. // }
  422. // if (this.#disableApiUntil) {
  423. // if (Date.now() < this.#disableApiUntil) {
  424. // return Promise.resolve({ apiDisabled: true });
  425. // }
  426. // this.#disableApiUntil = null;
  427. // }
  428. // return new Promise(resolve => {
  429.  
  430. // let fullUrl = this._urlBase;
  431. // if (id.startsWith('q=') || id.startsWith('cid=')) {
  432. // fullUrl += id;
  433. // } else {
  434. // fullUrl += `place_id=${id}`;
  435. // }
  436. // $.getJSON(fullUrl).then(json => {
  437. // const res = {};
  438. // if (json.status === 'OK') {
  439. // res.loc = json.result.geometry.location;
  440. // if (json.result.business_status === 'CLOSED_PERMANENTLY') {
  441. // res.permclosed = true;
  442. // } else if (json.result.business_status === 'CLOSED_TEMPORARILY') {
  443. // res.tempclosed = true;
  444. // }
  445. // this._cacheLink(id, res);
  446. // } else if (json.status === 'NOT_FOUND') {
  447. // res.notfound = true;
  448. // this._cacheLink(id, res);
  449. // } else if (this.#disableApiUntil) {
  450. // res.apiDisabled = true;
  451. // } else {
  452. // res.error = json.status;
  453. // res.errorMessage = json.error_message;
  454. // this.#disableApiUntil = Date.now() + 10 * 1000; // Disable api calls for 10 seconds.
  455. // console.error(`${GM_info.script.name}, Google Link Enhancer disabled for 10 seconds due to API error.`, res);
  456. // }
  457. // resolve(res);
  458. // });
  459. // });
  460. // }
  461.  
  462. static #onMapMouseenter(event) {
  463. // If the point isn't destroyed yet, destroy it when mousing over the map.
  464. event.data.#destroyPoint();
  465. }
  466.  
  467. static #getSelectedFeatures() {
  468. if (!W.selectionManager.getSelectedFeatures) {
  469. return W.selectionManager.selectedItems;
  470. }
  471. return W.selectionManager.getSelectedFeatures();
  472. }
  473.  
  474. async #formatLinkElements(callCount = 0) {
  475. const $links = $('#edit-panel').find(this.#EXT_PROV_ELEM_QUERY);
  476. const selFeatures = W.selectionManager.getSelectedFeatures();
  477. if (!$links.length) {
  478. // If links aren't available, continue calling this function for up to 3 seconds unless place has been deselected.
  479. if (callCount < 30 && selFeatures.length && selFeatures[0].model.type === 'venue') {
  480. setTimeout(() => this.#formatLinkElements(++callCount), 100);
  481. }
  482. } else {
  483. const existingLinks = GoogleLinkEnhancer.#getExistingLinks();
  484.  
  485. // fetch all links first
  486. const promises = [];
  487. const extProvElements = [];
  488. $links.each((ix, linkEl) => {
  489. const $linkEl = $(linkEl);
  490. extProvElements.push($linkEl);
  491.  
  492. const id = GoogleLinkEnhancer.#getIdFromElement($linkEl);
  493. if (!id) return;
  494.  
  495. promises.push(this.#getLinkInfoAsync(id));
  496. });
  497. await Promise.all(promises);
  498.  
  499. extProvElements.forEach($extProvElem => {
  500. const id = GoogleLinkEnhancer.#getIdFromElement($extProvElem);
  501.  
  502. if (!id) return;
  503.  
  504. const link = this.#linkCache[id];
  505. if (existingLinks[id] && existingLinks[id].count > 1 && existingLinks[id].isThisVenue) {
  506. setTimeout(() => {
  507. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#FFA500' }).attr({
  508. title: this.strings.linkedToXPlaces.replace('{0}', existingLinks[id].count)
  509. });
  510. }, 50);
  511. }
  512. this.#addHoverEvent($extProvElem);
  513. if (link) {
  514. if (link.permclosed && !this.#DISABLE_CLOSED_PLACES) {
  515. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#FAA' }).attr('title', this.strings.permClosedPlace);
  516. } else if (link.tempclosed && !this.#DISABLE_CLOSED_PLACES) {
  517. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#FFA' }).attr('title', this.strings.tempClosedPlace);
  518. } else if (link.notFound) {
  519. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#F0F' }).attr('title', this.strings.badLink);
  520. } else {
  521. const venue = GoogleLinkEnhancer.#getSelectedFeatures()[0].model;
  522. if (this.#isLinkTooFar(link, venue)) {
  523. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '#0FF' }).attr('title', this.strings.tooFar.replace('{0}', this.distanceLimit));
  524. } else { // reset in case we just deleted another provider
  525. $extProvElem.find(this.#EXT_PROV_ELEM_CONTENT_QUERY).css({ backgroundColor: '' }).attr('title', '');
  526. }
  527. }
  528. }
  529. });
  530. }
  531. }
  532.  
  533. static #getExistingLinks() {
  534. const existingLinks = {};
  535. let thisVenue;
  536. if (GoogleLinkEnhancer.#getSelectedFeatures().length) {
  537. thisVenue = GoogleLinkEnhancer.#getSelectedFeatures()[0].model;
  538. }
  539. W.model.venues.getObjectArray().forEach(venue => {
  540. const isThisVenue = venue === thisVenue;
  541. const thisPlaceIDs = [];
  542. venue.attributes.externalProviderIDs.forEach(provID => {
  543. const id = provID.attributes.uuid;
  544. if (thisPlaceIDs.indexOf(id) === -1) {
  545. thisPlaceIDs.push(id);
  546. let link = existingLinks[id];
  547. if (link) {
  548. link.count++;
  549. link.venues.push(venue);
  550. } else {
  551. link = { count: 1, venues: [venue] };
  552. existingLinks[id] = link;
  553. if (provID.attributes.url != null) {
  554. const u = provID.attributes.url.replace('https://maps.google.com/?', '');
  555. link.url = u;
  556. }
  557. }
  558. link.isThisVenue = link.isThisVenue || isThisVenue;
  559. }
  560. });
  561. });
  562. return existingLinks;
  563. }
  564.  
  565. // Remove the POI point from the map.
  566. #destroyPoint() {
  567. if (this.#ptFeature) {
  568. this.#ptFeature.destroy();
  569. this.#ptFeature = null;
  570. this.#lineFeature.destroy();
  571. this.#lineFeature = null;
  572. }
  573. }
  574.  
  575. // Add the POI point to the map.
  576. #addPoint(id) {
  577. if (!id) return;
  578. const link = this.#linkCache[id];
  579. if (link) {
  580. if (!link.notFound) {
  581. const coord = link.loc;
  582. const poiPt = new OpenLayers.Geometry.Point(coord.lng, coord.lat);
  583. poiPt.transform(W.Config.map.projection.remote, W.map.getProjectionObject().projCode);
  584. const placeGeom = GoogleLinkEnhancer.#getSelectedFeatures()[0].geometry.getCentroid();
  585. const placePt = new OpenLayers.Geometry.Point(placeGeom.x, placeGeom.y);
  586. const ext = W.map.getExtent();
  587. const lsBounds = new OpenLayers.Geometry.LineString([
  588. new OpenLayers.Geometry.Point(ext.left, ext.bottom),
  589. new OpenLayers.Geometry.Point(ext.left, ext.top),
  590. new OpenLayers.Geometry.Point(ext.right, ext.top),
  591. new OpenLayers.Geometry.Point(ext.right, ext.bottom),
  592. new OpenLayers.Geometry.Point(ext.left, ext.bottom)]);
  593. let lsLine = new OpenLayers.Geometry.LineString([placePt, poiPt]);
  594.  
  595. // If the line extends outside the bounds, split it so we don't draw a line across the world.
  596. const splits = lsLine.splitWith(lsBounds);
  597. let label = '';
  598. if (splits) {
  599. let splitPoints;
  600. splits.forEach(split => {
  601. split.components.forEach(component => {
  602. if (component.x === placePt.x && component.y === placePt.y) splitPoints = split;
  603. });
  604. });
  605. lsLine = new OpenLayers.Geometry.LineString([splitPoints.components[0], splitPoints.components[1]]);
  606. let distance = poiPt.distanceTo(placePt);
  607. let unitConversion;
  608. let unit1;
  609. let unit2;
  610. if (W.model.isImperial) {
  611. distance *= 3.28084;
  612. unitConversion = 5280;
  613. unit1 = ' ft';
  614. unit2 = ' mi';
  615. } else {
  616. unitConversion = 1000;
  617. unit1 = ' m';
  618. unit2 = ' km';
  619. }
  620. if (distance > unitConversion * 10) {
  621. label = Math.round(distance / unitConversion) + unit2;
  622. } else if (distance > 1000) {
  623. label = (Math.round(distance / (unitConversion / 10)) / 10) + unit2;
  624. } else {
  625. label = Math.round(distance) + unit1;
  626. }
  627. }
  628.  
  629. this.#destroyPoint(); // Just in case it still exists.
  630. this.#ptFeature = new OpenLayers.Feature.Vector(poiPt, { poiCoord: true }, {
  631. pointRadius: 6,
  632. strokeWidth: 30,
  633. strokeColor: '#FF0',
  634. fillColor: '#FF0',
  635. strokeOpacity: 0.5
  636. });
  637. this.#lineFeature = new OpenLayers.Feature.Vector(lsLine, {}, {
  638. strokeWidth: 3,
  639. strokeDashstyle: '12 8',
  640. strokeColor: '#FF0',
  641. label,
  642. labelYOffset: 45,
  643. fontColor: '#FF0',
  644. fontWeight: 'bold',
  645. labelOutlineColor: '#000',
  646. labelOutlineWidth: 4,
  647. fontSize: '18'
  648. });
  649. W.map.getLayerByUniqueName('venues').addFeatures([this.#ptFeature, this.#lineFeature]);
  650. this.#timeoutDestroyPoint();
  651. }
  652. } else {
  653. this.#getLinkInfoAsync(id).then(res => {
  654. if (res.error || res.apiDisabled) {
  655. // API was temporarily disabled. Ignore for now.
  656. } else {
  657. this.#addPoint(id);
  658. }
  659. });
  660. }
  661. }
  662.  
  663. // Destroy the point after some time, if it hasn't been destroyed already.
  664. #timeoutDestroyPoint() {
  665. if (this.#timeoutID) clearTimeout(this.#timeoutID);
  666. this.#timeoutID = setTimeout(() => this.#destroyPoint(), 4000);
  667. }
  668.  
  669. static #getIdFromElement($el) {
  670. const providerIndex = $el.parent().children().toArray().indexOf($el[0]);
  671. return W.selectionManager.getSelectedFeatures()[0].model.getExternalProviderIDs()[providerIndex]?.attributes.uuid;
  672. }
  673.  
  674. #addHoverEvent($el) {
  675. $el.hover(() => this.#addPoint(GoogleLinkEnhancer.#getIdFromElement($el)), () => this.#destroyPoint());
  676. }
  677.  
  678. #observeLinks() {
  679. this.elem = document.querySelector('#edit-panel');
  680. this.#linkObserver.observe(document.querySelector('#edit-panel'), { childList: true, subtree: true });
  681. }
  682.  
  683. // The JSONP interceptor is used to watch the head element for the addition of JSONP functions
  684. // that process Google link search results. Those functions are overridden by our own so we can
  685. // process the results before sending them on to the original function.
  686. #addJsonpInterceptor() {
  687. // The idea for this function was hatched here:
  688. // https://stackoverflow.com/questions/6803521/can-google-maps-places-autocomplete-api-be-used-via-ajax/9856786
  689.  
  690. // The head element, where the Google Autocomplete code will insert a tag
  691. // for a javascript file.
  692. const head = $('head')[0];
  693. // The name of the method the Autocomplete code uses to insert the tag.
  694. const method = 'appendChild';
  695. // The method we will be overriding.
  696. const originalMethod = head[method];
  697. this.#originalHeadAppendChildMethod = originalMethod;
  698. const that = this;
  699. /* eslint-disable func-names, prefer-rest-params */ // Doesn't work as an arrow function (at least not without some modifications)
  700. head[method] = function() {
  701. // Check that the element is a javascript tag being inserted by Google.
  702. if (arguments[0] && arguments[0].src && arguments[0].src.match(/GetPredictions/)) {
  703. // Regex to extract the name of the callback method that the JSONP will call.
  704. const callbackMatchObject = (/callback=([^&]+)&|$/).exec(arguments[0].src);
  705.  
  706. // Regex to extract the search term that was entered by the user.
  707. const searchTermMatchObject = (/\?1s([^&]+)&/).exec(arguments[0].src);
  708.  
  709. // const searchTerm = unescape(searchTermMatchObject[1]);
  710. if (callbackMatchObject && searchTermMatchObject) {
  711. // The JSONP callback method is in the form "abc.def" and each time has a different random name.
  712. const names = callbackMatchObject[1].split('.');
  713. // Store the original callback method.
  714. const originalCallback = names[0] && names[1] && window[names[0]] && window[names[0]][names[1]];
  715.  
  716. if (originalCallback) {
  717. const newCallback = function() { // Define your own JSONP callback
  718. if (arguments[0] && arguments[0].predictions) {
  719. // SUCCESS!
  720.  
  721. // The autocomplete results
  722. const data = arguments[0];
  723.  
  724. // console.log('GLE: ' + JSON.stringify(data));
  725. that._lastSearchResultPlaceIds = data.predictions.map(pred => pred.place_id);
  726.  
  727. // Call the original callback so the WME dropdown can do its thing.
  728. originalCallback(data);
  729. }
  730. };
  731.  
  732. // Add copy of all the attributes of the old callback function to the new callback function.
  733. // This prevents the autocomplete functionality from throwing an error.
  734. Object.keys(originalCallback).forEach(key => {
  735. newCallback[key] = originalCallback[key];
  736. });
  737. window[names[0]][names[1]] = newCallback; // Override the JSONP callback
  738. }
  739. }
  740. }
  741. // Insert the element into the dom, regardless of whether it was being inserted by Google.
  742. return originalMethod.apply(this, arguments);
  743. };
  744. /* eslint-enable func-names, prefer-rest-params */
  745. }
  746.  
  747. #removeJsonpInterceptor() {
  748. $('head')[0].appendChild = this.#originalHeadAppendChildMethod;
  749. }
  750.  
  751. /* eslint-disable */ // Disabling eslint since this is copied code.
  752. #initLZString() {
  753. // LZ Compressor
  754. // Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
  755. // This work is free. You can redistribute it and/or modify it
  756. // under the terms of the WTFPL, Version 2
  757. // LZ-based compression algorithm, version 1.4.4
  758. this.#lzString = (function () {
  759. // private property
  760. const f = String.fromCharCode;
  761. const keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  762. const keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
  763. const baseReverseDic = {};
  764.  
  765. function getBaseValue(alphabet, character) {
  766. if (!baseReverseDic[alphabet]) {
  767. baseReverseDic[alphabet] = {};
  768. for (let i = 0; i < alphabet.length; i++) {
  769. baseReverseDic[alphabet][alphabet.charAt(i)] = i;
  770. }
  771. }
  772. return baseReverseDic[alphabet][character];
  773. }
  774. var LZString = {
  775. compressToBase64: function (input) {
  776. if (input === null) return "";
  777. const res = LZString._compress(input, 6, function (a) {
  778. return keyStrBase64.charAt(a);
  779. });
  780. switch (res.length % 4) { // To produce valid Base64
  781. default: // When could this happen ?
  782. case 0:
  783. return res;
  784. case 1:
  785. return res + "===";
  786. case 2:
  787. return res + "==";
  788. case 3:
  789. return res + "=";
  790. }
  791. },
  792. decompressFromBase64: function (input) {
  793. if (input === null) return "";
  794. if (input === "") return null;
  795. return LZString._decompress(input.length, 32, function (index) {
  796. return getBaseValue(keyStrBase64, input.charAt(index));
  797. });
  798. },
  799. compressToUTF16: function (input) {
  800. if (input === null) return "";
  801. return LZString._compress(input, 15, function (a) {
  802. return f(a + 32);
  803. }) + " ";
  804. },
  805. decompressFromUTF16: function (compressed) {
  806. if (compressed === null) return "";
  807. if (compressed === "") return null;
  808. return LZString._decompress(compressed.length, 16384, function (index) {
  809. return compressed.charCodeAt(index) - 32;
  810. });
  811. },
  812.  
  813. compress: function (uncompressed) {
  814. return LZString._compress(uncompressed, 16, function (a) {
  815. return f(a);
  816. });
  817. },
  818. _compress: function (uncompressed, bitsPerChar, getCharFromInt) {
  819. if (uncompressed === null) return "";
  820. let i, value,
  821. context_dictionary = {},
  822. context_dictionaryToCreate = {},
  823. context_c = "",
  824. context_wc = "",
  825. context_w = "",
  826. context_enlargeIn = 2, // Compensate for the first entry which should not count
  827. context_dictSize = 3,
  828. context_numBits = 2,
  829. context_data = [],
  830. context_data_val = 0,
  831. context_data_position = 0,
  832. ii;
  833. for (ii = 0; ii < uncompressed.length; ii += 1) {
  834. context_c = uncompressed.charAt(ii);
  835. if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
  836. context_dictionary[context_c] = context_dictSize++;
  837. context_dictionaryToCreate[context_c] = true;
  838. }
  839. context_wc = context_w + context_c;
  840. if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
  841. context_w = context_wc;
  842. } else {
  843. if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
  844. if (context_w.charCodeAt(0) < 256) {
  845. for (i = 0; i < context_numBits; i++) {
  846. context_data_val = (context_data_val << 1);
  847. if (context_data_position === bitsPerChar - 1) {
  848. context_data_position = 0;
  849. context_data.push(getCharFromInt(context_data_val));
  850. context_data_val = 0;
  851. } else {
  852. context_data_position++;
  853. }
  854. }
  855. value = context_w.charCodeAt(0);
  856. for (i = 0; i < 8; i++) {
  857. context_data_val = (context_data_val << 1) | (value & 1);
  858. if (context_data_position === bitsPerChar - 1) {
  859. context_data_position = 0;
  860. context_data.push(getCharFromInt(context_data_val));
  861. context_data_val = 0;
  862. } else {
  863. context_data_position++;
  864. }
  865. value = value >> 1;
  866. }
  867. } else {
  868. value = 1;
  869. for (i = 0; i < context_numBits; i++) {
  870. context_data_val = (context_data_val << 1) | value;
  871. if (context_data_position === bitsPerChar - 1) {
  872. context_data_position = 0;
  873. context_data.push(getCharFromInt(context_data_val));
  874. context_data_val = 0;
  875. } else {
  876. context_data_position++;
  877. }
  878. value = 0;
  879. }
  880. value = context_w.charCodeAt(0);
  881. for (i = 0; i < 16; i++) {
  882. context_data_val = (context_data_val << 1) | (value & 1);
  883. if (context_data_position === bitsPerChar - 1) {
  884. context_data_position = 0;
  885. context_data.push(getCharFromInt(context_data_val));
  886. context_data_val = 0;
  887. } else {
  888. context_data_position++;
  889. }
  890. value = value >> 1;
  891. }
  892. }
  893. context_enlargeIn--;
  894. if (context_enlargeIn === 0) {
  895. context_enlargeIn = Math.pow(2, context_numBits);
  896. context_numBits++;
  897. }
  898. delete context_dictionaryToCreate[context_w];
  899. } else {
  900. value = context_dictionary[context_w];
  901. for (i = 0; i < context_numBits; i++) {
  902. context_data_val = (context_data_val << 1) | (value & 1);
  903. if (context_data_position === bitsPerChar - 1) {
  904. context_data_position = 0;
  905. context_data.push(getCharFromInt(context_data_val));
  906. context_data_val = 0;
  907. } else {
  908. context_data_position++;
  909. }
  910. value = value >> 1;
  911. }
  912. }
  913. context_enlargeIn--;
  914. if (context_enlargeIn === 0) {
  915. context_enlargeIn = Math.pow(2, context_numBits);
  916. context_numBits++;
  917. }
  918. // Add wc to the dictionary.
  919. context_dictionary[context_wc] = context_dictSize++;
  920. context_w = String(context_c);
  921. }
  922. }
  923. // Output the code for w.
  924. if (context_w !== "") {
  925. if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
  926. if (context_w.charCodeAt(0) < 256) {
  927. for (i = 0; i < context_numBits; i++) {
  928. context_data_val = (context_data_val << 1);
  929. if (context_data_position === bitsPerChar - 1) {
  930. context_data_position = 0;
  931. context_data.push(getCharFromInt(context_data_val));
  932. context_data_val = 0;
  933. } else {
  934. context_data_position++;
  935. }
  936. }
  937. value = context_w.charCodeAt(0);
  938. for (i = 0; i < 8; i++) {
  939. context_data_val = (context_data_val << 1) | (value & 1);
  940. if (context_data_position === bitsPerChar - 1) {
  941. context_data_position = 0;
  942. context_data.push(getCharFromInt(context_data_val));
  943. context_data_val = 0;
  944. } else {
  945. context_data_position++;
  946. }
  947. value = value >> 1;
  948. }
  949. } else {
  950. value = 1;
  951. for (i = 0; i < context_numBits; i++) {
  952. context_data_val = (context_data_val << 1) | value;
  953. if (context_data_position === bitsPerChar - 1) {
  954. context_data_position = 0;
  955. context_data.push(getCharFromInt(context_data_val));
  956. context_data_val = 0;
  957. } else {
  958. context_data_position++;
  959. }
  960. value = 0;
  961. }
  962. value = context_w.charCodeAt(0);
  963. for (i = 0; i < 16; i++) {
  964. context_data_val = (context_data_val << 1) | (value & 1);
  965. if (context_data_position === bitsPerChar - 1) {
  966. context_data_position = 0;
  967. context_data.push(getCharFromInt(context_data_val));
  968. context_data_val = 0;
  969. } else {
  970. context_data_position++;
  971. }
  972. value = value >> 1;
  973. }
  974. }
  975. context_enlargeIn--;
  976. if (context_enlargeIn === 0) {
  977. context_enlargeIn = Math.pow(2, context_numBits);
  978. context_numBits++;
  979. }
  980. delete context_dictionaryToCreate[context_w];
  981. } else {
  982. value = context_dictionary[context_w];
  983. for (i = 0; i < context_numBits; i++) {
  984. context_data_val = (context_data_val << 1) | (value & 1);
  985. if (context_data_position === bitsPerChar - 1) {
  986. context_data_position = 0;
  987. context_data.push(getCharFromInt(context_data_val));
  988. context_data_val = 0;
  989. } else {
  990. context_data_position++;
  991. }
  992. value = value >> 1;
  993. }
  994. }
  995. context_enlargeIn--;
  996. if (context_enlargeIn === 0) {
  997. context_enlargeIn = Math.pow(2, context_numBits);
  998. context_numBits++;
  999. }
  1000. }
  1001. // Mark the end of the stream
  1002. value = 2;
  1003. for (i = 0; i < context_numBits; i++) {
  1004. context_data_val = (context_data_val << 1) | (value & 1);
  1005. if (context_data_position === bitsPerChar - 1) {
  1006. context_data_position = 0;
  1007. context_data.push(getCharFromInt(context_data_val));
  1008. context_data_val = 0;
  1009. } else {
  1010. context_data_position++;
  1011. }
  1012. value = value >> 1;
  1013. }
  1014. // Flush the last char
  1015. while (true) {
  1016. context_data_val = (context_data_val << 1);
  1017. if (context_data_position === bitsPerChar - 1) {
  1018. context_data.push(getCharFromInt(context_data_val));
  1019. break;
  1020. } else context_data_position++;
  1021. }
  1022. return context_data.join('');
  1023. },
  1024. decompress: function (compressed) {
  1025. if (compressed === null) return "";
  1026. if (compressed === "") return null;
  1027. return LZString._decompress(compressed.length, 32768, function (index) {
  1028. return compressed.charCodeAt(index);
  1029. });
  1030. },
  1031. _decompress: function (length, resetValue, getNextValue) {
  1032. let dictionary = [],
  1033. next,
  1034. enlargeIn = 4,
  1035. dictSize = 4,
  1036. numBits = 3,
  1037. entry = "",
  1038. result = [],
  1039. i,
  1040. w,
  1041. bits, resb, maxpower, power,
  1042. c,
  1043. data = {
  1044. val: getNextValue(0),
  1045. position: resetValue,
  1046. index: 1
  1047. };
  1048. for (i = 0; i < 3; i += 1) {
  1049. dictionary[i] = i;
  1050. }
  1051. bits = 0;
  1052. maxpower = Math.pow(2, 2);
  1053. power = 1;
  1054. while (power !== maxpower) {
  1055. resb = data.val & data.position;
  1056. data.position >>= 1;
  1057. if (data.position === 0) {
  1058. data.position = resetValue;
  1059. data.val = getNextValue(data.index++);
  1060. }
  1061. bits |= (resb > 0 ? 1 : 0) * power;
  1062. power <<= 1;
  1063. }
  1064. switch (next = bits) {
  1065. case 0:
  1066. bits = 0;
  1067. maxpower = Math.pow(2, 8);
  1068. power = 1;
  1069. while (power !== maxpower) {
  1070. resb = data.val & data.position;
  1071. data.position >>= 1;
  1072. if (data.position === 0) {
  1073. data.position = resetValue;
  1074. data.val = getNextValue(data.index++);
  1075. }
  1076. bits |= (resb > 0 ? 1 : 0) * power;
  1077. power <<= 1;
  1078. }
  1079. c = f(bits);
  1080. break;
  1081. case 1:
  1082. bits = 0;
  1083. maxpower = Math.pow(2, 16);
  1084. power = 1;
  1085. while (power !== maxpower) {
  1086. resb = data.val & data.position;
  1087. data.position >>= 1;
  1088. if (data.position === 0) {
  1089. data.position = resetValue;
  1090. data.val = getNextValue(data.index++);
  1091. }
  1092. bits |= (resb > 0 ? 1 : 0) * power;
  1093. power <<= 1;
  1094. }
  1095. c = f(bits);
  1096. break;
  1097. case 2:
  1098. return "";
  1099. }
  1100. dictionary[3] = c;
  1101. w = c;
  1102. result.push(c);
  1103. while (true) {
  1104. if (data.index > length) {
  1105. return "";
  1106. }
  1107. bits = 0;
  1108. maxpower = Math.pow(2, numBits);
  1109. power = 1;
  1110. while (power !== maxpower) {
  1111. resb = data.val & data.position;
  1112. data.position >>= 1;
  1113. if (data.position === 0) {
  1114. data.position = resetValue;
  1115. data.val = getNextValue(data.index++);
  1116. }
  1117. bits |= (resb > 0 ? 1 : 0) * power;
  1118. power <<= 1;
  1119. }
  1120. switch (c = bits) {
  1121. case 0:
  1122. bits = 0;
  1123. maxpower = Math.pow(2, 8);
  1124. power = 1;
  1125. while (power !== maxpower) {
  1126. resb = data.val & data.position;
  1127. data.position >>= 1;
  1128. if (data.position === 0) {
  1129. data.position = resetValue;
  1130. data.val = getNextValue(data.index++);
  1131. }
  1132. bits |= (resb > 0 ? 1 : 0) * power;
  1133. power <<= 1;
  1134. }
  1135. dictionary[dictSize++] = f(bits);
  1136. c = dictSize - 1;
  1137. enlargeIn--;
  1138. break;
  1139. case 1:
  1140. bits = 0;
  1141. maxpower = Math.pow(2, 16);
  1142. power = 1;
  1143. while (power !== maxpower) {
  1144. resb = data.val & data.position;
  1145. data.position >>= 1;
  1146. if (data.position === 0) {
  1147. data.position = resetValue;
  1148. data.val = getNextValue(data.index++);
  1149. }
  1150. bits |= (resb > 0 ? 1 : 0) * power;
  1151. power <<= 1;
  1152. }
  1153. dictionary[dictSize++] = f(bits);
  1154. c = dictSize - 1;
  1155. enlargeIn--;
  1156. break;
  1157. case 2:
  1158. return result.join('');
  1159. }
  1160. if (enlargeIn === 0) {
  1161. enlargeIn = Math.pow(2, numBits);
  1162. numBits++;
  1163. }
  1164. if (dictionary[c]) {
  1165. entry = dictionary[c];
  1166. } else {
  1167. if (c === dictSize) {
  1168. entry = w + w.charAt(0);
  1169. } else {
  1170. return null;
  1171. }
  1172. }
  1173. result.push(entry);
  1174. // Add w+entry[0] to the dictionary.
  1175. dictionary[dictSize++] = w + entry.charAt(0);
  1176. enlargeIn--;
  1177. w = entry;
  1178. if (enlargeIn === 0) {
  1179. enlargeIn = Math.pow(2, numBits);
  1180. numBits++;
  1181. }
  1182. }
  1183. }
  1184. };
  1185. return LZString;
  1186. })();
  1187. }
  1188. /* eslint-enable */
  1189. }