Guest User

Untitled

a guest
Jul 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <script src="https://yandex.st/jquery/2.2.3/jquery.min.js" type="text/javascript"></script>
  2.  
  3. <script charset="utf-8" src="https://api-maps.yandex.ru/1.1/index.xml" type="text/javascript"></script>
  4.  
  5. <div style="width:600px;height:400px" id="YMapsID" class="YMaps YMaps-cursor-grab"></div>
  6.  
  7. <? $pint = '58.211748';?>
  8. <script type="text/javascript">
  9. var points_json = '{"Points":[{"MapPoinName": "Город 1","MapPointPopulation": 125000,"MapPointCoordinates": "<?=$pint?>, 59.979321"}, {"MapPoinName": "Город 2","MapPointPopulation": 105000,"MapPointCoordinates": "51.221748, 53.929321"}]}';
  10. var points = $.parseJSON(points_json);
  11. // Создание обработчика для события window.onLoad
  12. YMaps.jQuery(function () {
  13. // Создание экземпляра карты и его привязка к созданному контейнеру
  14. var map = new YMaps.Map(YMaps.jQuery("#YMapsID")[0]),
  15.  
  16. // Центр карты
  17. center,
  18.  
  19. // Масштаб
  20. zoom = 10;
  21.  
  22. // Получение информации о местоположении пользователя
  23. if (YMaps.location) {
  24. center = new YMaps.GeoPoint(YMaps.location.longitude, YMaps.location.latitude);
  25.  
  26. if (YMaps.location.zoom) {
  27. zoom = 3;
  28. }
  29.  
  30. map.openBalloon(center, "Место вашего предположительного местоположения:<br/>"
  31. + (YMaps.location.country || "")
  32. + (YMaps.location.region ? ", " + YMaps.location.region : "")
  33. + (YMaps.location.city ? ", " + YMaps.location.city : "")
  34. )
  35. }else {
  36. center = new YMaps.GeoPoint(37.64, 55.76);
  37. }
  38. for(var i=0;i < points.Points.length;i++){
  39. var tmp_points = points.Points[i]['MapPointCoordinates'].split(', ');
  40. var desc = points.Points[i]['MapPointPopulation'];
  41. var placemark = new YMaps.Placemark(new YMaps.GeoPoint(tmp_points[0],tmp_points[1]));
  42.  
  43. placemark.description = "point "+i+" description" + desc;
  44. map.addOverlay(placemark);
  45.  
  46. center = new YMaps.GeoPoint(tmp_points[0], tmp_points[1]);
  47.  
  48. }
  49. // Рисуем карту
  50. map.setCenter(center, zoom);
  51. });
  52. </script>
Add Comment
Please, Sign In to add comment