Skip to content

Commit 0d5cc7b

Browse files
committed
Uses the citiesJSON service to get geoname
1 parent 7b145c2 commit 0d5cc7b

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/models/data-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class DataManager {
145145

146146
pluginState.pins.forEach(pin => {
147147
const extractedColor = geoImage.extractColor(pin.lat, pin.long);
148-
const label = pinLabel(pin);
148+
const label = pin.label || pinLabel(pin);
149149
const paletteIndex = this.reversePalette?.[GeoImage.rgbToNumber(extractedColor)] ?? -1;
150150
const paletteValue = neoDataset.paletteToValue(paletteIndex);
151151
const color = paletteValue === null ? {r: 148, g: 148, b: 148} : extractedColor;
@@ -264,7 +264,9 @@ export class DataManager {
264264
if (!image?.pins) {
265265
return;
266266
}
267+
console.log("image.pins", image.pins);
267268
Object.values(image.pins).forEach(pin => {
269+
console.log("pin", pin);
268270
items.push({
269271
date: image.date,
270272
color: pin.color,
@@ -281,7 +283,8 @@ export class DataManager {
281283
// FIXME: Change pin lat lon to geoname
282284
const pinColorMap: Record<string, string> = {};
283285
pluginState.pins.forEach(pin => {
284-
pinColorMap[`${parseFloat(pin.lat.toFixed(2))}, ${parseFloat(pin.long.toFixed(2))}`] = pin.color;
286+
pinColorMap[`${pin.label}`] = pin.color;
287+
// pinColorMap[`${parseFloat(pin.lat.toFixed(2))}, ${parseFloat(pin.long.toFixed(2))}`] = pin.color;
285288
});
286289

287290
await updateDataContextTitle(neoDataset.label);

src/models/plugin-state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
kPluginName,
1010
kVersion
1111
} from "../data/constants";
12-
import { createOrUpdateMap, createSelectionList, deleteSelectionList, updateSelectionList } from "../utils/codap-utils";
12+
import { createOrUpdateMap, createSelectionList, deleteSelectionList, updateSelectionList,
13+
getMapComponentInfo } from "../utils/codap-utils";
1314
import { NeoDataset } from "./neo-types";
14-
import { getMapComponentInfo } from "../utils/codap-utils";
1515
import { geoLocSearch, MapComponentInfo } from "../utils/location-utils";
1616

1717
export interface IMapPin {
@@ -84,12 +84,14 @@ class PluginState {
8484
const lat = pin.values[kPinLatAttributeName];
8585
const long = pin.values[kPinLongAttributeName];
8686
const locationResult = yield geoLocSearch(lat, long, bounds);
87+
console.log("locationResult", locationResult);
8788
const label = locationResult.values.location;
8889
labels.push(label);
8990
}
9091

9192
this.pins = pinData.map((pin: any, index: number) => {
9293
const values = pin.values;
94+
console.log("labels", labels);
9395
return {
9496
color: values[kPinColorAttributeName],
9597
id: pin.id,

src/utils/location-utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export const geoLocSearch = async (lat: number, long: number, bounds: IBounds) =
6464
const populationLimitClause = "city15000";
6565
// boundsClause is used if using citiesJSON service
6666
const boundsClause = `north=${bounds.north}&south=${bounds.south}&east=${bounds.east}&west=${bounds.west}`;
67-
// const url = `${kGeolocCitiesService}?${[locClause, userClause, boundsClause, maxRowsClause].join("&")}`;
68-
const url = `${kGeolocService}?${[locClause, userClause, maxRowsClause, radiusClause, populationLimitClause ]
69-
.join("&")}`;
67+
const url = `${kGeolocCitiesService}?${[locClause, userClause, boundsClause, maxRowsClause].join("&")}`;
68+
// const url = `${kGeolocService}?${[locClause, userClause, maxRowsClause, radiusClause, populationLimitClause ]
69+
// .join("&")}`;
7070
try {
7171
const response = await fetch(url);
7272
if (response.ok) {
@@ -87,14 +87,14 @@ export const geoLocSearch = async (lat: number, long: number, bounds: IBounds) =
8787
console.log("sorted geonames", JSON.parse(JSON.stringify(sortedGeonamesByPopulation)));
8888

8989
// find the nearest location nearest the lat/long. We use the commented out code if using the citiesJSON service
90-
// const nearest = findNearestCity(lat, long, data.geonames);
91-
const nearest = sortedGeonamesByPopulation[0];
90+
const nearest = findNearestCity(lat, long, data.geonames);
91+
// const nearest = sortedGeonamesByPopulation[0];
9292
console.log("nearest location", JSON.parse(JSON.stringify(nearest)));
9393
return nearest
94-
? {success: true, values: {location:`${nearest.name}, ${nearest.adminCode1}`}}
94+
// ? {success: true, values: {location:`${nearest.name}, ${nearest.adminCode1}`}}
9595
// Return this value if using the citiesJSON service.
9696
// citiesJSON service does not have adminCode1 (state name), se we use countrycode
97-
// ? {success: true, values: {location:`${nearest.name}, ${nearest.countrycode}`}}
97+
? {success: true, values: {location:`${nearest.name}, ${nearest.countrycode}`}}
9898
: {success: false, values: {location: "Unknown Location"}};
9999
} else {
100100
return Promise.reject(response.statusText);

0 commit comments

Comments
 (0)