public getCoordinates()

in src/geocoder/geocodingCache.ts [72:115]


        public getCoordinates(key: string): JQueryPromise<{}> {
            let deferred = $.Deferred();
            let result = undefined;
            // Check in-memory cache
            const shortKey: string = GeocodingCache.getShortKey(key);
            let pair: GeocodeCacheEntry = this.geocodeCache[shortKey];
            if (pair) {
                ++pair.hitCount;
                result = pair.coordinate;
                return deferred.resolve(result);
            }
            // Check local storage cache
            const localStoragePromise: IPromise<string> = this.localStorageService.get(GeocodingCache.TILE_LOCATIONS);
            localStoragePromise.then((value) => {
                const parsedValue = JSON.parse(value);
                if (!parsedValue) {
                    return deferred.resolve(result);
                }

                // Register all keys in memory
                for (let parsedKey in parsedValue) {
                    const location = parsedValue[parsedKey];
                    pair = {
                        coordinate: {
                            latitude: location.lat,
                            longitude: location.lon
                        }
                    } as GeocodeCacheEntry;

                    const shortParsedKey: string = GeocodingCache.getShortKey(parsedKey);
                    this.registerInMemory(shortParsedKey, pair.coordinate);

                    if (parsedKey === shortKey) {
                        result = pair.coordinate;
                        deferred.resolve(result);
                    }
                }
            })
                .catch(() => {
                    deferred.resolve(result);
                });

            return deferred;
        }