123

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Geocoding</title>
</head>

<body>
    <!-- This <div> is the container into which our map control will be loaded. -->
    <div id="map">
        <div class="geocodingPanel">
            <div class="geocoding-row" id="geocoding-row">
                <span>Search in Country(ies)</span>
                <select id="country-filter">
                    <option value="" selected>All</option>
                    <option value="us">United States</option>
                    <option value="jp">Japan</option>
                    <option value="de">Germany</option>
                    <option value="gb">United Kingdom</option>
                    <option value="in">India</option>
                    <option value="fr">France</option>
                    <option value="br">Brazil</option>
                    <option value="it">Italy</option>
                    <option value="ca">Canada</option>
                    <option value="cn">China</option>
                    <option value="af">Afghanistan</option>
                    <option value="ax">Aland Islands</option>
                    <option value="al">Albania</option>
                    <option value="dz">Algeria</option>
                    <option value="as">American Samoa</option>
                    <option value="ad">Andorra</option>
                    <option value="ao">Angola</option>
                    <option value="ai">Anguilla</option>
                    <option value="aq">Antarctica</option>
                    <option value="ag">Antigua and Barbuda</option>
                    <option value="ar">Argentina</option>
                    <option value="am">Armenia</option>
                    <option value="aw">Aruba</option>
                    <option value="au">Australia</option>
                    <option value="at">Austria</option>
                    <option value="az">Azerbaijan</option>
                    <option value="bs">Bahamas</option>
                    <option value="bh">Bahrain</option>
                    <option value="bd">Bangladesh</option>
                    <option value="bb">Barbados</option>
                    <option value="by">Belarus</option>
                    <option value="be">Belgium</option>
                    <option value="bz">Belize</option>
                    <option value="bj">Benin</option>
                    <option value="bm">Bermuda</option>
                    <option value="bt">Bhutan</option>
                    <option value="bo">Bolivia</option>
                    <option value="bq">Bonaire, Sint Eustatius and Saba</option>
                    <option value="ba">Bosnia and Herzegovina</option>
                    <option value="bw">Botswana</option>
                    <option value="bv">Bouvet Island</option>
                    <option value="io">British Indian Ocean Territory</option>
                    <option value="vg">British Virgin Islands</option>
                    <option value="bn">Brunei Darussalam</option>
                    <option value="bg">Bulgaria</option>
                    <option value="bf">Burkina Faso</option>
                    <option value="bi">Burundi</option>
                    <option value="kh">Cambodia</option>
                    <option value="cm">Cameroon</option>
                    <option value="cv">Cape Verde</option>
                    <option value="ky">Cayman Islands</option>
                    <option value="cf">Central African Republic</option>
                    <option value="td">Chad</option>
                    <option value="cl">Chile</option>
                    <option value="cx">Christmas Island</option>
                    <option value="cc">Cocos (Keeling) Islands</option>
                    <option value="co">Colombia</option>
                    <option value="km">Comoros</option>
                    <option value="ck">Cook Islands</option>
                    <option value="cr">Costa Rica</option>
                    <option value="ci">Côte d'Ivoire</option>
                    <option value="hr">Croatia</option>
                    <option value="cu">Cuba</option>
                    <option value="cw">Curaçao</option>
                    <option value="cy">Cyprus</option>
                    <option value="cz">Czech Republic</option>
                    <option value="cd">Democratic Republic of the Congo</option>
                    <option value="dk">Denmark</option>
                    <option value="dj">Djibouti</option>
                    <option value="dm">Dominica</option>
                    <option value="do">Dominican Republic</option>
                    <option value="tl">East Timor</option>
                    <option value="ec">Ecuador</option>
                    <option value="eg">Egypt</option>
                    <option value="sv">El Salvador</option>
                    <option value="gq">Equatorial Guinea</option>
                    <option value="er">Eritrea</option>
                    <option value="ee">Estonia</option>
                    <option value="et">Ethiopia</option>
                    <option value="fk">Falkland Islands</option>
                    <option value="fo">Faroe Islands</option>
                    <option value="fj">Fiji</option>
                    <option value="fi">Finland</option>
                    <option value="gf">French Guiana</option>
                    <option value="pf">French Polynesia</option>
                    <option value="tf">French Southern Lands</option>
                    <option value="ga">Gabon</option>
                    <option value="ge">Georgia</option>
                    <option value="gh">Ghana</option>
                    <option value="gi">Gibraltar</option>
                    <option value="gr">Greece</option>
                    <option value="gl">Greenland</option>
                    <option value="gd">Grenada</option>
                    <option value="gp">Guadeloupe</option>
                    <option value="gu">Guam</option>
                    <option value="gt">Guatemala</option>
                    <option value="gg">Guernsey</option>
                    <option value="gn">Guinea</option>
                    <option value="gw">Guinea-Bissau</option>
                    <option value="gy">Guyana</option>
                    <option value="ht">Haiti</option>
                    <option value="hm">Heard Island and MaxDonald Islands</option>
                    <option value="hn">Honduras</option>
                    <option value="hk">Hong Kong</option>
                    <option value="hu">Hungary</option>
                    <option value="is">Iceland</option>
                    <option value="id">Indonesia</option>
                    <option value="ir">Iran</option>
                    <option value="iq">Iraq</option>
                    <option value="ie">Ireland</option>
                    <option value="im">Isle of Man</option>
                    <option value="il">Israel</option>
                    <option value="jm">Jamaica</option>
                    <option value="je">Jersey</option>
                    <option value="jo">Jordan</option>
                    <option value="kz">Kazakhstan</option>
                    <option value="ke">Kenya</option>
                    <option value="ki">Kiribati</option>
                    <option value="xk">Kosovo</option>
                    <option value="kw">Kuwait</option>
                    <option value="kg">Kyrgyzstan</option>
                    <option value="la">Laos</option>
                    <option value="lv">Latvia</option>
                    <option value="lb">Lebanon</option>
                    <option value="ls">Lesotho</option>
                    <option value="lr">Liberia</option>
                    <option value="ly">Libya</option>
                    <option value="li">Liechtenstein</option>
                    <option value="lt">Lithuania</option>
                    <option value="lu">Luxembourg</option>
                    <option value="mo">Macao</option>
                    <option value="mk">Macedonia</option>
                    <option value="mg">Madagascar</option>
                    <option value="mw">Malawi</option>
                    <option value="my">Malaysia</option>
                    <option value="mv">Maldives</option>
                    <option value="ml">Mali</option>
                    <option value="mt">Malta</option>
                    <option value="mh">Marshall Islands</option>
                    <option value="mq">Martinique</option>
                    <option value="mr">Mauritania</option>
                    <option value="mu">Mauritius</option>
                    <option value="yt">Mayotte</option>
                    <option value="mx">Mexico</option>
                    <option value="fm">Micronesia</option>
                    <option value="md">Moldova</option>
                    <option value="mc">Monaco</option>
                    <option value="mn">Mongolia</option>
                    <option value="me">Montenegro</option>
                    <option value="ms">Montserrat</option>
                    <option value="ma">Morocco</option>
                    <option value="mz">Mozambique</option>
                    <option value="mm">Myanmar</option>
                    <option value="na">Namibia</option>
                    <option value="nr">Nauru</option>
                    <option value="np">Nepal</option>
                    <option value="an">Netherlands Antilles</option>
                    <option value="nc">New Caledonia</option>
                    <option value="nz">New Zealand</option>
                    <option value="ni">Nicaragua</option>
                    <option value="ne">Niger</option>
                    <option value="ng">Nigeria</option>
                    <option value="nu">Niue</option>
                    <option value="nf">Norfolk Island</option>
                    <option value="kp">North Korea</option>
                    <option value="mp">Northern Mariana Islands</option>
                    <option value="no">Norway</option>
                    <option value="om">Oman</option>
                    <option value="pk">Pakistan</option>
                    <option value="pw">Palau</option>
                    <option value="ps">Palestinian Territory</option>
                    <option value="pa">Panama</option>
                    <option value="pg">Papua New Guinea</option>
                    <option value="py">Paraguay</option>
                    <option value="pe">Peru</option>
                    <option value="ph">Philippines</option>
                    <option value="pn">Pitcairn</option>
                    <option value="pl">Poland</option>
                    <option value="pt">Portugal</option>
                    <option value="pr">Puerto Rico</option>
                    <option value="qa">Qatar</option>
                    <option value="cg">Republic of the Congo</option>
                    <option value="re">Réunion</option>
                    <option value="ro">Romania</option>
                    <option value="ru">Russia</option>
                    <option value="rw">Rwanda</option>
                    <option value="bl">Saint Barthélemy</option>
                    <option value="sh">Saint Helena</option>
                    <option value="kn">Saint Kitts and Nevis</option>
                    <option value="lc">Saint Lucia</option>
                    <option value="mf">Saint Martin</option>
                    <option value="pm">Saint Pierre and Miquelon</option>
                    <option value="vc">Saint Vincent and the Grenadines</option>
                    <option value="ws">Samoa</option>
                    <option value="sm">San Marino</option>
                    <option value="st">São Tomé and Príncipe</option>
                    <option value="sa">Saudi Arabia</option>
                    <option value="sn">Senegal</option>
                    <option value="rs">Serbia</option>
                    <option value="sc">Seychelles</option>
                    <option value="sl">Sierra Leone</option>
                    <option value="sg">Singapore</option>
                    <option value="sx">Sint Maarten</option>
                    <option value="sk">Slovakia</option>
                    <option value="si">Slovenia</option>
                    <option value="sb">Solomon Islands</option>
                    <option value="so">Somalia</option>
                    <option value="za">South Africa</option>
                    <option value="gs">South Georgia and South Sandwich Islands</option>
                    <option value="kr">South Korea</option>
                    <option value="ss">South Sudan</option>
                    <option value="es">Spain</option>
                    <option value="lk">Sri Lanka</option>
                    <option value="sd">Sudan</option>
                    <option value="sr">Suriname</option>
                    <option value="sj">Svalbard and Jan Mayen</option>
                    <option value="sz">Swaziland</option>
                    <option value="se">Sweden</option>
                    <option value="ch">Switzerland</option>
                    <option value="sy">Syria</option>
                    <option value="tw">Taiwan</option>
                    <option value="tj">Tajikistan</option>
                    <option value="tz">Tanzania</option>
                    <option value="th">Thailand</option>
                    <option value="gm">The Gambia</option>
                    <option value="nl">The Netherlands</option>
                    <option value="tg">Togo</option>
                    <option value="tk">Tokelau</option>
                    <option value="to">Tonga</option>
                    <option value="tt">Trinidad and Tobago</option>
                    <option value="tn">Tunisia</option>
                    <option value="tr">Turkey</option>
                    <option value="tm">Turkmenistan</option>
                    <option value="tc">Turks and Caicos Islands</option>
                    <option value="tv">Tuvalu</option>
                    <option value="ug">Uganda</option>
                    <option value="ua">Ukraine</option>
                    <option value="ae">United Arab Emirates</option>
                    <option value="um">United States Minor Outlying Islands</option>
                    <option value="vi">United States Virgin Islands</option>
                    <option value="uy">Uruguay</option>
                    <option value="uz">Uzbekistan</option>
                    <option value="vu">Vanuatu</option>
                    <option value="va">Vatican City</option>
                    <option value="ve">Venezuela</option>
                    <option value="vn">Vietnam</option>
                    <option value="wf">Wallis and Futuna Islands</option>
                    <option value="eh">Western Sahara</option>
                    <option value="ye">Yemen</option>
                    <option value="zm">Zambia</option>
                    <option value="zw">Zimbabwe</option>
                </select>
            </div>
            <div class="geocoding-row ">
                <span>Max Return Count</span>
                <input type="number" id="count-limit" value="5" min="1" max="10">
            </div>
        </div>

        <div id="searchBar">
            <div id="geocoder">
                <i></i>
                <input type="search" id="address" autocomplete="off" placeholder="Search...">
                <div class="result-wrap">
                    <ul id="geocoderResult">
                    </ul>
                    <div class="loading hidden">
                        <img src="https://samples.thinkgeo.com/cloud/example/image/Spinner-1s-50px.gif" alt="loading">
                    </div>
                </div>
            </div>
        </div>

        <!-- Set up error message tip. -->
        <div id="error-modal" class="hide">
            <div class="modal-content">
                <p>We're having trouble communicating with the ThinkGeo Cloud. Please check the API key being used in
                    this sample's
                    JavaScript source code, and ensure it has access to the ThinkGeo Cloud services you are requesting.
                    You
                    can create and manage your API keys at
                    <a href="https://cloud.thinkgeo.com" target="_blank" rel="noopener">https://cloud.thinkgeo.com</a>.
                </p>
                <button>OK</button>
            </div>
        </div>
    </div>
    <!-- This <div> is the container into which our popup panel will be rendered. -->
    <div id="popup" class="ol-popup hidden">
        <a href="#" id="popup-closer" class="ol-popup-closer"></a>
        <div id="popup-content">
        </div>
        <div class="icon">
            <img src="https://samples.thinkgeo.com/cloud/example/image/point.png" alt="Marker">
        </div>
    </div>
