简体   繁体   English

如何通过购买次数设置标记的尺寸?

[英]How do I set a marker's size by a number of purchases?

In an e-commerce system I'm building, I want to use google maps api to show the origins of the purchases.在我正在构建的电子商务系统中,我想使用 google maps api 来显示购买的来源。 I want the markers to be shaped as a circle, and I want that circle's size to be determined by the number of purchases made from that particular city.我希望标记的形状为一个圆圈,并且我希望该圆圈的大小由从该特定城市购买的数量决定。 Let's say there were 100 orders from NYC and 200 from Boston, The Boston's circle will be twice the size.假设有来自纽约市的 100 个订单和来自波士顿的 200 个订单,波士顿的圈子将是其两倍。

How can I do that?我怎样才能做到这一点?

Your marker icon can be a symbol (SVG path) so you can scale it to your convenience.您的标记图标可以是一个符号(SVG 路径),因此您可以根据需要对其进行缩放。

The following example upscales the symbol each time you add one to the map.每次向地图添加一个符号时,以下示例都会放大该符号。 You can easily reuse that to your use case.您可以轻松地将其重用于您的用例。

var map;
var polyLine;
var polyOptions;
var iconSize = 0.5;

function initialize() {

    var mapOptions = {
        zoom: 5,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: new google.maps.LatLng(0,0)
    };

    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

    google.maps.event.addListener(map, 'click', function(event) {

        addPoint(event);
    });
}

function addPoint(event) {

    var icon = {

        path: "M-20,0a20,20 0 1,0 40,0a20,20 0 1,0 -40,0",
        fillColor: '#FF0000',
        fillOpacity: .6,
        anchor: new google.maps.Point(0,0),
        strokeWeight: 0,
        scale: iconSize
    }

    var marker = new google.maps.Marker({
        position: event.latLng,
        map: map,
        draggable: false,
        icon: icon,
        zIndex : -20
    });

    map.panTo(event.latLng);

    iconSize += .1;
}

initialize();

JSFiddle demo JSFiddle 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM