使用javascript的多个标记图标的下拉选项
使用选项值更改自定义图标贴图会让我感到困惑。所以请帮我提一下你的意见D 这是选项值使用javascript的多个标记图标的下拉选项,javascript,php,google-maps,drop-down-menu,options,Javascript,Php,Google Maps,Drop Down Menu,Options,使用选项值更改自定义图标贴图会让我感到困惑。所以请帮我提一下你的意见D 这是选项值 <select name='type' id='type' onChange='document.getElementById("customicon").value="this.value"'> <option<?php if($place['type'] == "sekolahremaja") {?> selected="selected"<?php } ?
<select name='type' id='type' onChange='document.getElementById("customicon").value="this.value"'>
<option<?php if($place['type'] == "sekolahremaja") {?> selected="selected"<?php } ?>>Sekolah Remaja</option>
<option<?php if($place['type'] == "jalanremaja") {?> selected="selected"<?php } ?>>Jalan Remaja</option>
<option<?php if($place['type'] == "komunitas") {?> selected="selected"<?php } ?>>Komunitas</option>
<option<?php if($place['type'] == "screening") {?> selected="selected"<?php } ?>>Screening</option>
<option<?php if($place['type'] == "lembaga") {?> selected="selected"<?php } ?>>Lembaga</option>
<option<?php if($place['type'] == "personal") {?> selected="selected"<?php } ?>>Personal</option>
<option<?php if($place['type'] == "foto") {?> selected="selected"<?php } ?>>Foto</option>
</select>
>Sekolah Remaja
>杰兰·雷马哈
>科蒙塔斯
>筛选
>伦巴加
>私人的
>福托
这是我的javascript代码
var customicon = {
"sekolahremaja" : "sekolahremaja",
"jalanremaja" : "jalanremaja",
"komunitas" : "komunitas",
"screening" : "screening",
"lembaga" : "lembaga",
"personal" : "personal",
"events" : "events",
};
var markerImage = "../images/icons/"+customicon+".png";
<?php if ($_GET['place_id']){?>
var marker = new google.maps.Marker({
position: new google.maps.LatLng(<?=$place['lat']?>,<?=$place['lng']?>),
map: map,
animation: google.maps.Animation.DROP,
draggable: true,
icon: markerImage
});
var customicon={
“sekolahremaja”:“sekolahremaja”,
“jalanremaja”:“jalanremaja”,
“科穆塔斯”:“科穆塔斯”,
“筛选”:“筛选”,
“lembaga”:“lembaga”,
“个人”:“个人”,
“事件”:“事件”,
};
var markerImage=“../images/icons/”+customicon+“.png”;
var marker=new google.maps.marker({
位置:新google.maps.LatLng(,),
地图:地图,
动画:google.maps.animation.DROP,
真的,
图标:markerImage
});
我不确定这是否是您想要的
<select name='type' id='type' onchange='changeMarker(this.value)'>
<option value="sekolahremaja">Sekolah Remaja</option>
...
<option value="foto">Foto</option>
</select>
Sekolah Remaja
...
福托
javascript的东西
function changeMarker(v){
var customicon = {
"sekolahremaja" : "sekolahremaja",
"jalanremaja" : "jalanremaja",
"komunitas" : "komunitas",
"screening" : "screening",
"lembaga" : "lembaga",
"personal" : "personal",
"events" : "events",
};
var markerImage = "../images/icons/"+customicon[v]+".png";
var marker = new google.maps.Marker({
position: new google.maps.LatLng(<?=$place['lat']?>,<?=$place['lng']?>),
map: map,
animation: google.maps.Animation.DROP,
draggable: true,
icon: markerImage
});
}
功能更改标记(v){
var customicon={
“sekolahremaja”:“sekolahremaja”,
“jalanremaja”:“jalanremaja”,
“科穆塔斯”:“科穆塔斯”,
“筛选”:“筛选”,
“lembaga”:“lembaga”,
“个人”:“个人”,
“事件”:“事件”,
};
var markerImage=“../images/icons/”+自定义图标[v]+“.png”;
var marker=new google.maps.marker({
位置:新google.maps.LatLng(,),
地图:地图,
动画:google.maps.animation.DROP,
真的,
图标:markerImage
});
}
试试这个
<select name='type' id='type' onChange="changeImage(this.value)">
<option value="sekolahremaja" <?php if($place['type'] == "sekolahremaja") {?> selected="selected"<?php } ?>>Sekolah Remaja</option>
<option value="jalanremaja" <?php if($place['type'] == "jalanremaja") {?> selected="selected"<?php } ?>>Jalan Remaja</option>
<option value="komunitas" <?php if($place['type'] == "komunitas") {?> selected="selected"<?php } ?>>Komunitas</option>
<option value="screening" <?php if($place['type'] == "screening") {?> selected="selected"<?php } ?>>Screening</option>
<option value="lembaga" <?php if($place['type'] == "lembaga") {?> selected="selected"<?php } ?>>Lembaga</option>
<option value="personal" <?php if($place['type'] == "personal") {?> selected="selected"<?php } ?>>Personal</option>
<option value="foto" <?php if($place['type'] == "foto") {?> selected="selected"<?php } ?>>Foto</option>
</select>
因为customicon是对象
现在,markerImage
有了你想要显示为标记图标的图像的url
同时检查位置:new google.maps.LatLng(,)
在这里,您需要将lat
和lng
转换为如下数字
position: new google.maps.LatLng(Number(<?=$place['lat']?>),Number(<?=$place['lng']?>))
position:new google.maps.LatLng(Number(),Number())
也许你需要像var-markerImage=“../images/icons/”+自定义图标[keyOfSelectedOption]+“.png”这样的东西代码>因为customicon是JSON数据。不管怎样,什么是#customicon?#customicon是我的选项值变量,我不知道它是否错了。我不知道如何使用javascript-\我不知道为什么,但它仍然不起作用(我想我对另一个脚本有问题,但非常感谢你:)我会把你的代码保留在笔记上。:)
position: new google.maps.LatLng(Number(<?=$place['lat']?>),Number(<?=$place['lng']?>))