Optimization of work with graphics
For definitions and basic concepts, see:
Dynamic: true/false mode
The dynamic parameter in the data source (MMapFeatureDataSource) determines how the objects update on the map:
- dynamic: true (by default) - provides synchronous update of graphics. It is recommended for interactive tools (editors, ruler), where an instant interface reaction is important.
- dynamic: false - provides high performance with a large number of objects, but the update of the graphics occurs asynchronously (UI can launch when editing).
Current implementation: for dynamic: true, a raster engine (SVG) is used, for dynamic: false - vector (Webgl). This is a detail of the implementation and not part of the public API. In the future, behavior may change, do not rely on the choice of the engine directly.
Practical scenarios
- Mass display (1000+ objects): Use dynamic: false.
- Interactive scenarios (editing, ruler): Use dynamic: true.
- For hybrid scenarios: the main array of objects - Datasource C dynamic: false, editable object - separate Datasource with dynamic: true.
Examples
vanilla
react
const featuresSource = new MMapFeatureDataSource({ id: 'features', dynamic: false });
map.addChild(featuresSource);
map.addChild(new MMapLayer({ source: 'features', type: 'features' }));
const polygon = new MMapFeature({
geometry: { type: 'Polygon', coordinates: [coords] },
style: POLYGON_STYLE,
source: 'features'
});
featuresSource.addChild(polygon);
<MMapFeatureDataSource id="features" dynamic={false} />
<MMapLayer source="features" type="features" />
<MMapFeature geometry={{ type: 'Polygon', coordinates: [coords] }} style={POLYGON_STYLE} source="features" />
Features Z-index and layers order
- The raster layer (dynamic: true) is always displayed on top of the vector (dynamic: false), regardless of the value of Z-index.
- You can not place a raster layer under vector - this is a limitation of the architecture of engines.
- If you need to display features under buildings or other objects of the scheme, use only the vector layer (dynamic: false) and correctly set up the layers through Z-index.
Read more about the order of layers and Z-index, see Layers orders.
Recommendations
- Do not mix interactive and mass objects in one Datasource.
- For scripts with editing one object of a thousand: temporarily transfer it to Datasource with dynamic: true, then return back.
- Always indicate the meaning of dynamic clearly in critical scenarios to avoid unexpected behavior in API updates.