davestacey
2/17/2015 - 9:01 PM

Add the Office marker using the office location passed from the Drupal node, on click zoom in.

Add the Office marker using the office location passed from the Drupal node, on click zoom in.

      /////////////////////////////
      // Add the Office marker
      nsmap.addOfficeMarker = function (map, coordinates) {
        var longitude = coordinates.lon;
        var latitude = coordinates.lat;

         //This uses Leaflet.js's markers:
         var officeMarker = L.divIcon({
          iconSize:     [2, 20],
          iconAnchor:   [20, 30],
          className: 'comment',
          html: '<i class="fi-marker medium"></i>'
         });
         
        var marker = L.marker([latitude, longitude], {icon: officeMarker}).addTo(map);

        // Popup
        //marker.bindPopup("<b>Hello world!</b><br>I am a popup.").openPopup();
        // map.on('click', function(e) {
        //   console.log(this);
        //   //console.log(nsmap.bounds);
        //   //map.fitBounds(nsmap.bounds);
        // }

        marker.on('click', function(e) {
            // TODO - toggle click function for zoom and reset
            //console.log('nsmap.initialPosition', nsmap.initialPosition);
            if (nsmap.zoomed === false){
              //console.log('Zooming in');
              nsmap.initialPosition.groupCenter = map.getCenter();
              nsmap.initialPosition.groupZoom = map.getZoom();
              map.setView(new L.LatLng(e.latlng.lat, e.latlng.lng), 9);
              nsmap.zoomed = true;
            } else {
              //console.log('Zooming out');
              map.setView(new L.LatLng(nsmap.initialPosition.groupCenter.lat, nsmap.initialPosition.groupCenter.lng), nsmap.initialPosition.groupZoom);
              nsmap.zoomed = false;
            }
            //map.panTo(new L.LatLng(40.737, -73.923));
        });

        // capture map click
        map.on('click', onMapClick);
        function onMapClick(){
          //console.log('initialPosition', nsmap.initialPosition);
          if (nsmap.zoomed === true){
            //console.log('Zooming out');
            map.setView(new L.LatLng(nsmap.initialPosition.groupCenter.lat, nsmap.initialPosition.groupCenter.lng), nsmap.initialPosition.groupZoom);
            nsmap.zoomed = false;
          }
        };
        // click action
        // var popup = L.popup();
        // function onMapClick(e) {
        //     popup
        //         .setLatLng(e.latlng)
        //         .setContent("You clicked the map at " + e.latlng.toString())
        //         .openOn(map);
        // }
      }//END addOfficeMarker()