zoukankan      html  css  js  c++  java
  • maptalks 开发GIS地图(40)maptalks.three.33- custom-mergedmixin-geometry

    1. 多重复用对象, multiplexing geometry。 又学了一个单词。

    2. 定义 Bar 对象。

     1         function getBar(options) {
     2             const { radius, height } = barCache.getOptions();
     3             const geometry = barCache.getObject3d().geometry;
     4             const scaleR = options.radius / radius, scaleH = options.height / height;
     5             const bar = new maptalks.BaseObject();
     6             bar._initOptions(Object.assign({}, barCache.getOptions(), options));
     7             bar._createMesh(geometry, material);
     8             bar.getObject3d().scale.set(scaleR, scaleR, scaleH);
     9             const { altitude, coordinate } = options;
    10             const layer = barCache.getLayer();
    11             const z = layer.distanceToVector3(altitude, altitude).x;
    12             const position = layer.coordinateToVector3(coordinate, z);
    13             bar.getObject3d().position.copy(position);
    14             return bar;
    15 
    16         }

    3. 处理数据

     1    const data = json.features.slice(0, 10000).map(function (dataItem) {
     2                     dataItem = gcoord.transform(dataItem, gcoord.AMap, gcoord.WGS84);
     3                     return {
     4                         coordinate: dataItem.geometry.coordinates,
     5                         height: Math.random() * 200,
     6                         value: Math.random() * 10000,
     7                         radius: 5 + 5 * Math.random(),
     8                         topColor: '#fff',
     9                         interactive: false
    10                     }
    11                 });
    12 
    13                 barCache = threeLayer.toBox(data[0].coordinate, data[0], material);
    14                 bars.push(barCache);
    15                 data.forEach(d => {
    16                     const bar = getBar(d);
    17                     //event test
    18                     ['click', 'mousemove', 'mouseout', 'mouseover', 'mousedown', 'mouseup', 'dblclick', 'contextmenu'].forEach(function (eventType) {
    19                         bar.on(eventType, function (e) {
    20                             console.log(e.type, e);
    21                             // console.log(this);
    22                             if (e.type === 'mouseout') {
    23                                 this.setSymbol(material);
    24                             }
    25                             if (e.type === 'mouseover') {
    26                                 this.setSymbol(highlightmaterial);
    27                             }
    28                         });
    29                     });
    30                     // tooltip test
    31                     // box.setToolTip(d.value, {
    32                     //     showTimeout: 0,
    33                     //     eventsPropagation: true,
    34                     //     dx: 10
    35                     // });
    36                     // //infowindow test
    37                     // box.setInfoWindow({
    38                     //     content: d.value,
    39                     //     title: 'message',
    40                     //     animationDuration: 0,
    41                     //     autoOpenOn: false
    42                     // });
    43                     bars.push(bar);
    44                 });
    45 
    46                 threeLayer.addMesh(bars);

    4. 页面显示

    5. 源码地址

    https://github.com/WhatGIS/maptalkMap/tree/main/threelayer/demo

     
  • 相关阅读:
    目前比较全的CSS重设(reset)方法总结
    UrlRewritingNet.UrlRewrite 中文文档
    CSS Hack汇总快查
    CSS8款CSS制作数据报表技巧
    CSS属性与JavaScript 编码方法对照表
    需要掌握的八个CSS布局技巧
    了解网页设计标准尺寸
    JavaScript是否为创造游戏准备好了
    JavaScript(2)
    CSS兼容
  • 原文地址:https://www.cnblogs.com/googlegis/p/14738153.html
Copyright © 2011-2022 走看看