Tôi có 4 tàu để thiết lập trên một bản đồ duy nhất, vì vậy tôi sử dụng ví dụ phát triển của Google và sau đó xoắn nó
https://developers.google.com/maps/documentation/javascript/examples/icon-complex
Trong chức năng dưới đây tôi đặt 3 các tùy chọn màu sắc khác:
function setMarkers(map, locations) {
...
var image = {
url: 'img/bullet_amarelo.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(40, 40),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 40)
};
var image1 = {
url: 'img/bullet_azul.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(40, 40),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 40)
};
var image2 = {
url: 'img/bullet_vermelho.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(40, 40),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 40)
};
var image3 = {
url: 'img/bullet_verde.png',
// This marker is 20 pixels wide by 32 pixels tall.
size: new google.maps.Size(40, 40),
// The origin for this image is 0,0.
origin: new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
anchor: new google.maps.Point(0, 40)
};
...
}
An d trong CHO rống lên tôi đặt một màu cho mỗi tàu:
for (var i = 0; i < locations.length; i++) {
...
if (i==0) var imageV=image;
if (i==1) var imageV=image1;
if (i==2) var imageV=image2;
if (i==3) var imageV=image3;
...
# remember to change icon: image to icon: imageV
}
Kết quả cuối cùng:
http://www.mercosul-line.com.br/site/teste.html
Thank you very much :) đây là những gì tôi đang tìm kiếm :) tôi có thể biết, để tôi áp dụng điều này bên trong nơi mà tôi nhanh chóng các điểm đánh dấu như tôi đã hiển thị hoặc là nó được định nghĩa bên ngoài riêng rẽ? :) –
Cả hai công việc. Hoặc bạn có thể thêm thuộc tính 'icon' và đặt nó, hoặc sử dụng' setIcon'. Tôi sẽ thêm lưu ý về điều này. – jsalonen
cảm ơn bạn rất nhiều vì đã giúp đỡ :) –