codediodeio / geofirex

:globe_with_meridians: :round_pushpin: Geolocation Queries with Firestore & RxJS

Home Page:https://geo-test-c92e4.firebaseapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

toGeoJSON returns empty properties

josemurillodev opened this issue · comments

Hi! My query seems to work but, the returned properties are empty. No errors

const cities = geo.collection('cities');

async function getGeoJSON(point) {
  const query = cities.within(point, 10, 'position');
  const obvservable = query.pipe(toGeoJSON('position'));
  const geoj = await get(obvservable);
  return geoj;
}

The database has 9 cities with a name property. this is what i get in console:

features: Array(7)
  0:
      geometry: {type: "Point", coordinates: Array(2)}
      properties:
           __proto__: Object
      type: "Feature"
      __proto__: Object
  1: {type: "Feature", geometry: {…}, properties: {…}}
  2: {type: "Feature", geometry: {…}, properties: {…}}
  3: {type: "Feature", geometry: {…}, properties: {…}}
  4: {type: "Feature", geometry: {…}, properties: {…}}
  5: {type: "Feature", geometry: {…}, properties: {…}}
  6: {type: "Feature", geometry: {…}, properties: {…}}
length: 7
__proto__: Array(0)
type: "FeatureCollection"

firebase: "^4.6.2",
geofirex: "0.0.6",
rxjs: "^6.3.3"

I took a look at the source code and find what was my problem

/**
 * RxJS operator that converts a collection to a GeoJSON FeatureCollection
 * @param  {string} field the document field that contains the GeoFirePoint
 * @param  {boolean=false} includeProps
 */

So, i just need to pass a true value to includeProps

const cities = geo.collection('delegaciones');

async function getGeoJSON(point) {
  const query = cities.within(point, 10, 'position');
  const obvservable = query.pipe(toGeoJSON('position', true)); // here
  const geoj = await get(obvservable);
  return geoj;
}

You can close this now