</body>
</html>
            
          
!
            
              body {
  margin: 0;
  position: relative;
  font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

#map {
  width: 100%;
  height: 100%;
}

.ol-full-screen {
  bottom: 7.5em;
  right: 0.5em;
  top: unset;
}

.ol-zoom {
  bottom: 2.5em;
  right: 0.5em;
  top: unset;
  left: unset;
}

.ol-zoom button {
  width: 1.2em !important;
  height: 1.2em !important;
}

.ol-control button {
  height: 1.2em !important;
  width: 1.2em !important;
  border: solid 1px #ccc;
  font-size: 1.5em !important;
  background-color: #fff !important;
  color: #2d3c4d;
  cursor: pointer;
  border-radius: 2px;
}

.ol-control button:focus {
  outline: unset;
}

.ol-popup {
  position: absolute;
  background-color: white;
  -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  padding: 15px;
  border-radius: 10px;
  border: 1px solid #cccccc;
  bottom: 55px;
  left: -50px;
  min-width: 310px;
  z-index: 1001;
}

.ol-popup:after,
.ol-popup:before {
  top: 100%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.ol-popup:after {
  border-top-color: white;
  border-width: 10px;
  left: 48px;
  margin-left: -10px;
}

.ol-popup:before {
  border-top-color: #cccccc;
  border-width: 11px;
  left: 48px;
  margin-left: -11px;
}

.ol-popup-closer {
  text-decoration: none;
  position: absolute;
  top: 2px;
  right: 8px;
}

.ol-popup-closer:after {
  content: "✖";
}

#searchBar {
  top: 20px;
  position: absolute;
  width: 50%;
  left: 25%;
  max-width: none;
  z-index: 1000;
}

