Example: Style Overrides

Style overrides allow us to specify exceptions to the default, layer-wide style properties specified by the Contents - Style panel for drawings and labels.   Before proceeding, please read the Style: Overrides topic.




We begin with a map that has one layer, called Regions, a drawing that shows the regions of France as areas.   This drawing shows French regions after the recent consolidation of regions into a smaller number of larger regions.   The areas in the drawing use default, black and gray style. We have used the Layers panel to specify a nice shade of blue for the background, to liven up the display despite the drab, default formatting.




Opening the drawing's table we see it has three fields, an mfd_id field as usual for drawings, a Name text field and a Geom field that contains geom data defining each area.




With the focus on the map, in the Contents - Style panel we can see default black and gray formatting is used for style properties.   We click the Options tab.   




We click New Field to create a new text field that will be used for style overrides.  The new field will contain the style JSON string for each record that is used to specify an individual style for that record, thus overriding the overall style.  We could use an existing, text field if there happens to be an otherwise unused text field in the table's schema, but it is usually a good idea to create a new field and to name that field Style so we know what it is intended to be.




In the New Field dialog we accept the default field name of Style.  We could name the field whatever we want, but most Manifold users get into the habit of using the default name, Style, so the purpose of the field is obvious when viewing a table or a table's schema.  Press OK.  




The dialog resets back to the opening, default tab.  We click again on the Options tab.




Back in the Options tab, we check the Use style overrides box.   If there is a text field in the table called Style, by default that will be loaded into list of available text fields.   We could use another text field, but, again, most Manifold users will get into the habit of using field named "Style" to store style override data.   Press the Update Options button.




A new text field called Style appears in the table.  It is filled with NULLs since so far we have not specified any style overrides for any areas in the drawing.




To specify a style override, we Alt-click an area to choose it as the context object for the Record panel.   The area is marked with small blue boxes at the vertices of the area.   




The Record panel immediately pops into action, showing field values for that object. We see we have clicked the area for Centre-Val de Loire, a truly fine region of France, the historical heart of the country.  We click on the Style tab.




The Style tab shows the style properties applied to the area.  By default, these are the same style properties set in Contents - Style for the entire layer, with the area symbol being a total style button.   We click the Fill Color button to change fill color from the default gray to green.


Important:  If the Use style overrides box has not been checked in Contents - Style - Options, we will not be able to change the style used by this object.  We can only change these style properties if we have checked the Use style overrides box.



When we change the fill color to green a square icon appears on the button to indicate we have specified a style override.  We press Update Record to apply the change.


eg_style_override01_11a.png  eg_style_override01_11.png


Immediately, our area is rendered using the green fill color we specified.    We can clean up the display by alt-clicking an empty spot on the map to clear the context status of the area, so it is not highlighted with a necklace of blue dots.




If we look in the drawing's table we see that the Style field for the Centre-Val de Loire record has acquired a JSON text string for the style override we specified.  All the other areas have NULLs in their Style field because we only specified a style override for one area.


One of the great things about saving style overrides in text fields is that we can uncheck and then re-check the Use style overrides box without losing the style overrides we have specified.





If we uncheck the Use style overrides box and press the Update Options button the system stops using style overrides.   It applies to all objects whatever style has been specified in the Contents - Style panel.





If we check the Use style overrides box and press the Update Options button again, the system once more starts using style overrides.  Any style overrides in the Style field are applied.  






We uncheck Use style overrides and press the Update Options button, and then we click the Contents - Style panel to change style properties for the layer.




In the Style panel we set a thematic format that colors regions of France using their names as unique values.




In the map we see the effect as each region is colored by the thematic format based on region name.  




In the Options tab we check the Use style overrides box and press the Update Options button.




The style override we specified earlier takes effect.  We see that the style override for the Centre Val de Loire region is still there.

Finding all Objects with Style Overrides

If we look at a map where objects are styled in a variety of ways we may want to know which are styled using the layer style properties specified by Contents - Style and which are styled using a style override.


That is easy to do using the Select panel.




We open the drawing's table, and then with the focus on the opened table in the Select panel we choose the Non-null Values template using the Style field.  Press Replace Selection.




That immediately selects all records where the Style field value is not NULL.  In this case, only one record is selected, shown above using red selection color.




The corresponding area automatically also is selected in the map and also shown in red selection color.

Clearing a Style Override

Suppose we have some style overrides set for various objects in our drawing, and we would like to clear those, that is not have them any more.   That is easy to do, by simply setting the values of the Style field for those objects to NULL.   We can do that using the Transform panel, a useful approach if we want to set the value to NULL in many records, or we can use an Alt-click on each object to remove the style override using the Record pane.


Using the Transform panel:


Clearing style overrides for all objects is simple:  we copy a NULL into the Style field for each record.   To do that we launch the Transform panel.  




We choose Style as the target field, Copy as the transform template, and then after choosing the Expression setting for the Value box we enter NULL for the expression.  Press Update Field.


If we like, we can choose only some objects for which the style override will be cleared.   To do that we select all the desired objects, either in the drawing or in the table.   we launch the Transform panel.  




We check the Restrict to selection box, choose Style as the target field, Copy as the transform template, and then after choosing the Expression setting for the Value box we enter NULL for the expression.  Press Update Field.


Important: we check the Restrict to selection box, since we only want to put NULLs into the Style field only for selected records.




Right away, the panel previews for us in blue preview color what it will do.  For example, if we had selected the Centre-Val de Loire record we can see from the illustration above that the Copy template with Restrict to selection checked will put a NULL into the Style value for the selected record.  We click the Update Field button.




A NULL appears in the Style field.    We choose Edit - Select None to clear the selection and thus to clean up the display.




