cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              html,
body,
#map {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

#geocodeError {
    position: absolute;
    display: none;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    padding: 25px;
    width: 250px;
    height: 150px;
    background: #fff;
    border: 2px solid #000;   
    font-weight: bold;
    font-size: 1.1em;
    text-align: center;
    z-index: 2000;
}

#errorCloseBtn {
    position: absolute;
    padding: 8px;    
    top: 2px;
    right: 4px;
    font-weight: bold;
    font-size: 0.96em;
}

#errorText {
    margin-top: 30px;
}
            
          
!
            
              'use strict';

// create geocode error box element
var geocodeErEl = document.createElement('div');
geocodeErEl.setAttribute('id', 'geocodeError');
    
// create close button for error box
var geocoderErCloseEl = document.createElement('input');
geocoderErCloseEl.setAttribute('id','errorCloseBtn');
geocoderErCloseEl.setAttribute('type','button');
geocoderErCloseEl.setAttribute('value', 'X');
    
// create paragraph element to contain error text
var geocodeErTextEl = document.createElement('p');
geocodeErTextEl.setAttribute('id','errorText');
    
// append elements to geocode error div
jQuery(geocodeErEl).append(geocoderErCloseEl);
jQuery(geocodeErEl).append(geocodeErTextEl);
        
// append elememnts to map
jQuery('#map').append(geocodeErEl);

// Map
var map = L.map('map', {
   center: [40.15, -77.25],
   zoom: 10,               
});

// Open Street Map 
var osm = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&#169; <a href="//www.openstreetmap.org/">OpenStreetMap</a> contributors, CC BY-SA license'
}).addTo(map);

// container for address search results
var addressSearchResults = new L.LayerGroup().addTo(map);

/*** Geocoder ***/
// OSM Geocoder
var osmGeocoder = new L.Control.OSMGeocoder({
    collapsed: false,
    position: 'topright',
    text: 'Search',
    placeholder: 'Enter address',    
    callback: function(results) {
            // error box element
            var geocodeErrorBox = jQuery('#geocodeError');
            var geocodeErrorText = jQuery('#errorText');
            
            // close error box if it is open
            if (!geocodeErrorBox.css('display','none')) {
                geocodeErrorBox.hide();
            }
            
            // If no results are found, add a message to the screen
            if (results.length == 0) {
				// placeholder="" is key to selecting DOM element
                var searchText = jQuery('.leaflet-control-geocoder-form input[placeholder="Enter address"]').val();
                // get search text or result text and put that in box
                geocodeErrorText.html('No results found for ' + searchText);
                geocodeErrorBox.show();
                return;
			}
            
            // clear previous geocode results
            addressSearchResults.clearLayers();
            
            // create icon for result
            var addressSearchIcon = L.AwesomeMarkers.icon({
                icon: 'map',
                prefix: 'fa',
                markerColor: 'orange',
                iconColor: '#fff'
             });
            
            // get coordinates for result
            var coords = L.latLng(results[0].lat,results[0].lon);
        
            // create a marker for result
            var marker = L.marker(coords, {
                icon: addressSearchIcon
            });
            
            // add result object to map and zoom to 
            addressSearchResults.addLayer(marker);            
            this._map.addLayer(marker).setView(coords,17);  
            
            // open pop-up for location
            var popup = L.popup({closeOnClick: true}).setLatLng(coords).setContent(results[0].display_name).openOn(map);
        }
    }).addTo(map);    

// add event listener to click event for error message close button
jQuery('#errorCloseBtn').click(function() {
   jQuery('#geocodeError').hide();
})
            
          
!
999px
Loading ..................

Console