#geocoder {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  border-radius: 3px;
  background: #fff;
  width: 100%;
  display: inline-block;
}

#geocoder i {
  width: 20px;
  height: 20px;
  background: url(https://samples.thinkgeo.com/cloud/example/image/seach.png);
  z-index: 1000;
  position: absolute;
  top: 10px;
  left: 10px;
}

#geocoder input {
  display: inline-block;
  font: 15px/20px sans-serif;
  margin: 0;
  color: rgba(0, 0, 0, .6);
  padding: 10px 35px;
  -webkit-appearance: none;
  border: 0px solid;
  width: 100%;
  border-radius: 3px;
}

#geocoder input:focus {
  outline: none;
}

.result-wrap {
  position: relative;
}

.loading {
  position: absolute;
  top: 17%;
  left: 45%;
}

#geocoderResult {
  list-style: none;
  padding: 0;
  margin: 0;
}

#geocoderResult li {
  border-top: 1px solid rgba(0, 0, 0, 0.10);
}

#geocoderResult li a {
  padding: 5px 15px;
  display: inline-block;
  width: 100%;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: 0;
  color: #3887BE;
  cursor: pointer;
}

#geocoderResult li a:hover {
  color: #63b6e5
}

#popup-content p,
h4,
h5 {
  margin-top: 5px;
  margin-bottom: 5px;
}

