Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const normalizedOffsets = (
offset?: number | Point | AnchorsOffset | [number, number]
): AnchorsOffset => {
if (!offset) {
return normalizedOffsets(new Point(0, 0));
}
if (typeof offset === 'number') {
// input specifies a radius from which to calculate offsets at all positions
const cornerOffset = Math.round(Math.sqrt(0.5 * Math.pow(offset, 2)));
return {
center: new Point(offset, offset),
top: new Point(0, offset),
bottom: new Point(0, -offset),
left: new Point(offset, 0),
right: new Point(-offset, 0),
'top-left': new Point(cornerOffset, cornerOffset),
'top-right': new Point(-cornerOffset, cornerOffset),
'bottom-left': new Point(cornerOffset, -cornerOffset),
'bottom-right': new Point(-cornerOffset, -cornerOffset)
};
}
if (offset instanceof Point || Array.isArray(offset)) {
// input specifies a single offset to be applied to all positions
return anchors.reduce(
(res, anchor) => {
res[anchor] = Point.convert(offset);
return res;
},
// tslint:disable-next-line:no-object-literal-type-assertion
it('findMTSPPaths', (done) => {
var findMTSPPathsParameter = new FindMTSPPathsParameters({
centers: [new mapboxgl.Point(6000, -5500), new mapboxgl.Point(5500, -2500), new mapboxgl.Point(2500, -3500)],
isAnalyzeById: false,
nodes: [new mapboxgl.Point(5000, -5000), new mapboxgl.Point(6500, -3200)],
hasLeastTotalCost: true,
});
var service = new NetworkAnalystService(url, options);
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl) => {
expect(method).toBe("GET");
expect(testUrl).toBe(url + "/mtsppath.json?");
return Promise.resolve(new Response(JSON.stringify(findMTSPPathsResultJson)));
});
service.findMTSPPaths(findMTSPPathsParameter, (result) => {
serviceResult = result;
try {
expect(service).not.toBeNull();
expect(serviceResult).not.toBeNull();
expect(serviceResult.type).toEqual("processCompleted");
expect(serviceResult.result.succeed).toBe(true);
expect(serviceResult.result.pathList.length).toEqual(2);
var broadcast_Point = (flowService) => {
var feature = {
geometry: {
coordinates: new mapboxgl.Point(5605, -3375),
type: "Point"
},
id: 1,
type: "Feature",
properties: {
id: 1,
time: new Date()
}
};
flowService.broadcast(feature);
}
returnEdgeFeatures: true,
returnEdgeGeometry: true,
returnEdgeIDs: true,
returnNodeFeatures: true,
returnNodeGeometry: true,
returnNodeIDs: true,
returnPathGuides: true,
returnRoutes: true
});
var analystParameter = new TransportationAnalystParameter({
resultSetting: resultSetting,
weightFieldName: "length"
});
var findPathParameters = new FindPathParameters({
isAnalyzeById: false,
nodes: [new mapboxgl.Point(4000, -3000), new mapboxgl.Point(5500, -2500), new mapboxgl.Point(6900, -4000)],
hasLeastEdgeCount: false,
parameter: analystParameter
});
var service = new NetworkAnalystService(url, options);
spyOn(FetchRequest, 'commit').and.callFake((method, testUrl) => {
expect(method).toBe("GET");
expect(testUrl).toBe(url + "/path.json?");
return Promise.resolve(new Response(JSON.stringify(findPathResultJson)))
});
service.findPath(findPathParameters, (result) => {
serviceResult = result;
try {
expect(service).not.toBeNull();
expect(serviceResult).not.toBeNull();
expect(serviceResult.type).toEqual("processCompleted");
expect(serviceResult.result.succeed).toBe(true);
rotationBounds(bounds, rotationCenterPoi, angle) {
var ltPoi = new mapboxgl.Point(bounds.left, bounds.top);
var rtPoi = new mapboxgl.Point(bounds.right, bounds.top);
var rbPoi = new mapboxgl.Point(bounds.right, bounds.bottom);
var lbPoi = new mapboxgl.Point(bounds.left, bounds.bottom);
var ver = [];
ver.push(this.getRotatedLocation(ltPoi.x, ltPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rtPoi.x, rtPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rbPoi.x, rbPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(lbPoi.x, lbPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
//bounds旋转后形成的多边形节点数组
var quad = [];
for (var i = 0; i < ver.length; i++) {
quad.push({
"x": ver[i].x,
"y": ver[i].y
});
_onZoom({pos, scale}) {
const point = new Point(...pos);
const transform = cloneTransform(this._map.transform);
const around = unprojectFromTransform(transform, point);
transform.zoom = transform.scaleZoom(this._map.transform.scale * scale);
transform.setLocationAtPoint(around, point);
this._callOnChangeViewport(transform, {isDragging: true});
}
rotationBounds(bounds, rotationCenterPoi, angle) {
var ltPoi = new mapboxgl.Point(bounds.left, bounds.top);
var rtPoi = new mapboxgl.Point(bounds.right, bounds.top);
var rbPoi = new mapboxgl.Point(bounds.right, bounds.bottom);
var lbPoi = new mapboxgl.Point(bounds.left, bounds.bottom);
var ver = [];
ver.push(this.getRotatedLocation(ltPoi.x, ltPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rtPoi.x, rtPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rbPoi.x, rbPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(lbPoi.x, lbPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
//bounds旋转后形成的多边形节点数组
var quad = [];
for (var i = 0; i < ver.length; i++) {
quad.push({
"x": ver[i].x,
getLabelPxLocation(feature) {
var geoText = feature.geometry;
var styleTmp = feature.style;
//将标签的地理位置转为像素位置
var locationTmp = geoText.getCentroid();
var locTmp = this.map.project(new mapboxgl.LngLat(locationTmp.x, locationTmp.y));
var loc = new mapboxgl.Point(locTmp.x, locTmp.y);
//偏移处理
if (styleTmp.labelXOffset || styleTmp.labelYOffset) {
var xOffset = isNaN(styleTmp.labelXOffset) ? 0 : styleTmp.labelXOffset;
var yOffset = isNaN(styleTmp.labelYOffset) ? 0 : styleTmp.labelYOffset;
var point = loc.add(new mapboxgl.Point(xOffset, -yOffset));
return new mapboxgl.Point(point.x, point.y);
} else {
return new mapboxgl.Point(loc.x, loc.y);
}
}
rotationBounds(bounds, rotationCenterPoi, angle) {
var ltPoi = new mapboxgl.Point(bounds.left, bounds.top);
var rtPoi = new mapboxgl.Point(bounds.right, bounds.top);
var rbPoi = new mapboxgl.Point(bounds.right, bounds.bottom);
var lbPoi = new mapboxgl.Point(bounds.left, bounds.bottom);
var ver = [];
ver.push(this.getRotatedLocation(ltPoi.x, ltPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rtPoi.x, rtPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(rbPoi.x, rbPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
ver.push(this.getRotatedLocation(lbPoi.x, lbPoi.y, rotationCenterPoi.x, rotationCenterPoi.y, angle));
//bounds旋转后形成的多边形节点数组
var quad = [];
for (var i = 0; i < ver.length; i++) {
quad.push({
"x": ver[i].x,
"y": ver[i].y
});
}