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

image-icon setting a nested property #7689

Closed
eduboxgithub opened this issue Dec 12, 2018 · 1 comment
Closed

image-icon setting a nested property #7689

eduboxgithub opened this issue Dec 12, 2018 · 1 comment

Comments

@eduboxgithub
Copy link

mapbox-gl-js version: 0.51

Question

I'm using the cluster feature documented here (https://www.mapbox.com/mapbox-gl-js/example/cluster/).

I made I few changes. Instead of circle in the "unclustered-point" and using a symbol with an icon-image. To correctly bind and use symbol with icon-image I had to create my custom sprite with about 600 icons (made it with spritezero-cli). The sprite is correctly loaded and all seems to work.

this.Map.addLayer(
{
	id: "unclustered-point",
	type: "symbol",
	source: "roadsigns",
	filter: ["!", ["has", "point_count"]],
	layout: 
	{
		"icon-image": "{Sign.Code}",
	}
});

The problem is the binding "icon-image": "{Sign.Code}".
I receive the data from a server request and parse it to GeoJSON with features.
In the properties prop of the GeoJSON a set the object received from the server:

RoadSign =
{
      Id: 1,
      Date: "24-12-2018",
      Location: { lng:0, lat:0 }
      Sign: { Name: "STOP", Id:1, Code:"A21" }
}

I tested to edit the object received from the server adding a SignCode prop on the root object.
If I do it the image is correctly assigned from the sprite, but some extra iterations needs to be done.

RoadSign =
{
      Id: 1,
      Date: "24-12-2018",
      Location: { lng:0, lat:0 }
      Sign: { Name: "STOP", Id:1, Code:"A21" }
      SignCode: "A21" 
}

this.Map.addLayer(
{
	id: "unclustered-point",
	type: "symbol",
	source: "roadsigns",
	filter: ["!", ["has", "point_count"]],
	layout: 
	{
		"icon-image": "{SignCode}",
	}
});

Is it not possible to bind to a nested prop from the properties object of the GeoJSON?

Links to related documentation

Cluster Example: https://www.mapbox.com/mapbox-gl-js/example/cluster/
Icon-Image value and bind: https://www.mapbox.com/mapbox-gl-js/style-spec

@asheemmamoowala
Copy link
Contributor

The icon-image property needs to use a get expression with an object type assertion for Sign.

See the example here: #2434 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants