проблемы со стилем моей карты Google - PullRequest
1 голос
/ 16 декабря 2011

Я всю неделю пытаюсь стилизовать свою карту Google и хожу кругами! У меня есть значения JSON, которые я хочу использовать, но не знаю, как добавить их в JavaScript! Я также хочу, чтобы элемент управления на панели масштабирования располагался справа от окна, а не слева, поскольку моя карта представляет собой полный фон страницы, поэтому слева она скрыта за элементами содержимого сайта.

Кто-нибудь может помочь?

:)

JSON, который я хочу добавить:

[{stylers: [{saturation: -90}, {gamma: 0.87}]}]

А у меня есть код для моей карты:

<script type="text/javascript">
//<![CDATA[

if (GBrowserIsCompatible()) { 

  // A function to create the marker and set up the event window
  // Dont try to unroll this function. It has to be here for the function closure
  // Each instance of the function preserves the contends of a different instance
  // of the "marker" and "html" variables which will be needed later when the event triggers.    
  function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    return marker;
  }

  // Display the map, with some controls and set the initial location 
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(50.826910965853585, -0.13648152351379395), 16);




  // Set up the markers with info windows 

  var point = new GLatLng(50.826910965853585, -0.13648152351379395);
  var marker = createMarker(point,'<div style="width:300px">text for pop up here....</div>')
  map.addOverlay(marker);





}







// display a warning if the browser was not compatible
else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

// This Javascript is based on code provided by the
// Community Church Javascript Team
// http://www.bisphamchurch.org.uk/   
// http://econym.org.uk/gmap/

//]]>
</script>

Ответы [ 2 ]

0 голосов
/ 17 декабря 2011

Проблема в том, что вы пытаетесь использовать Maps API V2, который не дает вам возможности стилизовать вашу карту. Как упоминалось в графическом разделении, этот код поможет вам оформить карту Maps API V3: http://code.google.com/apis/maps/documentation/javascript/styling.html#styling_the_default_map

Вы должны переключаться в любом случае, поскольку V2 устарела. Чтобы начать работу с картой V3, откройте страницу Основы API Карт .

0 голосов
/ 16 декабря 2011

Попробуйте:

var myStyles = [
  {
    featureType: "all",
    stylers: [ { saturation: -90 }, { gamma: 0.87 }
  }
];

map.setOptions({styles: myStyles });

На основе: http://code.google.com/apis/maps/documentation/javascript/styling.html#styling_the_default_map

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...