How can I add both 'point' and 'linestring' features to same map?

Created on 6 March 2024, 4 months ago
Updated 21 April 2024, 2 months ago

Hello,
I am trying to add a linestring feature to a set of features that already has points. The linestring is not rendering. I'm trying to follow the code from leaflet_views.api.php where it says "linestring" is a valid feature type. This is where I get a little lost though. Here's how I'm adding the feature:

// add linestring
				$features[] = [
					'type' => 'linestring',
					'points' => [[$lat1,$lng1],[$lat2,$lng2]],
					'coordinates' => [[$lat1,$lng1],[$lat2,$lng2]],
					'leaflet_id' => 'ls-'.$lrid.'-'.$crid,
				];

I added the 'coordinates' key first but then got an error that "length" of "points" couldn't be determined, so I tried putting in a "points" key. That clears the error but still no linestring. I'm looking at LeafletService.php but can't get anywhere.

I'm adding the map like this:

$map_info = leaflet_map_get_info("mymodule_map");
		$content['map'] = \Drupal::service('leaflet.service')->leafletRenderMap($map_info, $features, '480px');

Thanks for any pointers!

💬 Support request
Status

Fixed

Version

10.2

Component

Miscellaneous

Created by

🇺🇸United States dmudie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024