rebuildLabel();
The rebuildLabel method rerenders label for map layer area.
To execute the example the HTML page must contain the MapChart component named map (see Example of Creating the MapChart Component). Draw a label for the map layer area with the RU-KYA identifier. Next decrease the map scale and refresh position of the created label:
// Get map layer area with the RU identifier // Get map layer area with the RU identifier var shape = map.getShape("RU-KYA"); // Enable tooltip displaying shape._tooltipOn = true; // Get rectangle that limits map layer area var bounds = shape.getBoundsRect(); // Define label offsets from the left and top map edge var labelLeft = bounds.getLeft() + bounds.getWidth() / 4 + (map.getWidth() - map.getTopobaseSize().width) / 2; var labelTop = bounds.getTop() + bounds.getHeight() / 2 + (map.getHeight() - map.getTopobaseSize().height) / 2; // Create a label var label = new PP.MapLabel({ Chart: map, MaskText: "{%Name}", // Text mask Left: labelLeft, Top: labelTop, }); // Set label for map layer area shape.setLabel(label); // Redraw the label shape.rebuildLabel(label); // Determine map center var pointZoom = new PP.Point(map.getWidth() / 2, map.getHeight() / 2); // Set map scale to 0.5 map.setScale(0.5, pointZoom, 0, 0); // Indicate that a label is set for data layer area shape._labelOn = true; // Set initial center of map layer area to refresh label position shape._labelOrigX = bounds.getLeft() + bounds.getWidth() / 2; shape._labelOrigY = bounds.getTop() + bounds.getHeight() / 2; // Refresh label position shape.updateLabelPosition();
After executing the example a label with the text that contains area name is drawn for the map layer area with the RU-KYA identifier. After reducing the map scale by two, label position is updated:
See also: