Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- MAPBOX -->
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.0.0/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.0.0/mapbox.css' rel='stylesheet' />


<div id='map'></div>
              
            
!

CSS

              
                @import "lesshat";

body { margin:0; padding:0; }

#map { 
  position:absolute; 
  top:0; 
  bottom:0; 
  left:0;
  right:0;
}

img {
  position:relative;
  height:100%;
  width: 100%;
}

/* MARKER */
.marker {
  position: relative;
  top:0;
  left:0;
}

.pin {
  width: 30px;
  height: 30px;
  border-radius: 50% 50% 50% 0;
  background: red;
  position: absolute;
  
  margin: -20px 0 0 -20px;
  transform: rotate(-45deg);
}

.pin img {
  transform: rotate(45deg);
}

.bounce {
  animation-name: bounce;
  animation-fill-mode: both;
  animation-duration: 1s;
}

.pulse {
  background: #d6d4d4;
  border-radius: 50%;
  height: 14px;
  width: 14px;
  position: absolute;
  margin: 11px 0px 0px -12px;
  transform: rotateX(55deg);
  z-index: -2;
}
.pulse:after {
  content: "";
  border-radius: 50%;
  height: 40px;
  width: 40px;
  position: absolute;
  margin: -13px 0 0 -13px;
  animation: pulsate 1s ease-out;
  animation-iteration-count: infinite;
  opacity: 0;
  box-shadow: 0 0 1px 2px #00cae9;
  animation-delay: 1.1s;
}

@keyframes pulsate {
  0% {
    transform: scale(0.1, 0.1);
    opacity: 0;
  }

  50% {
    opacity: 1;
  }

  100% {
    transform: scale(1.2, 1.2);
    opacity: 0;
  }
}

@keyframes bounce {
  0% {
    opacity: 0;
    transform: translateY(-2000px) rotate(-45deg);
  }

  60% {
    opacity: 1;
    transform: translateY(30px) rotate(-45deg);
  }

  80% {
    transform: translateY(-10px) rotate(-45deg);
  }

  100% {
    transform: translateY(0) rotate(-45deg);
  }
}
              
            
!

JS

              
                // Provide your access token
L.mapbox.accessToken = 'pk.eyJ1IjoicWVydGlzIiwiYSI6IjNjMnFWaWcifQ.T3wJBXWarfTog8c-ooB5Ig';
    
var map = L.mapbox.map('map', 'examples.map-h68a1pf7')
    .setView([27.93, -37.45], 3);

var myLayer = L.mapbox.featureLayer().addTo(map);

  var inactiveMarker = L.marker(new L.LatLng(37.9, -77), {
        icon: L.mapbox.marker.icon({
            'marker-color': '#000'
        }),
        draggable: false
    }).addTo(map);
inactiveMarker._icon.style.opacity = 0.5;

// For 0 -> 9, create markers in a circle
for (var i = 0; i < 1; i++) {
    // Use a little math to position markers.
    // Replace this with your own code.
    var marker = L.marker([
        Math.cos(i / 10 * 2 * Math.PI) * 40,
        Math.sin(i / 10 * 2 * Math.PI) * 40
    ], {
      draggable: true,
        icon: L.divIcon({
            className: 'count-icon',
          html: 
          "<div class='marker'>" + 
            "<div class='pin bounce'>" +
          "<img src='http://upload.wikimedia.org/wikipedia/commons/8/87/Avatar_poe84it.png'>" +  
          
            "</div>" +
            "<div class='pulse'></div>"+
          "</div>",
          
            // Set a markers width and height.
            iconSize: [30, 30]
        })
    })
    .on('click', function(e) { 
      //alert(e)  
    })
    .on('drag', function() {
        //получить lat lng
        var marker1LatLng = this.getLatLng()
        var marker2LatLng = inactiveMarker.getLatLng()

        //преобразовать в координаты x y
        var point1 = map.latLngToContainerPoint(marker1LatLng)
        var point2 = map.latLngToContainerPoint(marker2LatLng)

        //приклеить маркер из точки один в точку два, дистанция, колбэк
        markerToStick(point1.x, point1.y, point2.x, point2.y, 50, function() {
            inactiveMarker.setLatLng(marker1LatLng)
        })
    })  
    .bindPopup("<b>Hello</b> marker", {
        closeButton: true,
        minWidth: 320
    }).openPopup()
    .addTo(map);
}

 function markerToStick(x1, y1, x2, y2, distance, cb) {
        var vecElem1 = new Victor(x1, y1);
        var vecElem2 = new Victor(x2, y2);
        var myDistance = vecElem1.distance(vecElem2);

        //прилепляем если дистанция маленькая
        if(myDistance < distance) {
            cb();
        }

        console.log(myDistance)
    }
              
            
!
999px

Console