In the map we see that there is no longer any style override applied to the Centre-Val de Loire area.    In the example above there was only one record that was selected, but if we had thousands of objects using a style override and we had selected them all, we could have instantly cleared the style override for all of those thousands of objects at once in a single step using the same procedure.


Using the Transform panel:


Another way to clear a style override is to manually Alt-click each object for which we would like to clear the style override and then use the Record panel.




We Alt-click the Centre-Val de Loire area to choose it for use in the Record panel.




In the Record panel's Style tab we click on the Fill Color property.   




In the drop down menu we choose Default.  




That clears the style override.  The square icon indicating a style override disappears from that style property's button, and the style property button shows the brown color assigned to that area by the thematic format which is specified for the entire layer.   We press the Update Record button to apply the changes.




Back in the map, we see that there is no longer any style override applied for the Centre-Val de Loire area.

Copying and Pasting Style Overrides between Objects

Because style overrides are simply non-NULL strings in the Style field we can copy and paste them between records if we want to apply the same style overrides to other objects.




Consider our example with a style override in use for the Centre-Val de Loire area, as seen above.




The style override is simply a string value in the Style field for the Centre-Val de Loire record.   We can copy and paste it just like any other string.



For example, we can right-click onto the Style cell for the Centre-Val de Loire record and choose Copy.  



We can then right-click onto the Style cell for the Hauts-de-France record and choose Paste.




That copies the style override string from the Centre-Val de Loire record and pastes it into the Hauts-de-France record.




Like magic, when we refresh the map view (choose View - Refresh or pan or zoom the view) the Hauts-de-France area is also colored with the same style override as used by the Centre-Val de Loire area.



We can right-click onto the Style cell for the Normadie record and Paste again.




That pastes the style override into the Normandie record.




Refreshing the map shows that the Normandie area now also uses the same style override.

Multiple Style Override Fields

We can have style override strings in more than one field in a table.   Whatever style override field we tell the system to use in the Contents - Style - Options tab will be used.




For example, suppose we use Edit - Schema to add an nvarchar field called Style 2 to the Regions Table.




In the Contents - Style - Options tab we check the Use style overrides box and in the pull-down list of available text fields we choose Style 2.    




That will now be the field the system will use as a source of style overrides for each object.   We press the Update Options button.




The map shows default formatting for all areas, because all of the areas have NULLs, that is no style overrides, in their Style 2 field.


Let us add some style overrides:




We Alt-click on the Pays de la Loire area.  




In the Record panel's Style tab we change the fill color to yellow and we press Update Record.   That creates a style override for that object.




The Pays de la Loire area appears in yellow.   We Alt-click the Centre-Val de Loire area.




We specify a magenta fill color and press Update Record.




We alt-click into an empty part of the map to clear up the display.   We now have two areas that use style overrides.




If we open the Regions Table we see that style override strings have been added to the Style 2 field for two records.


If we like, we can switch back and forth between using the two different style override fields.





In the Contents - Style - Options tab we choose Style as the field to use with style overrides.  We press the Update Options button.   Right away, the map uses the style overrides from that field.





In the Contents - Style - Options tab we choose Style 2 as the field to use with style overrides.   We press the Update Options button.   Right away, the map uses the style overrides from that field.


Style Overrides in Properties and the mfd_meta Table

We may want to use SQL or scripts to manipulate the use of style overrides.   How can we see if style overrides are in use, and, if they are, which field do they use?




Right-clicking a drawing in the Project panel and choosing Properties will show the properties for that drawing.  If Use style overrides has been checked for that drawing, it will contain a StyleOverrides property, the value of which will be the name of the field from which style overrides are used.   In the illustration above we see that style overrides are in use and that the Style field provides those overrides.




In the illustration above we see that style overrides are in use and that the Style 2 field provides those overrides.




In the illustration above there is no StyleOverrides property for the drawing, so we know that style overrides are not in use.




If we would like to access or to manipulate style overrides with SQL or programmatically, we can see in the mfd_meta System Data table if a layer has style overrides in use.  From the illustration above we can see that the Regions drawing uses style overrides, using the Style 2 field.



Is the field named 'Style' special?   - Yes and no.  The Use style overrides facility will look for a text field called Style in the drawing's table and, if a field named Style exists, that field will be used by default to store any style overrides.  We can choose a different text field if we like.   If a field named Style does not exist, the (new field) choice will create an nvarchar text field called Style.   If we already have a field called Style and we choose (new field), that will create a field called Style 2 and so on.   But there is nothing special about the name 'Style' other than it is short and easy to remember.  It also is more self-documenting than using the name 'Ringo' or 'Beatrice' for a field that will store style override text.


Why nvarchar?  Can it be a varchar?  - Yes, if we prefer.  Manifold uses nvarchar text type by default because supporting Unicode is good karma in an application that is used in many different countries.


Are style overrides a replacement for thematic formatting?  - No.  Style overrides generally are intended for special case needs, to be applied in an ad hoc manner.   For example, suppose we have thematically formatted a map for cartographic reasons but when it comes time to print there is one area that just does not look right, for which a slightly lighter color would look better.   If we are in a hurry, instead of spending more time tinkering with thematic formats we could simply take a brute force approach and use a style override to color that one area exactly the color which looks good in the layout.


Another good use for style overrides is when creating labels manually to annotate a map.   Style overrides allow us to manually specify the style of each label, such as size, font and color that we create.   When the numbers of labels are limited it is often easier to simply use style overrides than to organize a limited number of labels into several different layers that can all be formatted in the usual way.  


See Also









Style: Drawings


Style: Labels


Style: Overrides


Contents Pane


Contents - Record


Contents - Select


Contents - Transform


Example: Style Panel Quickstart - A tutorial introduction to using the Style panel in the Contents pane to apply color, symbology, size and rotation to areas, lines and points in drawings.