Javascript 在JQM中设置多个贴图点图标
我试图在画布上填充一些从JSON文件读取的映射点 我可以很好地创建一组点,但我想根据点的类型添加不同的图标。我已经尝试过评估JSON数据,地图不会加载更多的图标 我的代码如下:Javascript 在JQM中设置多个贴图点图标,javascript,jquery,google-maps-api-3,jquery-mobile,Javascript,Jquery,Google Maps Api 3,Jquery Mobile,我试图在画布上填充一些从JSON文件读取的映射点 我可以很好地创建一组点,但我想根据点的类型添加不同的图标。我已经尝试过评估JSON数据,地图不会加载更多的图标 我的代码如下: $.each( data.markers, function(i, marker) { $('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(marker.l
$.each( data.markers, function(i, marker) {
$('#map_canvas').gmap('addMarker', {
'position': new google.maps.LatLng(marker.latitude, marker.longitude),
if (marker.company == "Capgemini") {
'icon':new google.maps.MarkerImage("capico.png"),
} else if (marker.company == "Accenture") {
'icon':new google.maps.MarkerImage("accico.png"),
}
'bounds': true
}).click(function() {
//$('#map_canvas').gmap('openInfoWindow', {
// 'content': marker.content
$.mobile.changePage("#details");
我不知道我哪里出了问题
非常感谢您的帮助请尝试此代码
var customIcons = {
"Capgemini": {
icon: 'path_to_your_marker_pictures/capico.png',
},
"Accenture": {
icon: 'path_to_your_marker_pictures/accico.png',
}
};
var icon = customIcons[marker.company] || {};
var marker = new google.maps.Marker({
position: point,
icon: icon.icon,
});
最好的,
Darko谢谢你的回答Darko,但我不明白你的代码。根据marker.company的不同,我需要设置图标的类型,因此这需要在if语句中。我在回答中编辑代码(请参见上文)。我根据您的示例改编了我的代码,希望您现在理解。@EHarpham-您实际上不需要
if
语句。DarkoJ的答案也是一样的,在customIcons
对象中查找category
,并在其中选择两个图标之一。你会使用marker.company
而不是category
。我现在也在我的codecategory
中编辑到marker.company
,所以希望现在EHarpham已经明白了一切(请看我的答案上面)。