#popup-content .address {
  font-size: 0.8rem;
}

#popup-content .coodinates {
  font-size: 0.8rem;
  color: #8a8a8a;
}

.icon {
  position: absolute;
  bottom: -62px;
  left: 36px;
}

.hidden {
  display: none;
}

.focus {
  font-weight: 600;
}

.geocodingPanel {
  position: absolute;
  left: 1em;
  top: 1em;
  width: 290px;
  z-index: 4;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.62);
  border-color: #666 !important;
  border-radius: 3px;
  background-color: rgba(0, 0, 0, .75) !important;
  padding: 10px;
  color: white;
}

.geocoding-row {
  margin-top: 10px;
  display: inline-block;
  width: 100%;
  padding-bottom: 5px;
  border-bottom: solid 1px rgba(109, 108, 108, 0.314) !important;
}

.geocodingPanel h5 {
  margin-top: 0.1rem;
  margin-bottom: 0.1rem;
  color: white;
}

.geocoding-row button:focus {
  outline: unset;
}

.location-type-button {
  background-color: transparent;
  color: white;
  padding: 5px 8px;
  border-style: double;
  border-width: thin;
  cursor: pointer;
}

.location-type-button.selected {
  background-color: #3089ff;
}

.geocoding-row span,
label,
input[type=select] {
  font-size: 0.83rem;
  color: #eee;
  display: inline-block;
  margin-bottom: 5px;
}

.geocoding-row select,
input[type=number] {
  float: right;
  width: 127px;
}

#count-limit {
  width: 123px;
}

#autocomplete {
  margin-left: 77px;
}

#boundingbox {
  width: 286px;
  margin-top: 5px;
}

#error-message {
  position: absolute;
  top: -150px;
  left: 50%;
  width: auto;
  min-width: 300px;
  margin-left: auto;
  text-align: center;
  transform: translate(-50%, 0);
  transition: top 0.6s;
}

#error-message.show {
  top: 15px;
  transition: top 0.6s;
}

#error-message p {
  line-height: 40px;
  padding-left: 10px;
  padding-right: 10px;
  border-radius: 3px;
  border-color: #f5c6cb;
  background-color: #f8d7da;
  color: #721c24;
}

#error-modal {
  position: fixed;
  top: 0;
  height: 100%;
  width: 100%;
  z-index: 99;
  background-color: #0000006e;
}

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: auto;
  text-align: right;
  padding: 10px;
  border-radius: 5px;
  font-size: 1.1rem;
  line-height: 1.5;
  background-color: #f0f0f0;
  border: 1px solid #b8b8b8;
}

.modal-content p {
  text-align: left;
}

.modal-content button {
  color: #fff;
  background-color: #3d3d3e;
  border-color: #3d3d3e;
  border-radius: 4px;
  padding: 0 7px;
  height: 30px;
  width: 60px;
  cursor: pointer;
  margin-right: 20px;
}

