laravel-eloquent-spatial icon indicating copy to clipboard operation
laravel-eloquent-spatial copied to clipboard

Add support for custom properties in toFeatureCollectionJson method

Open MayGrass opened this issue 1 year ago • 3 comments

MayGrass avatar Mar 29 '24 08:03 MayGrass

Hi @MayGrass, thanks for the PR. Can you share the motivation for this PR? Also, please add tests and update API.md

MatanYadaev avatar Mar 29 '24 08:03 MatanYadaev

Previously, when generating a GeoJSON feature collection, there was no straightforward way to include properties for each feature. This meant that after generating the GeoJSON, additional steps were required, such as decoding the JSON, iterating over the features, and adding the properties manually.

The updated test ensures that the toFeatureCollectionJson method correctly handles the provided properties and generates the expected GeoJSON feature collection.

MayGrass avatar Mar 29 '24 09:03 MayGrass

I feel uncomfortable with the method signature you chose. The $properties parameter is an array of the parameters of each feature in the collection, which is a bit confusing and not an elegant API. What will happen if I enter more properties than the features? What if I want to have properties just on the fifth feature? etc You can see Turf.js API for example https://turfjs.org/docs/#featureCollection The properties are part of the features and not part of the collection.

var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});

var collection = turf.featureCollection([
  locationA,
  locationB,
  location
]);

Anyway, for this package, I don't think it's important to push this type of change, as most of this package's value is about integrating with the DB.

MatanYadaev avatar Mar 29 '24 21:03 MatanYadaev