خرید بک لینک

Vote count: 0

I'm working on a custom Google map. I have multiple markers with custom infowindows (everything working, wrapped in divs and styled). I've managed to assign links in a sidebar menu to the markers, so that an infowindow opens, when a menu item is clicked. The problem is, that it is always the same infowindow. I've probably gone through every question and answer on this subject, but I just can't get this to work...

The code for the map, markers, infowindows is:

var map;
var markers = [];
var content = [];
var map = new google.maps.LatLng(46.2171749, 7.5984075);     

var MY_MAPTYPE_ID = 'custom_style';
function initialize() {

var featureOpts = [ 
{ 
"featureType": "landscape.natural.landcover", 
"elementType": "geometry.fill", 
"stylers": [ 
   { "visibility": "on" }, 
   { "color": "#f2f9f4" } 
    ] 
  }, // and so on with the styling

var mapOptions = {
zoom: 10,
center: map,
mapTypeControl: false,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
},
mapTypeId: MY_MAPTYPE_ID
};

map = new google.maps.Map(document.getElementById('map-canvas'),
  mapOptions);

var styledMapOptions = {
name: 'Custom Style'
};

var customMapType = new google.maps.StyledMapType(featureOpts,styledMapOptions);

map.mapTypes.set(MY_MAPTYPE_ID, customMapType);

var locations = [
        ['Location 1', 46.096678, 7.2281081, 'pin.png', 1],
        ['Location 2', 46.0230159, 7.7428676, 'pin.png', 2],
        ['Location 3', 46.1125509, 7.919948, 'pin.png', 3],
    ];

   var infobox = new InfoBox({
     content: document.getElementById("infobox"),
     disableAutoPan: false,
     maxWidth: 800,
     pixelOffset: new google.maps.Size(-400, 10),
     zIndex: null,
     closeBoxMargin: "12px 12px 2px 2px",
     closeBoxURL: "icon-close.png",
     infoBoxClearance: new google.maps.Size(0, 0),
});

    var marker, i;
    for (i = 0; i < locations.length; i++) {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map,
            icon: locations[i][3]
        });

        markers.push(marker);

        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            retu function() {
                infobox.open(map, marker);
               /* infowindow.setContent(locations[i][0]); //enabling this line disables correct map paing!! */
                map.panTo(marker.getPosition(0, 427));
                map.panBy(0, 400);
            }
        })(marker, i));
    }
}

function myClick(id){
        google.maps.event.trigger(markers[id], 'click');
    }

google.maps.event.addDomListener(window, 'load', initialize);

The content for the infowindows is in the html, like so:

<div id="Location 1">
<div id="infobox_wrapper">    
<div id="infobox">
<div id="infobox_title_wrapper">
<div id="info_icon">
<img src="green_s.png"/>
</div>
<div id="info_title"><p>##</p>
</div>
<div id="info_place"><p>##</p>
</div>
</div>
<iframe width="800" height="450" src="##" frameborder="0" allowfullscreen></iframe>
<p class= "txt">##</p>
</div>
</div>
</div>

Does anyone have a solution for getting this to work? Is there any simple way of calling the infowindow content for each marker e.g. from the var locations = [] array, meaning that when a location is added, and a div or other id is specified there, the marker, along with the corresponding infowindow is placed on the map? Also, a side issue, the line infowindow.setContent(locations[i][0]); disables the correct paing of the map to the markers... Thanks

asked 35 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 5 ارديبهشت 1395 ساعت: 0:38

صفحه بندی