我正在为即将到来的节日创建一个场地列表,并希望每个场地都标有单独的标记图像。虽然我已经完成了地图的所有其他方面的工作,但我似乎无法在场地阵列中分配单个标记图像。
这就是我所拥有的:
function initialize() {
var styles = [
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [ { "visibility": "on" }, { "color": "#f5f5f5" } ] },
{ "featureType": "landscape.natural",
"stylers": [ { "visibility": "on" }, { "invert_lightness": true }, { "color": "#dadad9" } ] },
{ "featureType": "landscape.man_made",
"stylers": [ { "visibility": "off" }, { "color": "#ebebeb" } ] },
{ "featureType": "road.arterial", "elementType": "geometry",
"stylers": [ { "visibility": "simplified" }, { "color": "#ffffff" } ] },
{ "featureType": "road.arterial", "elementType": "labels.text",
"stylers": [ { "saturation": -100 }, { "gamma": 3.31 }, { "weight": 0.1 } ] },
{ "featureType": "road.arterial", "elementType": "labels.stroke",
"stylers": [ { "visibility": "off" } ] },
{ "featureType": "road.highway", "elementType": "geometry",
"stylers": [ { "visibility": "simplified" }, { "color": "#ffffff" } ] },
{ "featureType": "road.highway", "elementType": "labels", "stylers": [ { "visibility": "simplified" } ] },
{ "featureType": "road.highway", "elementType": "labels", "stylers": [ { "visibility": "off" } ] },
{ "featureType": "road.highway", "elementType": "labels.text.fill", "stylers": [ { "visibility": "on" } ] },
{ "elementType": "labels.icon", "stylers": [ { "visibility": "off" } ] },
{ "featureType": "road.local", "elementType": "geometry",
"stylers": [ { "visibility": "simplified" }, { "color": "#ffffff" } ] },
{ "featureType": "road.local", "elementType": "labels", "stylers": [ { "visibility": "simplified" } ] },
{ "featureType": "road.local", "elementType": "labels", "stylers": [ { "visibility": "off" } ] },
{ "featureType": "road.local", "elementType": "labels.text.fill", "stylers": [ { "visibility": "on" } ] },
{ "featureType": "water",
"stylers": [ { "color": "#646464" } ] },
{ "featureType": "poi.business",
"stylers": [ { "visibility": "on" } ] },
{ "featureType": "transit.line", "elementType": "labels.text",
"stylers": [ { "color": "#eeccff" }, { "visibility": "simplified" } ] },
{ "featureType": "transit.line", "elementType": "geometry.fill",
"stylers": [ { "visibility": "on" }, { "color": "#ff8080" } ] },
{
"featureType": "poi",
"stylers": [
{ "visibility": "off" }
]
},
{
"featureType": "administrative",
"stylers": [
{ "visibility": "off" }
]
},
{
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [
{ "visibility": "on" },
{ "color": "#e6e6e6" }
]
}
]
// STYLE
var styledMap = new google.maps.StyledMapType(styles,
{name: "Styled Map"});
var homePoint = new google.maps.LatLng(53.34729785,-6.25924587),
markers,
myMapOptions = {
zoom: 15,
center: homePoint,
disableDefaultUI: false,
zoomControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
map = new google.maps.Map(document.getElementById("map_canvas"), myMapOptions);
// var image = 'marker.png';
// var myLatLng = new google.maps.LatLng(53.34457415, -6.26930952);
// var Marker = new google.maps.Marker({
// position: myLatLng,
// map: map,
// icon: image
// });
// var image = 'theatre_04.png';
// var theLatLng = new google.maps.LatLng(52.34457415, -6.26930952);
// var Marker = new google.maps.Marker({
// position: theLatLng,
// map: map,
// title: 'Click to zoom',
// icon: image,
// address: "Abbey Theatre, 26 Lwr Abbey St, Dublin 1",
// tel: "+353 1 878 7222",
// link: "http://www.abbeytheatre.ie"
// });
// Marker style 1
function initMarkers(map, markerData) {
var newMarkers = [],
marker;
var newMarker = new google.maps.MarkerImage('theatre_01.png',
new google.maps.Size(30,30),
new google.maps.Point(0,0)
);
for(var i=0; i<markerData.length; i++) {
marker = new google.maps.Marker({
map: map,
// icon: newMarker,
draggable: false,
position: markerData[i].latLng,
visible: true,
labelContent: i,
labelClass: "labels"
}),
boxText = document.createElement("div"),
//INFOBOX STYLE
infoboxOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(0, 0),
zIndex: null,
boxStyle: {
opacity: 0.75,
width: "150px"
},
closeBoxMargin: "5px",
closeBoxURL: "close.png",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
// add a click listener to the marker
google.maps.event.addListener(marker, 'click', function() {
// reference clicked marker
var curMarker = this;
// loop through all markers
$.each(markers, function(index, marker) {
// if marker is not the clicked marker, close the marker
if(marker !== curMarker) {marker.infobox.close();}
});
});
newMarkers.push(marker);
//INFOBOX TEMPLATE
boxText.style.cssText = "background:#fff; color:#000; padding: 20px;";
boxText.innerHTML = "<a target='_blank' href='" + markerData[i].link + "'>" + markerData[i].tel + "<br/>" + markerData[i].address + "</a>";
newMarkers[i].infobox = new InfoBox(infoboxOptions);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
newMarkers[i].infobox.open(map, this);
map.panTo(markerData[i].latLng);
}
})(marker, i));
}
return newMarkers;
}
//MARKERS ARRAY
markers = initMarkers(map, [
{ latLng: new google.maps.LatLng(53.3485401, -6.257107), address: "Abbey Theatre, 26 Lwr Abbey St, Dublin 1", tel: "+353 1 878 7222", link: "http://www.abbeytheatre.ie" },
{ latLng: new google.maps.LatLng(53.3450158, -6.2650386), address: "The Ark, A Cultural Centre For Children, 11a Eustace St, Temple Bar, Dublin 2", tel: "+353 1 670 7788", link: "http://www.ark.ie" },
{ latLng: new google.maps.LatLng(53.39610586, -6.26289368), address: "axis:Ballymun, Dublin 9", tel: "+353 1 883 2100", link: "http://www.axis-ballymun.ie" },
{ latLng: new google.maps.LatLng(53.28856459, -6.3716197), address: "Civic Theatre, Tallaght, Dublin 24", tel: "+353 1 462 7477", link: "http://www.civictheatre.ie" },
{ latLng: new google.maps.LatLng(53.3453276, -6.2657425), address: "The Culture Box, 12 East Essex St, Temple Bar, Dublin 2" },
{ latLng: new google.maps.LatLng(53.3525572, -6.2500383), address: "DanceHouse, 1 Foley St, Dublin 1" },
{ latLng: new google.maps.LatLng(53.3934229, -6.3858142), address: "Draíocht, The Blanchardstown Centre, Dublin 15", tel: "+353 1 885 2622", link: "http://www.draiocht.ie" },
{ latLng: new google.maps.LatLng(53.3432286, -6.2565383), address: "Edmund Burke Theatre Arts Building, Trinity College, Dublin 2" },
{ latLng: new google.maps.LatLng(53.3449723, -6.2666144), address: "Festival Box Office, 44 East Essex St, Temple Bar, Dublin 2", tel: "+353 1 677 8899", link: "http://www.dublintheatrefestival.com" },
{ latLng: new google.maps.LatLng(53.3401925, -6.2611233), address: "Gaiety Theatre, 53/54 South King St, Dublin 2", tel: "0818 719 300", link: "http://www.gaietytheatre.ie" },
{ latLng: new google.maps.LatLng(53.3392288, -6.2463933), address: "Goethe-Institut, 37 Merrion Sq, Dublin 2" },
{ latLng: new google.maps.LatLng(53.3435732, -6.2639487), address: "Odessa, 13 Dame Court, Dublin 2" },
{ latLng: new google.maps.LatLng(53.3515299, -6.2532256), address: "Oonagh Young Gallery, 1 James Joyce St, Liberty Corner, Dublin 1" },
{ latLng: new google.maps.LatLng(53.3553559, -6.2621326), address: "OReilly Theatre, Belvedere 6 Great Denmark St, Dublin 1 "},
{ latLng: new google.maps.LatLng(53.2934538, -6.1348062), address: "Pavilion Theatre Marine Road, Dún Laoghaire, Co. Dublin", tel: "+353 1 231 2929", link: "http://www.paviliontheatre.ie" },
{ latLng: new google.maps.LatLng(53.3450204, -6.2662288), address: "Project Arts Centre, 39 East Essex St, Temple Bar, Dublin 2", tel: "+353 1 881 9613", link: "http://www.projectartscentre.ie" },
{ latLng: new google.maps.LatLng(53.34492803, -6.25734687), address: "Samuel Beckett Theatre, Trinity College, Dublin 2" },
{ latLng: new google.maps.LatLng(53.3449333, -6.2688625), address: "Smock Alley Theatre, 6/7 Exchange St Lwr, Dublin 8", tel: "+353 1 677 0014", link: "http://www.smockalley.com" },
{ latLng: new google.maps.LatLng(53.3455723, -6.2636546), address: "Temple Bar Gallery and Studios, 5 – 9 Temple Bar, Dublin 2"},
]);
//HOOK UP STYLES
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
}
如果更容易,您可以在此处查看 wip:http: //www.detail.ie/ftp/DTF/map/dtf_5.html
提前致谢,
磷