[QUOTE]
Михаил Перевёрткин написал:
Вот как пробую я. Компонент по введенной долготой, широтой и радиусом рисует окружность:
[CODE] private circleObject = new MapObject( new VectorLayer(this.map, {
alias: '',
id: Utils.generateGUID(),
url: '',
}),
MapObjectType.MultiPolygon,
{ local: LOCALE.Plane }
);
drawObject(value: any) {
const pointSelector: PointSelector = { contourNumber: this.circleCount++ };
const center = this.map.geoToPixel(
new GeoPoint(value.longitude, value.latitude, 0, this.map.ProjectionId),
this.mapWindow.getMap().getZoom()
);
let radius_meter = value.radius * 1000 || 0;
const latitude = Number(value.latitude) || 0.1;
const longitude = Number(value.longitude)|| 0.1;
const mapCalculator = new GWTK.MapCalculations(this.map);
const pointXYComp = mapCalculator.mapDirectPositionComputation(latitude, longitude, 0, 0);
const pointGeo = new GeoPoint(pointXYComp.l, pointXYComp.b);
const pointXY = pointGeo.toMapPoint();
this.customFields = { radius_meter, pointXY };
for (let numberPoint = 0; numberPoint < 361; numberPoint = numberPoint + 10) {
const positions = mapCalculator.mapDirectPositionComputation(latitude, longitude, numberPoint, radius_meter);
if (positions) {
console.log(pointSelector);
this.circleObject.addGeoPoint(new GeoPoint(positions.l, positions.b), pointSelector);
}
}
//this.circleObject.closeObject();
this.map.setActiveObject(this.circleObject);
// Показать значение радиуса
this.showLabel(center.x, center.y, radius_meter);
//this.map.fitBounds(this.circleObject.getBounds());
} [/CODE]
При выполнении метода ошибка
[CODE] Cannot read properties of undefined (reading 'map')
TypeError: Cannot read properties of undefined (reading 'map')
at MultiLineGeometry.getPointListForDrawing (eval at ./GIS WebToolKit SE/debug/source/mapobject/geometry/MultiLineGeometry.ts (http://localhost:8080/js/app.js:3705:1), <anonymous>:193:54)
at MultiPolygonGeometry.getPointListForDrawing (eval at ./GIS WebToolKit SE/debug/source/mapobject/geometry/MultiPolygonGeometry.ts (http://localhost:8080/js/app.js:3727:1), <anonymous>:140:123)
at MapObject.getPointListForDrawing (eval at ./GIS WebToolKit SE/debug/source/mapobject/MapObject.ts (http://localhost:8080/js/app.js:3650:1), <anonymous>:965:26)
at Function.eval (eval at ./GIS WebToolKit SE/debug/source/renderer/SVGrenderable.ts (http://localhost:8080/js/app.js:3826:1), <anonymous>:192:32)
at step (webpack-internal:///./node_modules/tslib/tslib.es6.mjs:181:21)
at Object.eval [as next] (webpack-internal:///./node_modules/tslib/tslib.es6.mjs:162:51)
at eval (webpack-internal:///./node_modules/tslib/tslib.es6.mjs:155:69)
at new Promise (<anonymous>)
at __awaiter (webpack-internal:///./node_modules/tslib/tslib.es6.mjs:151:10)
at SVGrenderable.createGroupNode (eval at ./GIS WebToolKit SE/debug/source/renderer/SVGrenderable.ts (http://localhost:8080/js/app.js:3826:1), <anonymous>:187:61) [/CODE] [/QUOTE]
В текущем примере круг добавляется в виде нового контура для первого полигона геометрии (то есть второй и последующие контуры будут считаться вырезом для первого).
Для добавления самостоятельного контура в селекторе нужно использовать номер объекта:
[CODE] const pointSelector: PointSelector = { objectNumber: this.circleCount++ };[/CODE]
Ошибка же предположительно возникает из-за свойства this.circleCount - оно проинициализировано числом (0)?