android canvas广告牌,cesium 实现广告牌移入显示tooltip

bVbG7KJ

1、tooltip css

// tooltip 样式

.tooltipdiv-inner {

padding: 3px 8px;

}

/* 向左 */

.toolTip-left {

position: absolute;

width: 300px;

min-height: 80px;

border: 4px solid rgba(19, 159, 255, 1);

border-radius: 20px;

background-color: rgba(30, 49, 74, 0.6);

}

.toolTip-left:before {

content: "";

display: block;

position: absolute;

left: -20px;

top: 50%;

transform: translateY(-50%);

border-top: 20px solid transparent;

border-bottom: 20px solid transparent;

border-right: 20px solid rgba(19, 159, 255, 1);

}

// 内容样式

.con {

font-size: 28px;

color: #ffff;

line-height: 80px;

}

// tooltip 样式

.tooltipdiv-inner {

padding: 3px 8px;

}

/* 向左 */

.toolTip-left {

position: absolute;

width: 300px;

min-height: 80px;

border: 4px solid rgba(19, 159, 255, 1);

border-radius: 20px;

background-color: rgba(30, 49, 74, 0.6);

}

.toolTip-left:before {

content: "";

display: block;

position: absolute;

left: -20px;

top: 50%;

transform: translateY(-50%);

border-top: 20px solid transparent;

border-bottom: 20px solid transparent;

border-right: 20px solid rgba(19, 159, 255, 1);

}

// 内容样式

.con {

font-size: 28px;

color: #ffff;

line-height: 80px;

}

// 2、通过函数去动态创建tooltip的dom结构

tooltip.js

var TooltipDiv = (function () {

var isInit = false;

function _ () { };

_.initTool = function (frameDiv) {

if (isInit) { return; }

var div = document.createElement('DIV');

div.className = "toolTip-left";//

// var arrow = document.createElement('DIV');

// arrow.className = "tooltipdiv-arrow";

// div.appendChild(arrow);

var title = document.createElement('DIV');

title.className = "tooltipdiv-inner";

div.appendChild(title);

this._div = div;

this._title = title;

frameDiv.appendChild(div);

isInit = true;

}

_.setVisible = function (visible) {

if (!isInit) { return; }

this._div.style.display = visible ? 'block' : 'none';

};

/*

position屏幕坐标

显示在屏幕上

*/

_.showAt = function (position, message) {

if (!isInit) { return; }

if (position && message) {

this.setVisible(true);

this._title.innerHTML = message;

this._div.style.position = "absolute"

this._div.style.left = position.x + 60 + "px";

this._div.style.top = (position.y - this._div.clientHeight/2) + "px";

}

};

return _;

})();

export default TooltipDiv

// 在页面引入cesium界面tooltip.js

import TooltipDiv from "../../assets/tooltip.js"

var viewer = new Cesium.Viewer('cesiumContainer', {

imageryProvider: new Cesium.UrlTemplateImageryProvider({

url: 'http://www.google.cn/maps/vt?lyrs=y&x={x}&gl=cn&y={y}&z={z}',

tilingScheme: new Cesium.WebMercatorTilingScheme()

}),

creditContainer: "cesiumContainer",

selectionIndicator: false,

animation: false,

baseLayerPicker: false,

geocoder: false,

timeline: false,

sceneModePicker: true,

navigationHelpButton: false,

infoBox: false,

fullscreenButton: true

});

//绘制广告牌

let img = require("../assets/images/life.png")

viewer.scene.globe.depthTestAgainstTerrain = true;

var billboard = viewer.entities.add({

id: '111111',

name: "程海指挥中心",

info: {

name: 'aaaa',

val: 100

},

position: Cesium.Cartesian3.fromDegrees(110.20, 34.55, 3000),

billboard: {

heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,

image: img,

verticalOrigin: 0,

width: 32,

height: 145,

pixelOffset: new Cesium.Cartesian2(0, -72),

}

});

viewer.zoomTo(billboard);

var scene = viewer.scene;

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);

TooltipDiv.initTool(viewer.cesiumWidget.container);

// 鼠标移入自定义弹出框

handler.setInputAction(function (movement) {

if (scene.mode !== Cesium.SceneMode.MORPHING) {

var pickedObject = scene.pick(movement.endPosition);

console.log(pickedObject, 'gggggg')

if (scene.pickPositionSupported && Cesium.defined(pickedObject) && pickedObject.id._id === '111111') {

TooltipDiv.showAt(movement.endPosition, `

名字:${pickedObject.id._name}
`);

} else {

TooltipDiv.setVisible(false);

}

}

}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Cesium中创建自定义广告牌,您可以按照以下步骤进行操作: 1. 首先,您需要在Cesium中加载必要的库和资源。您可以从Cesium官方网站下载Cesium库,并将其包含在您的项目中。 2. 创建一个Canvas元素,用于绘制广告牌的内容。您可以使用HTML5 Canvas API绘制图形、文本等。 3. 使用Cesium的Entity API创建一个实体对象,将广告牌与地球上的位置相关联。您可以指定广告牌的位置、旋转角度、大小等属性。 4. 使用Cesium的BillboardVisualizer类创建一个广告牌可视化对象,并将其与实体对象关联起来。这将处理广告牌的渲染和更新。 5. 在渲染循环中,更新广告牌的内容和属性。您可以根据需要更改广告牌的位置、颜色、文本等。 下面是一个简单的示例代码,展示了如何在Cesium中创建自定义广告牌: ```javascript // 创建Canvas元素 var canvas = document.createElement('canvas'); canvas.width = 128; canvas.height = 64; var context2D = canvas.getContext('2d'); // 在Canvas上绘制内容 context2D.fillStyle = 'red'; context2D.fillRect(0, 0, canvas.width, canvas.height); context2D.font = 'bold 24px Arial'; context2D.fillStyle = 'white'; context2D.fillText('Custom Billboard', 10, 40); // 创建实体对象 var entity = new Cesium.Entity({ position: Cesium.Cartesian3.fromDegrees(0, 0, 0), }); // 创建广告牌可视化对象 var billboardVisualizer = new Cesium.BillboardVisualizer(scene, entityCollection); billboardVisualizer.update(entity); // 初始化广告牌 // 在渲染循环中更新广告牌 scene.postRender.addEventListener(function() { context2D.fillText('Time: ' + Date.now(), 10, 60); // 更新时间 billboardVisualizer.update(entity); // 更新广告牌 }); ``` 这只是一个简单示例,您可以根据需要进行自定义和扩展。您可以在Canvas上绘制任何内容,并使用Cesium的其他功能来控制广告牌的属性和行为。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值