ThinkGeo.com    |     Documentation    |     Premium Support

Unique label position per layer using same text style

Hello. I have a bunch of custom textstyles used for styling labels of layers (by setting DefaultTextStyle).

Is there a way to make the label position of a layer unique without changing the textstyle?

For instance, maybe I have a simple text style that’s size 12 and red text. Two layers are using this style for it’s label. For one layer, I want the label to be above the features. For the other layer, I want the label to be below the features.

Ideally I want to be able to place the labels either above, below, to the right, to the left, or directly on top of the features. Is there any kind of property I can set on the layer itself to achieve this?

Hi @Dan_Weaver,

Thanks for your post. I assume you’re using a custom textstyle that you developed yourself. In this case, you have a couple options.

Option 1 would be to keep most of your custom textstyle code in a base TextStyle class and then create smaller subclasses for the different label positioning. The would let you reuse most of your custom TextStyle code.

Option 2 may be more of what you’re asking. If your data has columns with values that you want to use to determine the label’s postion, then you could create a custom value style to switch the label’s position based on that data point’s column value.

Also, to find out more on our existing styles and how to extend, check out this blog post and extensibility guide. There’s this older post about creating a custom ValueStyle.

Let us know if you have other question or if I did not understand your original question.

Thanks,
John

Sorry “custom” might not be the right word, it’s just a simple textstyle. There aren’t any columns that will be used to determine the position. Let’s say I have a textstyle I am using for multiple layers. This is the same instance of textstyle used for each layer’s DefaultTextStyle so when I update the textstyle’s color or size or whatever, it updates for all the layers using it.

However, I want to set the label position on the layer level, so that even though I’m using the same textstyle for each layer, the label position can be different. Is this possible?

Thanks!

Hi @Dan_Weaver,

Thank you for the clarification. In general, the same instance of a style should not be used on multiple layers. It’s easier and there’s no real performance hit from just instantiating a new style for each layer - especially if the layer labels need to be style differently.

If you have a data column that you want to style on, this is possible to do with the same instance of a style, but that doesn’t seem like your scenario.

Is there a reason you need to u se the same instance of a style for multiple layers? If not, it’s really better to use different instances of styles.

Thanks,
John

Eh not exactly, it’s just a lot to refactor to switch to multiple instances in the current codebase and when we updated a style we wanted it to apply to every layer/feature using that style because the only thing we ever really want different is the label position. But like you said, there’s no performance issue so maybe refactoring is the best bet.

Thanks for the info!

Thanks Dan.

Sorry this structure isn’t the best for your codebase. If you send a portion of your codebase to support@thinkgeo.com I can go over it more in detail and then confirm with the product team that there’s not a better solution.

Thanks,
John