.hide {
  display: none;
}
@media (max-width: 1380px) {
  #searchBar{
    left: 340px;
  }
}

@media (max-height: 400px) and (orientation: landscape) {
  .modal-content {
    width: 80vw;
  }

  .geocodingPanel {
    display: none;
  }

  #searchBar {
    width: 100%;
    left: 0;
    top: 0%;
  }

  button.ol-full-screen-false {
    display: none;
  }
}

@media (max-width: 767px) {
  .modal-content {
    width: 80vw;
  }

  .geocodingPanel {
    display: none;
  }

  .ol-control button {
    font-family: initial;
    line-height: 1.2em;
  }

  #searchBar {
    width: 100%;
    left: 0;
    top: 0%;
  }

  button.ol-full-screen-false {
    display: none;
  }
}
            
          
!
            
              /*===========================================================================*/
// Geocoding
// Sample map by ThinkGeo
// 
//   1. ThinkGeo Cloud API Key
//   2. Map Control Setup
//   3. Popup Setup
//   4. Geocoder Setup
//   5. Event Listeners
//   6. Tile Loading Event Handlers
/*===========================================================================*/


/*---------------------------------------------*/
// 1. ThinkGeo Cloud API Key
/*---------------------------------------------*/

// First, let's define our ThinkGeo Cloud API key, which we'll use to
// authenticate our requests to the ThinkGeo Cloud API.  Each API key can be
// restricted for use only from a given web domain or IP address.  To create your
// own API key, you'll need to sign up for a ThinkGeo Cloud account at
// https://cloud.thinkgeo.com.
const apiKey = 'WPLmkj3P39OPectosnM1jRgDixwlti71l8KYxyfP2P0~';

/*---------------------------------------------*/
// 2. Map Control Setup
/*---------------------------------------------*/

// Now we'll create the base layer for our map.  The base layer uses the ThinkGeo
// Cloud Maps Raster Tile service to display a detailed street map.  For more
// info, see our wiki:
// https://wiki.thinkgeo.com/wiki/thinkgeo_cloud_maps_raster_tiles
let baseLayer = new ol.mapsuite.VectorTileLayer('https://cdn.thinkgeo.com/worldstreets-styles/3.0.0/dark.json', {
    apiKey: apiKey,
    layerName: 'dark'
});

// Create a default view for the map when it starts up.
let view = new ol.View({
    // Center the map on the United States and start at zoom level 3.
    center: ol.proj.fromLonLat([-96.79620, 32.79423]),
    maxResolution: 40075016.68557849 / 512,
    zoom: 3,
    minZoom: 2,
    maxZoom: 19
})

let map;
let geocodingLayer;
let initializeMap = () => {

    // Create and initialize our interactive map.
    map = new ol.Map({
        renderer: 'webgl',
        // Add our previously-defined ThinkGeo Cloud Raster Tile layer to the map.
        layers: [baseLayer],
        // States that the HTML tag with id="map" should serve as the container for our map.
        target: 'map',
        loadTilesWhileAnimating: true,
        loadTilesWhileInteracting: true,
        // Add a default view for the map when it starts up.
        view: view
    });


    // The next part sets up the style for the geocoder layer.
    let styles = {
        boundingBox: new ol.style.Style({
            stroke: new ol.style.Stroke({
                color: [0, 0, 255, 0.5],
                width: 1
            }),
            fill: new ol.style.Fill({
                color: [0, 0, 255, 0.1]
            })
        }),
    }

    // Create the geocoder layer and use the pre-defined style for our geocoding layer and add it to map.
    geocodingLayer = new ol.layer.Vector({
        source: new ol.source.Vector({
            features: []
        }),
        style: function () {
            let style = styles['boundingBox'];
            return style;
        }
    });
    map.addLayer(geocodingLayer);

    // Add a button to the map that lets us toggle full-screen display mode.
    map.addControl(new ol.control.FullScreen());

    map.on("click", function (e) {
        var resultDiv = document.getElementById('geocoderResult');
        if (resultDiv) {
            resultDiv.innerText = ""
            focusIndex = -1;
        }
    })
}

WebFont.load({
    custom: {
        families: ["vectormap-icons"],
        urls: ["https://cdn.thinkgeo.com/vectormap-icons/2.0.0/vectormap-icons.css"],
        testStrings: {
            'vectormap-icons': '\ue001'
        }
    },
    // The "active" property defines a function to call when the font has
    // finished downloading.  Here, we'll call our initializeMap method.
    active: initializeMap
});

/*---------------------------------------------*/
// 3. Popup Setup
/*---------------------------------------------*/

