0

我需要在 Yandex 地图中设置地标的不透明度。但我找不到将它作为道具或任何其他方式提供的方法。在文档化方面没有任何关于它的内容。你有什么建议吗?我不想将新的透明标记添加到我的资产文件夹中。

这是我创建地标的方法

 const courierReachMarker = new ymaps.Placemark([$scope.map.courierReachMarker.coords.latitude, $scope.map.courierReachMarker.coords.longitude], null, {
          iconLayout: 'default#image',
          iconImageHref: `/${$scope.map.courierReachMarker.options.icon.url}`,
          iconImageSize: [30, 30],
          iconImageOffset: [-15, -30],
          draggable: false,
          courierMarker: true,
        });
        $scope.yMap.courierReachMarker = courierReachMarker;
        $scope.yMap.geoObjects
          .add($scope.yMap.courierReachMarker);

请帮忙 :)

4

1 回答 1

0

您可以创建一个模板:

var squareLayout = ymaps.templateLayoutFactory.createClass('<div class="placemark_layout_container"><img src="https://sandbox.api.maps.yandex.net/examples/ru/2.1/icon_customImage/images/myIcon.gif" width=50 height=50/></div>');

添加css规则:

.placemark_layout_container img{ 
    opacity: 0.3
    }

并使用它:

var squarePlacemark = new ymaps.Placemark(
    [55.725118, 37.682145], {}, {
        iconLayout: squareLayout,
        iconShape: {
            type: 'Rectangle',
            coordinates: [
                [-25, -25], [25, 25]
            ]
        }
    }
);

https://jsfiddle.net/sjq68obx/1/

于 2019-04-09T09:30:27.357 回答