Googleマップjavascript Apiに新しいです。私のapplication.nowにカスタムオーバーレイを使用してカスタムマーカーを追加しました。カスタムマーカーにinfoWindowを追加したいaddDomListenerメソッドを使用して、アラートを追加することが私の次のコードノーマルマーカーのようなGoogleマップのカスタムオーバーレイに情報ウィンドウを追加する方法
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (pos) {
var myLatLng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
// var userObj = {}
function CustomMarker(latlng, map, imageSrc) {
this.latlng_ = latlng;
this.imageSrc = imageSrc;
// Once the LatLng and text are set, add the overlay to the map. This will
// trigger a call to panes_changed which should in turn call draw.
this.setMap(map);
}
CustomMarker.prototype = new google.maps.OverlayView();
CustomMarker.prototype.draw = function() {
// Check if the div has been created.
var div = this.div_;
if (!div) {
// Create a overlay text DIV
div = this.div_ = document.createElement('div');
// Create the DIV representing our CustomMarker
div.className = "customMarker"
var img = document.createElement("img");
img.src = this.imageSrc;
div.appendChild(img);
google.maps.event.addDomListener(div, "click", function (event) {
google.maps.event.trigger(me, "click");
});
// Then add the overlay to the DOM
var panes = this.getPanes();
panes.overlayImage.appendChild(div);
}
// Position the overlay
var point = this.getProjection().fromLatLngToDivPixel(this.latlng_);
console.log("ss :"+point.x)
if (point) {
div.style.left = point.x + 'px';
div.style.top = point.y + 'px';
}
};
CustomMarker.prototype.remove = function() {
// Check if the overlay was on the map and needs to be removed.
if (this.div_) {
this.div_.parentNode.removeChild(this.div_);
this.div_ = null;
}
};
CustomMarker.prototype.getPosition = function() {
return this.latlng_;
};
CustomMarker.prototype.setPosition = function (latlng_) {
this.latlng_=latlng_;
this.draw();
};
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
center:myLatLng
});
UserService.GetCurrent().then(function (user) {
$scope.user = user;
currentUser = user
user.lat = myLatLng;
user.mission = room;
socket.emit('subscribe', user);
interval= setInterval(getNewCords, 2000);
// $interval.cancel(interval);
console.log("ssa :"+angular.toJson(interval))
});
var infowindow = new google.maps.InfoWindow();
socket.on('userList', function (userList) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
console.log(userList[i].icon);
for (var i = 0; i < userList.length; i++) {
marker[userList[i].pseudoName]= new CustomMarker(new google.maps.LatLng(userList[i].lat.lat,userList[i].lat.lng), map, userList[i].icon)
markers.push(marker[userList[i].pseudoName]);
}
});
})
} else {
alert('Geo Location feature is not supported in this browser.');
}
を見つけてください、私のカスタムマーカー参照 custom marker
を見つけてくださいアレクセイZuevcustom overlay example
にjsのフィドルクレジットの下に見つけます
投稿したコードがあなたのフィドルと違っているようです。私は何とかあなたのフィドルに情報ウィンドウを置くことができました – JkAlombro