Code example
import { useState } from 'react';
import { createGeoPoint, createMapCameraPosition } from '@mapconductor/js-sdk-core';
import { MapLibreDesign, MapLibreMapView2D, useMapLibreViewState } from '@mapconductor/react-for-maplibre';
// (1) Create the map
const initialCamera = createMapCameraPosition({
position: createGeoPoint({ latitude: 35.6812, longitude: 139.7671 }),
zoom: 12,
});
const mapViewState = useMapLibreViewState({
mapDesignType: MapLibreDesign.OsmBrightJa,
cameraPosition: initialCamera,
});
// (2) Prepare the data and interaction state
const [palette, setPalette] = useState({
water: '#3a7ca5',
land: '#f2efe6',
street: '#ffffff',
building: '#d9d0c9',
});
// A rule reaches layers by role, so the same words work in someone
// else's style. mix blends each layer's own colour toward the picked
// one; visible: false leaves the layers out of the document, so they
// are not drawn at all.
const rules = buildStyleRules((r) => {
r.role(LayerRole.water, { colorFilter: { mix: { color: palette.water, amount: strength } } });
r.role(LayerRole.building, { visible: false });
});
// (3) Render the map and its overlays
<MapLibreMapView2D state={mapViewState}>
<VectorTileLayer style={style} rules={rules} opacity={opacity} />
</MapLibreMapView2D>
How the code works
Draws a MapLibre vector style on any backend by rasterising it in the browser and serving the result as ordinary raster tiles.
The backend never sees a vector style, which is what makes this work on Google Maps, MapKit, Cesium and the rest — none of them can read one.
Changing a colour replaces the style and re-rasterises the vector tiles already in memory. Nothing is fetched again: the geometry did not change, only the paint applied to it. Symbol layers are not drawn, because placing labels without collisions needs to see neighbouring tiles.