简体   繁体   English

jvectormap添加具有不同半径的标记

[英]jvectormap add marker with different radius

I'm trying to create a jvectormap and populate it with markers received via ajax. 我正在尝试创建一个jvectormap并使用通过ajax接收到的标记填充它。 I'm now able to put the markers in the map but I'd love to change the radius of them based on another value received via ajax. 现在,我可以将标记放置在地图上,但是我很想根据通过ajax接收到的另一个值来更改标记的半径。

$.ajax({
            url: "/map",
            type: 'post',
            dataType: 'json',
            data: {
                _csrf : 'token'
            },
            success: function (data) {
                var mapObj = new jvm.Map({
                    container: $('#todaymap'),
                    map: 'it_merc_en',
                    normalizeFunction: 'polynomial',        
                    markerStyle: {
                        initial: {
                            fill: '#F8E23B',
                            stroke: '#383f47',
                            r: 3,
                        },
                        hover: {
                            fill: '#383f47',
                            stroke: '#383f47'
                        }
                    },
                    backgroundColor: '#383f47',
                    markers: [],
                    series: {
                        markers: [{
                            attribute: 'r',
                            scale: [3,10]
                        }],
                    }
                });
                $('#todaymap div:first-child').hide();

                var mapMarkers = [];
                var mapMarkersValues = [];
                mapMarkers.length = 0;
                mapMarkersValues.length = 0;
                for (var i = 0, l= data.length; i < l; i++) {
                    coords= Array();
                    coords[0]= data[i].lat;
                    coords[1]= data[i].lng;

                    console.log(data[i].count);
                    mapMarkers.push({name: data[i].name, latLng: coords});
                }
                mapObj.addMarkers(mapMarkers, []);  
            }
        }); 

the field I want to use is data[i].count which has a value from 0 to 6 based on a count of the occurrences. 我要使用的字段是data[i].count ,根据出现次数计数,其值为0到6。 I didn't find anything useful on the net. 我在网上找不到任何有用的东西。 Anyone has an idea on how to do it? 有人对如何做有想法吗?

A similar approach I've just tested on my own implementation of the map works, however my version is set to alter the markers that have already been set upon creation of the map using, it uses: 我刚刚在自己的地图实现中测试了一种类似的方法,但是我的版本设置为更改使用创建地图时已经设置的标记,它使用:

mapObj.markers[markerNumber].element.config.style.initial.r = scaleValue;
mapObj.applyTransform();

So for this to work you would have to add this after the mapObj.addMarkers line using another loop over the data, and then use applyTransform() to redraw/refresh the map with the changed marker information after this secondary loop, something like this should work I would imagine: 因此,要执行此操作,您将不得不在mapObj.addMarkers行之后使用数据的另一个循环将其添加,然后在此辅助循环之后使用applyTransform()来使用更改后的标记信息重绘/刷新地图,这应该是这样的我想像的工作:

for (var i = 0, l= data.length; i < l; i++) {
    mapObj.markers[i].element.config.style.initial.r = data[i].count;
}
mapObj.applyTransform();

Edit: After looking at your code again and trying something out on mine with the initial marker creation, I think you could do it actually just adding the information to the mapMarkers array like so: 编辑:再次查看代码并尝试创建初始标记后,我想您实际上可以将信息添加到mapMarkers数组中,如下所示:

mapMarkers.push({name: data[i].name, latLng: coords, r:data[i].count});

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

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