-1

我在我的联系页面http://www.liebekuchen.co.uk/talk-to-us/上有一个样式化的 Google Map V3,它可以正常工作,除了精灵图像显示的一些问题,但是我需要将此 JSON 添加到两个我的陈列室页面上的单独地图http://www.liebekuchen.co.uk/kitchen-showrooms/如何为具有不同位置的多张地图添加样式?页面头部调用的JS;

<script type="text/javascript">

$(document).ready(function() {

    // V3 map

        var myLatlng = new google.maps.LatLng('51.4525368','0.2481994');


        var mapOptions = {

        mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: new google.maps.LatLng('51.4600368','0.0781994'),
        zoom: 11,
        mapTypeControl: false,
        scrollwheel:false

        };

        var map = new google.maps.Map(document.getElementById("head-office-map"), mapOptions);


      var styles = [
      map styles here...
        ]
      }
    ];


    map.setOptions({styles: styles});

    var contentString = "";

   var infowindow = new google.maps.InfoWindow({
        content: contentString,

    });

    var $image = new google.maps.MarkerImage("../images/icons/LK-mapicon.png",
    // size
    new google.maps.Size(50, 50),
    // origin
    new google.maps.Point(0, 0),
    // anchor
    new google.maps.Point(25, 50));

    var $shadow = new google.maps.MarkerImage("../images/icons/LK-mapicon-shadow.png",
    // size
    new google.maps.Size(65, 39),
    // origin
    new google.maps.Point(0, 0),
    // anchor
    new google.maps.Point(25, 50));

    var marker = new google.maps.Marker({
        clickable: false,
        position: myLatlng,
        map: map,
        title:"Liebe Kuchen Head Office",
        icon:$image,
        shadow:$shadow
    });

    google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    });


});

4

1 回答 1

0

如果您想将相同的 javascript 添加到多个页面,请创建一个仅定义该代码(地图样式)的外部文件,并将其包含在所有需要它的地图中。(未测试)

<script type="text/javascript" src="scripts/mapstyle.js"></script>

其中“mapstyle.js”将包含:

  var styles = [
  map styles here...
    ]
  }
];
于 2013-01-10T14:55:36.823 回答