简体   繁体   English

Google Maps API圆形标记,大小可变

[英]Google Maps API circle markers, variable size

 var xml = data.responseXML; var circles = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var name = markers[i].getAttribute("location"); var scans = markers[i].getAttribute("scans"); var point = new google.maps.LatLng( parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("long"))); var html = name; var marker = new google.maps.Marker({ center: center, strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35, map: map, radius:1000 }); bindInfoWindow(marker, map, infoWindow, html); } 

Trying to add some data to circle markers. 尝试向圆标记添加一些数据。

The circles are already markers for specific locations, but I want to make them vary in size depending on a count that corresponds to that location. 圆圈已经是特定位置的标记,但是我想让它们的大小根据与该位置相对应的计数而变化。 I cannot seem to find any code to make markers of variable size, since each marker is most likely going to have a unique number of contacts. 我似乎找不到任何代码来制作大小可变的标记,因为每个标记很可能具有唯一数量的联系人。 Any ideas? 有任何想法吗?

Here's the code I have now for markers. 这是我现在用于标记的代码。 I know its not right, since it's not producing what I want. 我知道这是不对的,因为它没有产生我想要的东西。

https://developers.google.com/maps/documentation/javascript/examples/circle-simple <---This is the effect that I am looking for, but I don't understand how to get the values for size to change based on the data entered in the table. https://developers.google.com/maps/documentation/javascript/examples/circle-simple <---这是我想要的效果,但我不知道如何获取要更改的size值根据表格中输入的数据。

You can set the marker radius to an integer returned by a function. 您可以将标记半径设置为函数返回的整数。 Or it can be an expression. 也可以是一个表达式。

Here is a JsFiddle with a working example where the count attribute in the XML is set by an expression. 这是一个带有示例的JsFiddle,其中XML中的count属性由表达式设置。

function initMap() {
    var myLatLng = new google.maps.LatLng(47.6685771, -122.2553681),
        myOptions = {
            zoom: 12,
            center: myLatLng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        },
        map = new google.maps.Map(document.getElementById('map'), myOptions);

    var markers = xml.documentElement.getElementsByTagName("marker");

    for (var i = 0; i < markers.length; ++i) {
        var marker = markers[i];
        var name = marker.getAttribute("location");
        var point = new google.maps.LatLng(
        parseFloat(marker.getAttribute("lat")),
        parseFloat(marker.getAttribute("long")));
        var cityCircle = new google.maps.Circle({
            strokeColor: '#FF0000',
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: '#FF0000',
            fillOpacity: 0.35,
            map: map,
            center: point,
            radius: marker.getAttribute("count") * 75
        });
    }
}

https://jsfiddle.net/plbogen/ecj8o4uL https://jsfiddle.net/plbogen/ecj8o4uL

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

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