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

Function draw$3

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

Source from the content-addressed store, hash-verified

1547var fs_s$1 = ['precision mediump float;', 'uniform vec4 u_FragColor;', 'void main() {', 'gl_FragColor = u_FragColor;', '}'].join('');
1548
1549function draw$3(gl, data, options) {
1550
1551 if (!data) {
1552 return;
1553 }
1554
1555 var program = initShaders(gl, vs_s$1, fs_s$1);
1556
1557 var a_Position = gl.getAttribLocation(program, 'a_Position');
1558
1559 var a_PointSize = gl.getAttribLocation(program, 'a_PointSize');
1560
1561 var uFragColor = gl.getUniformLocation(program, 'u_FragColor');
1562
1563 //gl.clearColor(0.0, 0.0, 1.0, 1.0);
1564 gl.clear(gl.COLOR_BUFFER_BIT);
1565
1566 var halfCanvasWidth = gl.canvas.width / 2;
1567 var halfCanvasHeight = gl.canvas.height / 2;
1568
1569 var verticesData = [];
1570 var count = 0;
1571 for (var i = 0; i < data.length; i++) {
1572 var item = data[i].geometry._coordinates;
1573
1574 var x = (item[0] - halfCanvasWidth) / halfCanvasWidth;
1575 var y = (halfCanvasHeight - item[1]) / halfCanvasHeight;
1576
1577 if (x < -1 || x > 1 || y < -1 || y > 1) {
1578 continue;
1579 }
1580 verticesData.push(x, y);
1581 count++;
1582 }
1583
1584 var vertices = new Float32Array(verticesData);
1585 var n = count; // The number of vertices
1586
1587 // Create a buffer object
1588 var vertexBuffer = gl.createBuffer();
1589
1590 // Bind the buffer object to target
1591 gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
1592 // Write date into the buffer object
1593 gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
1594
1595 // Assign the buffer object to a_Position variable
1596 gl.vertexAttribPointer(a_Position, 2, gl.FLOAT, false, 0, 0);
1597
1598 // Enable the assignment to a_Position variable
1599 gl.enableVertexAttribArray(a_Position);
1600
1601 gl.vertexAttrib1f(a_PointSize, options._size);
1602
1603 var colored = getColorData(options.fillStyle || 'red');
1604
1605 gl.uniform4f(uFragColor, colored[0] / 255, colored[1] / 255, colored[2] / 255, colored[3] / 255);
1606 gl.drawArrays(gl.POINTS, 0, n);

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