Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map features get double serialized #211

Open
chanmathew opened this issue Nov 7, 2024 · 4 comments
Open

Map features get double serialized #211

chanmathew opened this issue Nov 7, 2024 · 4 comments
Labels
upstream-issue Issue in Maplibre itself

Comments

@chanmathew
Copy link

chanmathew commented Nov 7, 2024

Hi @dimfeld - Pardon me if I'm being annoying here, but on a streak to document some things :)

I've noticed that when you pass nested arrays or objects to a GeoJSON source as a feature:

<GeoJSON
		id="places"
		promoteId="id"
		data={{
			type: 'FeatureCollection',
			features: filteredMapData?.map((place: SelectPlaceModel) => ({
				type: 'Feature',
				geometry: {
					type: 'Point',
					coordinates: [place?.coordinates?.x, place?.coordinates?.y] as [number, number]
				},
				id: place.id,
				properties: place
			}))
		}}
		cluster={{
			radius: clusterRadius,
			maxZoom: 11
		}}
	>

And then you access the features in a MarkerLayer, either via an event, or the feature attribute:

<MarkerLayer
	applyToClusters
	asButton
	class="rounded-full border-8 border-white/60 ring-4 ring-white/30 ring-offset-4 ring-offset-white/10"
	draggable={false}
	on:click={(e) => console.log(e)} // e.properties would be double stringified
	let:feature
>
{console.log(feature.properties)} // feature.properties would be double stringified

Then the objects would be double stringified, here's an example:

{
    "id": "abc-123",
    "coordinates": "{\"x\":-115.17214,\"y\":36.1087863}",
    "google_place_name": "Taco Bell Cantina",
    "name": "Taco Bell Cantina",
    "description": "",
    "rating": 4.4,
    "user_ratings_total": 5482,
    "category": "{\"id\":8,\"icon\":\"ph:map-pin-fill\",\"name\":\"Other\",\"sort_order\":7}",
    "subcategory": "{\"id\":61,\"icon\":\"ph:map-pin-fill\",\"name\":\"Other\",\"sort_order\":60}",
    "photo": "817968ba-2193-42b9-8b94-fc2a02c3a142_0.jpg_1728874009077_undefined.jpg",
    "city": "Las Vegas",
    "country": "US",
    "formatted_address": "3717 S Las Vegas Blvd Suite 140-A, Las Vegas, NV 89109, USA",
    "website": "https://locations.tacobell.com/nv/las-vegas/3717-south-las-vegas-blvd.html?utm_source=yext&utm_campaign=googlelistings&utm_medium=referral&utm_term=032366&utm_content=website&y_source=1_NjE0MzkxNi03MTUtbG9jYXRpb24ud2Vic2l0ZQ%3D%3D",
    "opening_hours": "{\"periods\":[{\"open\":{\"day\":0,\"time\":\"0000\",\"hours\":0,\"minutes\":0}}],\"open_now\":true,\"weekday_text\":[\"Monday: Open 24 hours\",\"Tuesday: Open 24 hours\",\"Wednesday: Open 24 hours\",\"Thursday: Open 24 hours\",\"Friday: Open 24 hours\",\"Saturday: Open 24 hours\",\"Sunday: Open 24 hours\"]}",
    "formatted_phone_number": "(702) 272-2422",
    "sort_order": 7
}

Is there a way to make sure it's not double stringified? Right now my workaround is to have a helper function that parses it all before I do anything with it.

@dimfeld
Copy link
Owner

dimfeld commented Nov 7, 2024

I’m on my phone right now so can’t easily look it up, but IIRC someone else mentioned this before and it turned out to be an internal thing with how maplibre represents data internally. I think the best solution here is to look up those entries in the original source data where it looks like it should.

@dimfeld
Copy link
Owner

dimfeld commented Nov 7, 2024

Here was the previous discussion: #162

@dimfeld
Copy link
Owner

dimfeld commented Nov 7, 2024

Pardon me if I'm being annoying here, but on a streak to document some things

Not annoying at all, these are good questions :)

@chanmathew
Copy link
Author

Ah doh! Seems like both issues are blocked then, thanks for the quick clarifications! 😀

@dimfeld dimfeld added the upstream-issue Issue in Maplibre itself label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream-issue Issue in Maplibre itself
Projects
None yet
Development

No branches or pull requests

2 participants