/
githubmirror
/
Leaflet
Обзор
Документация
Войти
/
githubmirror
/
Leaflet
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/layer/vector/Rectangle.js
50 строк
1 KB
Simon Legner
Use super to access methods on superclass (#9902)
22 сен 2025, 12:48
Не верифицирован
22 сен 2025, 12:48
13b14dc
Код
Авторство
О чём код?
import {Polygon} from './Polygon.js'; import {LatLngBounds} from '../../geo/LatLngBounds.js'; /* * Rectangle extends Polygon and creates a rectangle when passed a LatLngBounds object. */ /* * @class Rectangle * @inherits Polygon * * A class for drawing rectangle overlays on a map. Extends `Polygon`. * * @example * * ```js * // define rectangle geographical bounds * const bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]]; * * // create an orange rectangle * new Rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map); * * // zoom the map to the rectangle bounds * map.fitBounds(bounds); * ``` * */ // @constructor Rectangle(latLngBounds: LatLngBounds, options?: Polyline options) export class Rectangle extends Polygon { initialize(latLngBounds, options) { super.initialize(this._boundsToLatLngs(latLngBounds), options); } // @method setBounds(latLngBounds: LatLngBounds): this // Redraws the rectangle with the passed bounds. setBounds(latLngBounds) { return this.setLatLngs(this._boundsToLatLngs(latLngBounds)); } _boundsToLatLngs(latLngBounds) { latLngBounds = new LatLngBounds(latLngBounds); return [ latLngBounds.getSouthWest(), latLngBounds.getNorthWest(), latLngBounds.getNorthEast(), latLngBounds.getSouthEast() ]; } }