admin管理员组文章数量:1332353
How do i change the icon of a marker on google maps when I mouseover the text in a div? I managed to change the marker icon onmouseover the marker in the map itself using
google.maps.event.addListener(marker1, "mouseover", function(event) {
this.setIcon(";chld=1|ffffff|c41200");
}
EDIT:
Here is what I have now:
function initialize(){
....
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(1.288693,103.846733),
map: map,
icon: ";chld=1|c41200|ffffff"
});
....
}
function changeMarker(marker) {
alert(marker);
}
and
<div id="searchresult" onmouseover="changeMarker(marker1)">
I'm using Chrome. In the console, onmouseover the div I get the error "Uncaught ReferenceError: marker1 is not defined"
How do i change the icon of a marker on google maps when I mouseover the text in a div? I managed to change the marker icon onmouseover the marker in the map itself using
google.maps.event.addListener(marker1, "mouseover", function(event) {
this.setIcon("http://chart.apis.google./chart?chst=d_map_pin_letter&chld=1|ffffff|c41200");
}
EDIT:
Here is what I have now:
function initialize(){
....
var marker1 = new google.maps.Marker({
position: new google.maps.LatLng(1.288693,103.846733),
map: map,
icon: "http://chart.apis.google./chart?chst=d_map_pin_letter&chld=1|c41200|ffffff"
});
....
}
function changeMarker(marker) {
alert(marker);
}
and
<div id="searchresult" onmouseover="changeMarker(marker1)">
I'm using Chrome. In the console, onmouseover the div I get the error "Uncaught ReferenceError: marker1 is not defined"
Share Improve this question edited May 19, 2011 at 4:15 Nyxynyx asked May 18, 2011 at 18:52 NyxynyxNyxynyx 63.7k163 gold badges507 silver badges856 bronze badges 1- On a side note, I would remove the php tag, since this question has nothing to do with php. I'd do it myself, but I don't yet have the privileges to retag questions. – matzahboy Commented May 18, 2011 at 23:14
3 Answers
Reset to default 6Add a onmouseover property to the div. Let's say it was called changeMarker.
function changeMarker(marker) {
var icon = new Google.maps.MarkerImage({ url:"http://chart.apis.google./chart?chst=d_map_pin_letter&chld=1|ffffff|c41200"});
marker.setIcon(icon);
}
Your div could then look like:
<div onmouseover="changeMarker(marker1)">
I would remend however caching the MarkerImage (since it seems pretty static) so that Google doesn't need to keep regenerating the graph image.
You can set other properties of the image. See the documentation
google.maps.event.addListener(marker1, 'mouseover', function () {
marker1.setIcon('miniMarker.png');
});
first call initialize function, define marker1 and then use this code, You can also call this function from different ways like you want on div mouse over etc.
I'm using Chrome. In the console, onmouseover
the <div>
I get the error:
Uncaught ReferenceError: marker1 is not defined
If you set variable like this:
function a() {
var marker1 = "foo";
}
alert(marker1);
marker1 is not accessible at "window" level. You have to write it like this:
var marker1;
function a() {
marker1 = "foo";
}
alert(marker1);
本文标签: javascriptChange icon of google map marker when onmouseover div (Google maps v3 api)Stack Overflow
版权声明:本文标题:javascript - Change icon of google map marker when onmouseover div (Google maps v3 api) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742323057a2453177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论