MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / draw$2

Function draw$2

libs/mapv/mapv.js:1484–1539  ·  view source on GitHub ↗
(gl, data, options)

Source from the content-addressed store, hash-verified

1482var fs_s = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
1483
1484function draw$2(gl, data, options) {
1485
1486 if (!data) {
1487 return;
1488 }
1489
1490 var program = initShaders(gl, vs_s, fs_s);
1491
1492 gl.enable(gl.BLEND);
1493 gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
1494
1495 //gl.clearColor(0.0, 0.0, 1.0, 1.0);
1496 gl.clear(gl.COLOR_BUFFER_BIT);
1497
1498 var halfCanvasWidth = gl.canvas.width / 2;
1499 var halfCanvasHeight = gl.canvas.height / 2;
1500
1501 // Create a buffer object
1502 var vertexBuffer = gl.createBuffer();
1503 // Bind the buffer object to target
1504 gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
1505
1506 var a_Position = gl.getAttribLocation(program, 'a_Position');
1507 // Assign the buffer object to a_Position variable
1508 gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
1509
1510 // Enable the assignment to a_Position variable
1511 gl.enableVertexAttribArray(a_Position);
1512
1513 var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
1514
1515 var colored = getColorData(options.strokeStyle || 'red');
1516
1517 gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
1518
1519 gl.lineWidth(options.lineWidth || 1);
1520
1521 for (var i = 0, len = data.length; i < len; i++) {
1522 var _geometry = data[i].geometry._coordinates;
1523
1524 var verticesData = [];
1525
1526 for (var j = 0; j < _geometry.length; j++) {
1527 var item = _geometry[j];
1528
1529 var x = (item[0] - halfCanvasWidth) / halfCanvasWidth;
1530 var y = (halfCanvasHeight - item[1]) / halfCanvasHeight;
1531 verticesData.push(x, y);
1532 }
1533
1534 var vertices = new Float32Array(verticesData);
1535 // Write date into the buffer object
1536 gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
1537 gl.drawArrays(gl.LINE_STRIP, 0, _geometry.length);
1538 }
1539}
1540
1541var line = {

Callers

nothing calls this directly

Calls 4

getColorDataFunction · 0.85
pushMethod · 0.80
initShadersFunction · 0.70
clearMethod · 0.45

Tested by

no test coverage detected