2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 26 forks source link

LatLng Values routinely get encoded as strings #16

Closed Okeanos closed 8 years ago

Okeanos commented 8 years ago

I recently extended my existing map with polylines using the supplied wrapper class dosamigos\leaflet\layers\PolyLine. However, even when creating a perfectly fine Polyline:

$path = new PolyLine();
$path->setLatLngs([
  new LatLng(['lat' => …, 'lng' => …]),
  new LatLng(['lat' => …, 'lng' => …])
]);

The resulting JS fails. This is because the current implementation of the encode function does not pass JSON_NUMERIC_CHECK onto the yii\helpers\Json::encode() method used to transform the LatLng object into JSON which results in string values instead of keeping the float values. This is also missing for Markers, however, in this case Leaflet itself appears to be more forgiving. Interestingly, for the map object itself the float values are kept as floats instead of being converted to strings even though the same process is used … maybe I am overlooking something?

tonydspaniard commented 8 years ago

Will review it asap.

Okeanos commented 8 years ago

Any progress on this issue?

tonydspaniard commented 8 years ago

@Okeanos I had a lot of issues with having free time to support the extensions. Do you mind providing me sample code to duplicate the issue? Thanks in advance.

Okeanos commented 8 years ago

No worries. I'll see whether I can whip something up before the holidays.

tonydspaniard commented 8 years ago

It doesn't need to be too large, just replicating the issue. I have time now to support our extensions.

tonydspaniard commented 8 years ago

@Okeanos I pushed a fix, let me know if it works. Thanks.

Okeanos commented 8 years ago

This fix appears to be working. I don't have any test cases for the following wrapper classes, though, so I can't say whether the respective encode() function also needs this treatment: FeatureGroup, LayerGroup, GeoJson, Polygon

Thank you for taking care of it :)

tonydspaniard commented 8 years ago

@Okeanos Good news. I'll update revision tag then. I have plans to update the library to make it much better in structure.