gpt4 book ai didi

javascript - 谷歌地图 v3 动态设置标记大小

转载 作者:行者123 更新时间:2023-11-30 18:50:16 26 4
gpt4 key购买 nike

这是问题所在,我有一个数据库,其中包含有关标记图像的信息:

我正在通过 ajax 调用检索所有这些并将数据保存为对象,因此我可以检查标记的位置类型并为该类型的位置放置适当的标记。

我正在恢复数据,但是当我尝试将数据添加到构造函数中以获得新的谷歌地图图像时出现错误,我已经通过警报检查了是否存在正确的信息,结果是什么???

// the following code will wor!!!
new google.maps.Size(32,37) // The Size works
//The following line breaks it with dynamic value
new google.maps.Size(myIconArray.icon[myData.name_etp].size)

完整代码如下:(静态代码行中的测试值与存储在我正在创建的对象引用中的值相同) http://www.focus-on-plants.com/locator_iconed.php

function addMarker(map, myData){
console.log(myData)
// Create the marker
// create the marker info first
myLatLng = new google.maps.LatLng(myData.lat_mdt, myData.lng_mdt);
markersArray.push(myLatLng);
markersInfoArray.push(myData);

// ----------------------------
// NOW CREATE THE ACTUAL ICON
//alert( myIconArray.icon[myData.name_etp].size)

/*var iconimage = new google.maps.MarkerImage(
'/images/icons/markers/flower_lb/image_med.png', //myIconArray.icon[myData.name_etp].image,
new google.maps.Size(myIconArray.icon[myData.name_etp].size) // The Size
//new google.maps.Point(myIconArray.icon[myData.name_etp].origin), // The origin
//new google.maps.Point(myIconArray.icon[myData.name_etp].anchorpoint) // The anchor
);*/
//console.log(iconimage)
var iconshape = {
type: 'poly',
coord: [0,2,1,2,1,1,18,0,18,1,19,2,20,19,19,19,18,21,14,21,10,26,5,21,1,21,1,20,0,20,0,2]
}

//alert(myIconArray.shape[myData.name_etp])
mySize = 'new google.maps.Size('+myIconArray.icon[myData.name_etp].size+')'
var iconimage = new google.maps.MarkerImage(
myIconArray.icon[myData.name_etp].image,
// the following code works!!!
new google.maps.Size(32,37) // The Size works
//The following line breaks iot with dynamic value
//new google.maps.Size(myIconArray.icon[myData.name_etp].size)


//new google.maps.Point(0, 0), // The origin
//new google.maps.Point(13,29) // The anchor
);
var iconshadow = new google.maps.MarkerImage(
'/images/icons/markers/flower_lb/shadow_med.png',
new google.maps.Size(42,18), // The Size
new google.maps.Point(0,0), // The origin
new google.maps.Point(13,18) // The anchor
);

var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: myData.name_mdt,
icon: iconimage,
shadow: iconshadow//,
//shape: iconshape
});

// Wrapping the event listener inside an anonymous function
// that we immediately invoke and passes the variable i to.
(function(myData, marker) {
// Creating the event listener. It now has access to the values of
// myData and marker as they were during its creation
google.maps.event.addListener(marker, 'click', function() {
//create thecontent for the infowindow
var content = createContent(myData);
var infowindow = new google.maps.InfoWindow({
content: content
});
infowindow.open(map, marker);
});
})(myData, marker);

};

最佳答案

好吧,我知道这是为什么了,

我正在传递 new google.maps.Size(myIconArray.icon[myData.name_etp].size)

google image maps.size 有两个单独的参数,new google.maps.Size(42,18)

我正在传递 32, 37 这实际上是一个字符串,

我需要使用以下方法拆分字符串:

tmp = myIconArray.icon[myData.name_etp].size.split(",")

然后为我使用的尺寸添加 x 和 y:new google.maps.Size(tmp[0], tmp[1])

关于javascript - 谷歌地图 v3 动态设置标记大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4157414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com