Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
drawGeometry = model => {
const json = model.toJSON()
const isMultiPolygon = ShapeUtils.isArray3D(json.polygon)
const polygons = isMultiPolygon ? json.polygon : [json.polygon]
// first destroy old one
if (this.primitive && !this.primitive.isDestroyed()) {
this.map.scene.primitives.remove(this.primitive)
}
this.primitive = new Cesium.PolylineCollection()
this.cameraMagnitude = this.map.camera.getMagnitude()
;(polygons || []).forEach(polygonPoints => {
if (!polygonPoints || polygonPoints.length < 3) {
return
}
if (
polygonPoints[0].toString() !==
polygonPoints[polygonPoints.length - 1].toString()
) {
polygonPoints.push(polygonPoints[0])
}
polygonPoints.forEach(point => {
point[0] = DistanceUtils.coordinateRound(point[0])
point[1] = DistanceUtils.coordinateRound(point[1])
})
return
}
const turfLine = Turf.lineString(setArr)
let bufferedLine = turfLine
this.cameraMagnitude = this.map.camera.getMagnitude()
if (lineWidth > 100 || this.cameraMagnitude < CAMERA_MAGNITUDE_THRESHOLD) {
bufferedLine = Turf.buffer(turfLine, Math.max(lineWidth, 1), 'meters')
}
// first destroy old one
if (this.primitive && !this.primitive.isDestroyed()) {
this.map.scene.primitives.remove(this.primitive)
}
this.primitive = new Cesium.PolylineCollection()
this.primitive.add(
this.constructLinePrimitive(bufferedLine.geometry.coordinates)
)
this.map.scene.primitives.add(this.primitive)
}
}
create(context, props) {
if (!context.primitiveCollection) return;
const element = new CesiumPolylineCollection({
modelMatrix: props.modelMatrix,
debugShowBoundingVolume: props.debugShowBoundingVolume,
length: props.length, //
scene: context.scene,
} as any);
context.primitiveCollection.add(element);
return element;
},
destroy(element, context) {
addLine(line, options) {
const lineObject = line.map(coordinate =>
convertPointCoordinate(coordinate)
)
const cartPoints = _.map(lineObject, point =>
Cesium.Cartographic.fromDegrees(
point.longitude,
point.latitude,
point.altitude
)
)
const cartesian = map.scene.globe.ellipsoid.cartographicArrayToCartesianArray(
cartPoints
)
const polylineCollection = new Cesium.PolylineCollection()
const polyline = polylineCollection.add({
width: 8,
material: Cesium.Material.fromType('PolylineOutline', {
color: determineCesiumColor(options.color),
outlineColor: Cesium.Color.WHITE,
outlineWidth: 4,
}),
id: options.id,
positions: cartesian,
})
if (map.scene.terrainProvider) {
const promise = Cesium.sampleTerrain(
map.scene.terrainProvider,
5,
cartPoints
return
}
this.destroyOldPrimitive()
const coordinates = [
[rectangle.east, rectangle.north],
[rectangle.west, rectangle.north],
[rectangle.west, rectangle.south],
[rectangle.east, rectangle.south],
[rectangle.east, rectangle.north],
]
const color = this.model.get('color')
this.primitive = new Cesium.PolylineCollection()
this.primitive.add({
width: 8,
material: Cesium.Material.fromType('PolylineOutline', {
color: color
? Cesium.Color.fromCssColorString(color)
: Cesium.Color.KHAKI,
outlineColor: Cesium.Color.WHITE,
outlineWidth: 4,
}),
id: 'userDrawing',
positions: Cesium.Cartesian3.fromRadiansArray(_.flatten(coordinates)),
})
this.options.map.scene.primitives.add(this.primitive)
this.options.map.scene.requestRender()
},
create: function (cprops, props, context) {
return new Cesium.PolylineCollection({
modelMatrix: cprops.modelMatrix,
debugShowBoundingVolume: cprops.debugShowBoundingVolume,
length: cprops.length,
scene: context.scene,
});
},
mount: function (element, context) {
addLine: function (line, geocontroller, options) {
var lineObject = line.map(function (coordinate) {
return convertPointCoordinate(coordinate);
});
var cartPoints = _.map(lineObject, function (point) {
return Cesium.Cartographic.fromDegrees(point.longitude, point.latitude, point.altitude);
});
var cartesian = geocontroller.ellipsoid.cartographicArrayToCartesianArray(cartPoints);
var polylineCollection = new Cesium.PolylineCollection();
var polyline = polylineCollection.add({
width: 8,
material: Cesium.Material.fromType('PolylineOutline', {
color: determineCesiumColor(options.color),
outlineColor: Cesium.Color.WHITE,
outlineWidth: 4
}),
id: options.id,
positions: cartesian
});
if (geocontroller.scene.terrainProvider) {
var promise = Cesium.sampleTerrain(geocontroller.scene.terrainProvider, 5, cartPoints);
Cesium.when(promise, function (updatedCartographic) {
var positions = geocontroller.ellipsoid.cartographicArrayToCartesianArray(updatedCartographic);
if (updatedCartographic[0].height && !options.view.isDestroyed) {
}
const color = this.model.get('color')
const centerPt = Turf.point([modelProp.lon, modelProp.lat])
const circleToCheck = new TurfCircle(
centerPt,
DistanceUtils.getDistanceInMeters(
modelProp.radius,
modelProp.radiusUnits
),
64,
'meters'
)
this.primitive = new Cesium.PolylineCollection()
this.primitive.add({
width: 8,
material: Cesium.Material.fromType('PolylineOutline', {
color: color
? Cesium.Color.fromCssColorString(color)
: Cesium.Color.KHAKI,
outlineColor: Cesium.Color.WHITE,
outlineWidth: 4,
}),
id: 'userDrawing',
positions: Cesium.Cartesian3.fromDegreesArray(
_.flatten(circleToCheck.geometry.coordinates)
),
})
this.options.map.scene.primitives.add(this.primitive)