// Now, we need to create the popup container for our location information. We'll create an 
// overlay which servers the popup container, and add it to our map. This popup panel will 
// show the place name and the map will pan to the address.
const container = document.getElementById('popup');
container.classList.remove('hidden');
const content = document.getElementById('popup-content');
const closer = document.getElementById('popup-closer');

// Create the popup overlay.
let overlay = new ol.Overlay({
    element: container,
    autoPan: false,
});

// Add an event listener to the close icon located in the top right corner of the popup. 
// When click the 'x' icon, the popup box and geocoder layer will disappear.
closer.onclick = () => {
    overlay.setPosition(undefined);
    let source = geocodingLayer.getSource();
    source.clear();
    closer.blur();
    return false;
};

// When calling this method, we'll add the popup panel to map and show the address info in the box.
const addPopup = (tile, coordinates, address, label) => {
    overlay.setPosition(ol.proj.fromLonLat(coordinates));
    map.addOverlay(overlay);
    if (label) {
        content.innerHTML = `<h4>${tile}</h4><p class="address">${address}</p><p class="coodinates">${coordinates[1]},${coordinates[0]} (${label})</p>`
    }
    else {
        content.innerHTML = `<h4>${tile}</h4><p class="address">${address}</p><p class="coodinates">${coordinates[1]},${coordinates[0]}</p>`
    }
}


/*---------------------------------------------*/
// 4. Geocoder Setup
/*---------------------------------------------*/

// Let's add a list of addresses that will let users visualize the location of what you searched. Every time you 
// input the address name in the top inptut form, it'll send request to get the relavant places and show you 
// in a list. You can enter the up button and down button to choose the place you want to perfom Geocode.

// We use thinkgeocloudclient.js, which is an open-source Javascript SDK for making 
// request to ThinkGeo Cloud Service. It simplifies the process of the code of request.

// We need to create the instance of Geocoder client and authenticate the API key.
let geocodingClient = new tg.GeocodingClient(apiKey);
let results;
let resultsLength;
let geocoderResultNode = document.getElementById('geocoderResult');

// This method will receive the result addresses from ThinkGeo Cloud, and render these addresses to the list. At 
// the same time, it will get some usefull info and write them as the property of DOM element <a>. These information 
// will be used when we add the geocoder layer to our map later.
const renderResult = (locations) => {
    document.querySelector('.loading').classList.add('hidden');
    if (locations.length > 0) {
        resultsLength = locations.length;
        let str = '';
        let i = -1
        for (let item of locations) {
            i = i + 1;
            str += `<li><a   data-index=${i} > ${item.address} </a></li>`
        }
        geocoderResultNode.innerHTML = str;
    } else {
        geocoderResultNode.innerHTML = ''
    }
    results = locations;
}

// This method actually performs the Geocoder request. It uses our ThinkGeo Cloud Services to get back the addresses 
// related to your input address. It will return a collection of addresses that the number will less than 5, while 
// the MaxResults parameter is 5.
const geocoder = (val) => {
    document.querySelector('.loading').classList.remove('hidden');
    let opts = getGeocodingOptions();
    const callback = (status, res) => {
        focusIndex = -1;
        if (status !== 200) {
            errorLoadingTile();
        } else {
            let locations = res.data.locations;
            renderResult(locations);
        }
    };
    if (geocodingClient.xhr) {
        geocodingClient.xhr.abort();
        delete geocodingClient.xhr;
    }
    geocodingClient.on("sendingrequest", function (e) {
        this.xhr = e.xhr;
    })
    // Call the searchByPoint API to search the points by the input address.
    geocodingClient.searchByPoint(val, callback, opts);
    geocodingClient.un("sendingrequest")
}

const getGeocodingOptions = () => {
    // Get selected location types.
    var locationTypes = [];
    var selectedButtons = document.getElementsByClassName("selected");
    for (var i = 0; i < selectedButtons.length; i++) {
        locationTypes.push(selectedButtons[i].value);
    }
    // Get country code
    var countryCode = document.querySelector('#country-filter').value;
    // Get MaxResults
    var countLimit = document.querySelector('#count-limit').value;
    // Get Autocomplete
    var autocomplete = true;

    let opts = {
        LocationType: locationTypes.join(","),
        Countries: countryCode,
        MaxResults: countLimit,
        Autocomplete: autocomplete,
        // Defaults as true for VerboseResults to display geometry of Results
        VerboseResults: true
    };

    return opts;
}

