0

ユーザーがリンクをクリックしたときにマップにマーカーを入力する次のスクリプトがあります。

1から12の個別のマーカーがあり、変数favoriteが1に等しい場合は、別のマーカーを使用します。

同じマップ上に複数のお気に入りが存在する可能性があります。

「newgoogle.maps.Marker」セクションで「iffavorite==1」のピースを追加する必要があると思いますが、頭を悩ませることはできません。

<script>
$(document).ready(function() {
$("#map").css({
    height: 900,
    width: 1400
});
var myLatLng = new google.maps.LatLng(<%=dcLatLng%>); //Query database for map center
MYMAP.init('#map', myLatLng, 12);

$("#showmarkers").click(function(e){
    MYMAP.placeMarkers('markers.asp?WisperID=<%=sWisperID%>');
});
});

var MYMAP = {
map: null,
bounds: null
}

MYMAP.init = function(selector, latLng, zoom) {
var myOptions = {
zoom:zoom,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map($(selector)[0], myOptions);
this.bounds = new google.maps.LatLngBounds();
}

MYMAP.placeMarkers = function(filename) {
$.get(filename, function(xml){
    $(xml).find("marker").each(function(){
        var name = $(this).find('name').text();
        var address = $(this).find('address').text();
        var postcode = $(this).find('postcode').text();
        var favourite = $(this).find('favourite').text();
        // create a new LatLng point for the marker
        var lat = $(this).find('lat').text();
        var lng = $(this).find('lng').text();
        var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));

        // extend the bounds to include the new point
        MYMAP.bounds.extend(point);



        var marker = new google.maps.Marker({
            position: point,
            map: MYMAP.map,
            icon: new google.maps.MarkerImage(
            '/images/int.png',
            new google.maps.Size(93, 63),
            new google.maps.Point(0, 0),
            new google.maps.Point(0, 63)
  )
        });




        var infoWindow = new google.maps.InfoWindow();
        var html='<strong>'+name+'</strong.><br />'+address+'<br  />'+postcode+'<br /><p>'+favourite+'</p>';
        google.maps.event.addListener(marker, 'mouseover', function() {
            infoWindow.setContent(html);
            infoWindow.open(MYMAP.map, marker);
        });
        google.maps.event.addListener(marker, 'mouseout', function() {
            infoWindow.setContent(html);
            infoWindow.close(MYMAP.map, marker);
        });
        MYMAP.map.fitBounds(MYMAP.bounds);
    });
});
}
</script>
4

1 に答える 1

0

あなたはほとんどそれを持っています。私はこのようなものがあなたの要件を満たしていると思います:

if (favourite == '1') {
        var marker = new google.maps.Marker({
            position: point,
            map: MYMAP.map,
            icon: new google.maps.MarkerImage(
                '/images/favourite.png',  // different image
                new google.maps.Size(93, 63),
                new google.maps.Point(0, 0),
                new google.maps.Point(0, 63)
            )
        });
} else {
        var marker = new google.maps.Marker({
            position: point,
            map: MYMAP.map,
            icon: new google.maps.MarkerImage(
                '/images/int.png',
                new google.maps.Size(93, 63),
                new google.maps.Point(0, 0),
                new google.maps.Point(0, 63)
            )
        });
}
于 2012-10-15T12:44:17.970 に答える