最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add a icon to cesium map instead of point - Stack Overflow

programmeradmin5浏览0评论

I want to add icon to a cesium map intead drawing a point. Currently I doing the below code, but want to replace the point below with an actual icon. I have been looking through the cesium documentation and cannot find anything that will do this. Thanks for any suggestions

var points = scene.primitives.add(new Cesium.PointPrimitiveCollection());

points.add({
    position : new Cesium.Cartesian3.fromDegrees(longitude, latitude),
    color : colorDot,
    outlineColor : Cesium.Color.WHITE,
    outlineWidth : width
});

I want to add icon to a cesium map intead drawing a point. Currently I doing the below code, but want to replace the point below with an actual icon. I have been looking through the cesium documentation and cannot find anything that will do this. Thanks for any suggestions

var points = scene.primitives.add(new Cesium.PointPrimitiveCollection());

points.add({
    position : new Cesium.Cartesian3.fromDegrees(longitude, latitude),
    color : colorDot,
    outlineColor : Cesium.Color.WHITE,
    outlineWidth : width
});
Share Improve this question edited Oct 13, 2016 at 22:37 paraquat 6396 silver badges10 bronze badges asked Oct 13, 2016 at 20:52 user3470688user3470688 5597 silver badges23 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

In Cesium, this is called a billboard. They are created in basically the same way as a point, except the image is generally loaded from a URL.

https://cesiumjs/Cesium/Build/Documentation/BillboardCollection.html

// Create a billboard collection with two billboards
var billboards = scene.primitives.add(new Cesium.BillboardCollection());
billboards.add({
  position : new Cesium.Cartesian3(1.0, 2.0, 3.0),
  image : 'url/to/image'
});
billboards.add({
  position : new Cesium.Cartesian3(4.0, 5.0, 6.0),
  image : 'url/to/another/image'
});

Adding to @paraquat's correct answer about Billboards: Cesium includes a "Pin Builder" that can be used to make typical map icons as billboards. Here's a demo.

var viewer = new Cesium.Viewer('cesiumContainer');

var pinBuilder = new Cesium.PinBuilder();

var url = Cesium.buildModuleUrl('Assets/Textures/maki/grocery.png');
var groceryPin = Cesium.when(pinBuilder.fromUrl(url, Cesium.Color.GREEN, 48), function(canvas) {
    return viewer.entities.add({
        name : 'Grocery store',
        position : Cesium.Cartesian3.fromDegrees(-75.1705217, 39.921786),
        billboard : {
            image : canvas.toDataURL(),
            verticalOrigin : Cesium.VerticalOrigin.BOTTOM
        }
    });
});
发布评论

评论列表(0)

  1. 暂无评论