// This method will create the address feature where you select, and add it to geocodingLayer which we create earlier.
// If the address is a street, slide the map over to the center point what we get back, otherwise, create a bounding box 
// polygon feature and add it to geocodinglayer. Fit the given geometry or extent based on the given boundingBox.
const renderMatchedPlacePolygon = (coordinatesX, coordinatesY, boundingBox, type, geometry) => {
    let source = geocodingLayer.getSource();
    source.clear();
    if (type === 'Street') {
        view.animate({
            center: ol.proj.fromLonLat([parseFloat(coordinatesX), parseFloat(coordinatesY)]),
            zoom: 18,
            duration: 0
        });
    } else {
        let format = new ol.format.WKT();
        let wktFeature = format.readFeature(geometry, {
            dataProjection: 'EPSG:4326',
            featureProjection: 'EPSG:3857'
        });
        geocodingLayer.getSource().addFeature(wktFeature);
        wktFeature.set('type', 'boundingBox');
        view.fit(wktFeature.getGeometry(), {
            padding: [20, 20, 20, 20]
        })
    }
}


/*---------------------------------------------*/
// 5. Event Listeners
/*---------------------------------------------*/

// These event listeners tell the UI when it's time to execute all of the 
// code we've written.

// This method will receive the index number of which address you select, and get the 
// value we need from the element property. By passing them to renderMatchedPlacePolygon 
// and addPopup method to perform Geocoder and show the popup info panel.
let focusIndex = -1;

const searchPlace = (focusIndex) => {
    if (focusIndex < 0) { return; }
    let geometry;
    let displayTitle;
    let displayAddress;
    let displayLabel;
    let coordinates;
    let boundingBox;
    let type;
    if (results) {
        let targetResult = results[focusIndex];
        if (targetResult) {
            // Geometry
            geometry = targetResult["geometry"];

            // coordinates
            var locationPoint = targetResult.locationPoint;
            coordinates = [parseFloat(locationPoint.pointX.toFixed(6)), parseFloat(locationPoint.pointY.toFixed(6))];


            // displayName and displayAddress
            var locationAddress = targetResult.address;
            var name = targetResult.name;
            var houseNumber = targetResult.addressComponents["housenumber"];
            var roadName = targetResult.addressComponents["street"];
            var titleArray = [];
            if (name) {
                titleArray.push(name);
            }

            var tmpRoad = "";
            if (houseNumber) {
                tmpRoad = tmpRoad + houseNumber + " ";
            }
            if (roadName) {
                tmpRoad = tmpRoad + roadName;
            }
            if (tmpRoad != "") {
                titleArray.push(tmpRoad);
            }
            displayTitle = titleArray.join(", ");

            if (displayTitle != "" && locationAddress.startsWith(displayTitle)) {
                displayAddress = locationAddress.substring(displayTitle.length + 2);
            }
            else {
                displayAddress = locationAddress;
            }

            // displayLabel
            if (targetResult.properties) {
                displayLabel = targetResult.properties.label;
            }

            // boundingBox
            boundingBox = targetResult.boundingBox;
            // type 
            type = targetResult.type;
        }
    }

    renderMatchedPlacePolygon(coordinates[0], coordinates[1], boundingBox, type, geometry);
    addPopup(displayTitle, coordinates, displayAddress, displayLabel);
}

// Control the selected item UI.
const computedHighlitIndex = (dir) => {
    let geocoderResult = document.querySelector('#geocoderResult');
    if (geocoderResult.querySelector('.focus')) {
        geocoderResult.querySelector('.focus').classList.remove('focus');
    }

    if (focusIndex < 0) { return; }

    var selectedData = geocoderResult.querySelectorAll('a[data-index]')[focusIndex];
    if (selectedData != undefined) {
        selectedData.classList.add('focus');
    }
}

