M
M
mrzgt2015-10-12 18:40:46
JavaScript
mrzgt, 2015-10-12 18:40:46

How to duplicate a script?

There is a script that displays a Google map, on one page you need to display several different maps, I can’t figure out how to properly duplicate the script

<script>
var map;
var egglabs = new google.maps.LatLng(55.883798, 37.42366);
var mapCoordinates = new google.maps.LatLng(55.883798, 37.42366);


var markers = [];
var image = new google.maps.MarkerImage(
    '9lessons.png',
    new google.maps.Size(100,100),
    new google.maps.Point(0,0),
    new google.maps.Point(42,56)
  );

function addMarker() 
{
      markers.push(new google.maps.Marker({
      position: egglabs,
      raiseOnDrag: false,
    icon: image,
      map: map,
      draggable: false
      }));
      
}

function initialize() {
  var mapOptions = {
  backgroundColor: "#ffffff",
    zoom: 14,
  disableDefaultUI: true,
  zoomControl: true,
  scrollwheel: false,
      zoomControlOptions: {
        style: google.maps.ZoomControlStyle.LARGE,
        position: google.maps.ControlPosition.RIGHT_CENTER
    },
    center: mapCoordinates,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
  
  styles: [
        {
          "featureType": "landscape.natural",
          "elementType": "geometry.fill",
          "stylers": [
            { "color": "#OOO" }
          ]
        },
        {
            "featureType": "landscape.man_made",
            "stylers": [
              { "color": "#ooo" },
              { "visibility": "off" }
            ]
        },
        {
            "featureType": "water",
            "stylers": [
               { "color": "#80C8E5" },
              { "saturation": 0 }
            ]
        },
        {
            "featureType": "road.arterial",
            "elementType": "geometry",
            "stylers": [
              { "color": "#999999" }
            ]
        }
       ,{
            "elementType": "labels.text.stroke",
            "stylers": [
              { "visibility": "off" }
            ]
        }
        ,{
            "elementType": "labels.text",
            "stylers": [
              { "color": "#333333" }
            ]
          }
        
        ,{
            "featureType": "road.local",
            "stylers": [
              { "color": "#dedede" }
            ]
          }
        ,{
            "featureType": "road.local",
            "elementType": "labels.text",
            "stylers": [
              { "color": "#666666" }
            ]
          }
        ,{
            "featureType": "transit.station.bus",
            "stylers": [
              { "saturation": -57 }
            ]
          }
        ,{
            "featureType": "road.highway",
            "elementType": "labels.icon",
            "stylers": [
              { "visibility": "off" }
            ]
          },{
            "featureType": "poi",
            "stylers": [
              { "visibility": "off" }
            ]
          }
      
      ]
      
    
  };
map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
addMarker();
 
}
google.maps.event.addDomListener(window, 'load', initialize);

    </script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2015-10-12
@IonDen

You must wrap the code in a function .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question