<!DOCTYPE html> <html> <head> <meta charset='UTF-8'/> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/> <link href='http://bigemap.com:9000/bigemap-gl.js/v1.1.0/Widgets/widgets.css' rel='stylesheet'/> <script src='http://bigemap.com:9000/bigemap-gl.js/v1.1.0/bigemap-gl.js'></script> <style> body { margin: 0; padding: 0; } #container { position: absolute; top: 0; bottom: 0; width: 100%; } .bmgl-widget-credits { display: none } </style> <title>Google Map Streets</title> </head> <body> <div id='container'></div> <script> bmgl.Config.HTTP_URL = 'http://bigemap.com:9000'; var viewer = new bmgl.Viewer('container', { mapId: 'bigemap.zhongkexingtu', requestRenderMode: false }); let rectangleInstanceArr = []; //创建线段 for (let i = 0; i < 30000; i++) { var PolyLineInstance = new bmgl.GeometryInstance({ geometry: new bmgl.PolylineGeometry({ positions: bmgl.Cartesian3.fromDegreesArray([ 119.7 + i / 1000, 30.2 + i / 1000, 119.8 + i / 1000, 30.2 + i / 1000, 117.8 + i / 1000, 30.2 + i / 1000, 117.2 + i / 1000, 30.2 + i / 1000, ]), width: 10.0, vertexFormat: bmgl.PolylineColorAppearance.VERTEX_FORMAT, }), attributes: { color: bmgl.ColorGeometryInstanceAttribute.fromColor( i % 2 == 0 ? bmgl.Color.GREEN : bmgl.Color.RED ), }, id: "a" + i }); rectangleInstanceArr.push(PolyLineInstance); } var lineinst = new bmgl.Primitive({ geometryInstances: rectangleInstanceArr, //折线外观 appearance: new bmgl.PolylineColorAppearance({ translucent: false }), asynchronous: false, // 确定在准备就绪之前是异步创建基元还是阻止创建基元。 }) viewer.scene.primitives.add( lineinst ) var arr = [ { id: 'aaa', xx: lineinst }, { id: 'bb', xx: lineinst }, ] // ------------------------------------------------------ //创建多边形 var polygon = new bmgl.GeometryInstance({ geometry: new bmgl.PolygonGeometry({ polygonHierarchy: new bmgl.PolygonHierarchy( bmgl.Cartesian3.fromDegreesArray([ 108, 45, 109, 48, 104, 48, 103, 45 ]) ) }), attributes: { color: bmgl.ColorGeometryInstanceAttribute.fromColor( bmgl.Color.RED ), }, id: "gon" }) // rectangleInstanceArr.push(polygon)] var goninst = new bmgl.Primitive({ geometryInstances: [polygon], //多边形外观 appearance: new bmgl.PerInstanceColorAppearance({ translucent: false, flat: true, closed: false, }), asynchronous: false, // 确定在准备就绪之前是异步创建基元还是阻止创建基元。 }) //获取单个图形 并改变颜色 // var goninst_attr = goninst.getGeometryInstanceAttributes(entity.id) // // goninst_attr.color = bmgl.ColorGeometryInstanceAttribute.toValue(bmgl.Color.RED); let gonpp = viewer.scene.primitives.add( goninst ) gonpp.readyPromise.then(function (model) { viewer.zoomTo(model) }) var lastA = '' var lastA_Color = "" //定义事件 var handler = new bmgl.ScreenSpaceEventHandler(viewer.canvas); handler.setInputAction(function (e) { var entity = viewer.scene.pick(e.endPosition); if (entity) { if (lastA) { lastA.color = lastA_Color lastA = "" lastA_Color = "" } console.log(entity.primitive) var attr = entity.primitive.getGeometryInstanceAttributes(entity.id) lastA = attr lastA_Color = attr.color attr.color = bmgl.ColorGeometryInstanceAttribute.toValue(bmgl.Color.PINK); } else { if (lastA) { lastA.color = lastA_Color lastA = "" lastA_Color = "" } } }, bmgl.ScreenSpaceEventType.MOUSE_MOVE); </script> </body> </html>
源码