document.addEventListener('DOMContentLoaded', () => {
    // Every time you input word into the input box, the value in it will be passed to 
    // geocoder method and perform the Geocoder services.
    let timer = null;
    let address = document.getElementById('address');

    address.addEventListener('click', () => {
        if ((navigator.userAgent.match(/(iOS|Android|iPhone)/i))) {
            document.querySelector(".ol-unselectable").style.display = 'none';
            document.querySelector("#geocoderResult").style.display = 'block';
            var popup = document.querySelector("#popup");
            if (popup != undefined) {
                popup.style.display = 'none'
            }
        } else if (document.querySelector(".ol-unselectable").style.display = 'none') {
            document.querySelector(".ol-unselectable").style.display = 'block';
        }
    });

    address.addEventListener('blur', () => {
        if ((navigator.userAgent.match(/(iOS|Android|iPhone)/i))) {
            document.querySelector(".ol-unselectable").style.display = 'block';
        }
    });

    address.addEventListener('input', () => {
        geocoderResult.se
        clearTimeout(timer);
        timer = setTimeout(() => {
            overlay.setPosition(undefined);
            let source = geocodingLayer.getSource();
            source.clear();
            let value = address.value;
            focusIndex = -1;
            if (value) {
                document.querySelector('.loading').classList.remove('hidden');
                geocoder(value);
            } else {
                geocoderResultNode.innerHTML = ''
            }
        }, 350);
    });

    // When you click the specific address, it'll perform Geocoder.
    document.getElementById('geocoderResult').addEventListener('click', (e) => {
        e = window.event || e;
        let target = e.target;
        if (target.nodeName == 'A') {
            focusIndex = Number(target.getAttribute('data-index'));
            computedHighlitIndex(focusIndex);
            searchPlace(focusIndex);
        }
        if ((navigator.userAgent.match(/(pad|iPad|iOS|Android|iPhone)/i))) {
            document.querySelector(".ol-unselectable").style.display = 'block';
            document.querySelector("#geocoderResult").style.display = 'none';
            var popup = document.querySelector("#popup");
            if (popup != undefined) {
                popup.style.display = 'block'
            }
        }
    });

    // Everytime inputing the address, the ThinkGeo Cloud will return the relative 
    // address list and we'll show them below the input box. You can enter the up button 
    // and down button to choose the place. 
    document.body.addEventListener('keydown', (e) => {
        e = window.event || e;
        switch (e.keyCode) {
            case 38:
                // Up
                e.preventDefault();
                focusIndex -= 1;
                if (focusIndex === -1) {
                    focusIndex = resultsLength - 1;
                }
                computedHighlitIndex(focusIndex);
                searchPlace(focusIndex);

                if ((navigator.userAgent.match(/(pad|iPad|iOS|Android|iPhone)/i))) {
                    document.querySelector(".ol-unselectable").style.display = 'block';
                    document.querySelector("#geocoderResult").style.display = 'none';
                    var popup = document.querySelector("#popup");
                    if (popup != undefined) {
                        popup.style.display = 'block'
                    }
                }
                break;
            case 40:
                // Down
                e.preventDefault();
                focusIndex += 1;
                if (focusIndex === resultsLength) {
                    focusIndex = 0;
                }
                computedHighlitIndex(focusIndex);
                searchPlace(focusIndex);

                if ((navigator.userAgent.match(/(pad|iPad|iOS|Android|iPhone)/i))) {
                    document.querySelector(".ol-unselectable").style.display = 'block';
                    document.querySelector("#geocoderResult").style.display = 'none';
                    var popup = document.querySelector("#popup");
                    if (popup != undefined) {
                        popup.style.display = 'block'
                    }
                }
                break;
            case 13:
                // Enter
                if (focusIndex !== -1) {
                    searchPlace(focusIndex);
                } else {
                    focusIndex = -1;
                    let value = document.getElementById('address').value;
                    geocoder(value);
                }

                if ((navigator.userAgent.match(/(pad|iPad|iOS|Android|iPhone)/i))) {
                    document.querySelector(".ol-unselectable").style.display = 'block';
                    document.querySelector("#geocoderResult").style.display = 'none';
                    var popup = document.querySelector("#popup");
                    if (popup != undefined) {
                        popup.style.display = 'block'
                    }
                }
                break;
            default:
                if ((navigator.userAgent.match(/(pad|iPad|iOS|Android|iPhone)/i))) {
                    document.querySelector("#geocoderResult").style.display = 'block';
                }
        }
    })
})

var searchProcess = function () {
    let address = document.getElementById('address');
    overlay.setPosition(undefined);
    let source = geocodingLayer.getSource();
    source.clear();
    focusIndex = -1;
    let value = address.value;
    if (value) {
        document.querySelector('.loading').classList.remove('hidden');
        geocoder(value);
    } else {
        geocoderResultNode.innerHTML = ''
    }
}

// selected locationtype changed
var locationTypeButtons = document.getElementsByClassName("location-type-button");
var locationTypeChanged = function (e) {
    if (this.classList.contains("selected")) {
        this.classList.remove("selected");
    }
    else {
        this.classList.add("selected");
    }
    searchProcess();
}
for (var i = 0; i < locationTypeButtons.length; i++) {
    locationTypeButtons[i].addEventListener("click", locationTypeChanged)
}

// Country Changed
var countryCodeSelect = document.getElementById("country-filter");
countryCodeSelect.addEventListener("change", searchProcess);

// Max Result Changed
var maxResult = document.getElementById("count-limit");
maxResult.addEventListener("change", searchProcess);

/*---------------------------------------------*/
// 6. Tile Loading Event Handlers
/*---------------------------------------------*/

// These events allow you to perform custom actions when 
// a map tile encounters an error while loading.
const errorLoadingTile = () => {
    const errorModal = document.querySelector('#error-modal');
    if (errorModal.classList.contains('hide')) {
        // Show the error tips when Tile loaded error.
        errorModal.classList.remove('hide');
    }
}

const setLayerSourceEventHandlers = (layer) => {
    let layerSource = layer.getSource();
    layerSource.on('tileloaderror', function () {
        errorLoadingTile();
    });
}

setLayerSourceEventHandlers(baseLayer);

document.querySelector('#error-modal button').addEventListener('click', () => {
    document.querySelector('#error-modal').classList.add('hide');
})

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console