Styling

Styling Items

Basic item styling is defined within the data objects for each layer. The items available for styling are:

The map below shows a simple network defined in the network layer. The color has been set for nodes, links, labels and text and an arrow has been added to end2 of the link with arrow.

Expand to see the charging stations object.
const linkColor = '#FD9067';
const textColor = '#F4F4F5';
const labelColor = '#6E7379';
const freeNodeColor = '#FD9067';
const fixedNodeColor = '#774299';

export const chargingStations = {
  Mainland: {
    type: 'node',
    color: fixedNodeColor, // sets the color of the node
    latitude: 49.27684,
    longitude: -123.11887,
    label: {
      text: '959-979 Mainland St',
      color: textColor, // sets the color of the label text
      backgroundColor: labelColor, // sets the background color of the label
    },
  },
  Vancouver: {
    type: 'node',
    color: freeNodeColor, // sets the color of the node
    label: {
      text: 'City of Vancouver',
      color: textColor, // sets the color of the label text
      backgroundColor: labelColor, // sets the background color of the label
    },
  },
  Beach: {
    type: 'node',
    color: fixedNodeColor, // sets the color of the node
    latitude: 49.272594,
    longitude: -123.12836,
    label: {
      text: '456 Beach Crescent',
      color: textColor, // sets the color of the label text
      backgroundColor: labelColor, // sets the background color of the label
    },
  },
  Richards: {
    type: 'node',
    color: fixedNodeColor, // sets the color of the node
    latitude: 49.279403,
    longitude: -123.118908,
    label: {
      text: '860 Richards St',
      color: textColor, // sets the color of the label text
      backgroundColor: labelColor, // sets the background color of the label
    },
  },
  link1: {
    type: 'link',
    color: linkColor, // sets the color of the link
    id1: 'Vancouver',
    id2: 'Mainland',
    end2: { arrow: true }, // adds an arrow to the id2 end of the link
  },
  link2: {
    type: 'link',
    color: linkColor, // sets the color of the link
    id1: 'Vancouver',
    id2: 'Beach',
    end2: { arrow: true }, // adds an arrow to the id2 end of the link
  },
  link3: {
    type: 'link',
    color: linkColor, // sets the color of the link
    id1: 'Vancouver',
    id2: 'Richards',
    end2: { arrow: true }, // adds an arrow to the id2 end of the link
  },
};

Styling Network Playground

Log in to view live examples

Styling Network Playground

Log in to view live examples

Override Item Styles

All styles set in the layer data can be dynamically overridden without changing the values in that data. Use the overrideStyle API to update the styling. To clear any style overrides, store the StyleReset function returned when calling overrideStyle (e.g. in a variable) and then call that StyleReset function.

All styles set in the layer data can be dynamically overridden without changing the values in that data. Use the overrideStyles API to update the styling.

The following map of Zürich uses the observations layer to show the path of a drone (created from a subset of GPS coordinates from The Zurich Urban Micro Aerial Vehicle Dataset) and a GeoJSON feature showing the area within 750m of the main train station, Zürich Hauptbahnhof.

Click Override Style to change the color of the observations within the radius to yellow. Click Reset Style to remove the overridden color.

A code snippet is shown below, or open the example in the playground to see the full code.

Override Style Playground

Log in to view live examples

Override Style Playground

Log in to view live examples
// create a variable to store the reset function
let resetStyleFunction;
// override the style when a button is clicked
overrideButton.addEventListener('click', () => {
  // reset any overridden styles
  resetStyleFunction?.();
  // override the style for 'obs10' and store the function to reset the styles
  resetStyleFunction = myObservationsLayer.overrideStyle('obs10', { color: '#FFC40C' });
});

// remove the override style when a button is clicked
resetButton.addEventListener('click', () => resetStyleFunction?.());
function App() {
  // define the styles to override
  let overriddenStyles = { ids: 'myObservationId', overrideStyle: { color: '#FFC40C' } };
  return (
    <>
      <MapWeave options={options}>
        {/* Add the overrideStyles prop to the observations layer */}
        <ObservationsLayer data={myData} overrideStyles={overriddenStyles} />
      </MapWeave>
    </>
  );
}

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.