Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                
  <div id="landno-panel" class="container mainnav">
    <div class="row">
      <div class="col-lg-offset-3 col-md-offset-3 col-lg-6 col-md-6 col-sm-6">
        <div class="panel panel-primary">
          <div class="panel-heading">
            <h3 class="panel-title">地號轉地圖</h3>
          </div>
          <div class="panel-body">
            <form class="form-horizontal">
              <fieldset>
                <label for="textArea" class="col-lg-3 control-label">輸入地號:</label>
                <div class="col-lg-9">
                  <textarea class="form-control js_landno" rows="10"></textarea>
                </div>

                <div class="col-lg-9 col-lg-offset-3">
                  <button class="btn btn-primary js_generate_map">
                    產生地圖
                  </button>
                </div>
              </fieldset>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div id="map-canvas"></div>
              
            
!

CSS

              
                html,body {
  width: 100%;
}

#map-canvas {
  width: 100%;
  height: 600px;
}
              
            
!

JS

              
                (function(root, factory){
  "use strict";
  if (typeof define === "function" && define.amd) {
    define(["jquery", "google"], factory);
  } else if (typeof exports === "object") {
    module.exports = factory(require("jquery", "google"));
  } else {
    root.Mapper = factory(root.jQuery, root.google);
  }
})(this, function($, google) {
	'use strict';

	var exports = {
		map_object: null,
		map_id: 'map-canvas',
		api_url: 'http://twland.ronny.tw/index/search'
	};

	exports.getAPIUrl = function(query) {
		if (Object.keys(query).length > 0){
			return exports.api_url + '?' + $.param(query);
		}

		return exports.api_url;
	};

	exports.page = {
		init: function() {
			// TODO : add event listener
			$('.js_generate_map').click(function(event) {
				event.preventDefault();
				var landno_str = $('.js_landno').val();
				var landno_list = landno_str.split('\n');

				exports.map.show(landno_list);
			});
		}
	};

	exports.map = {
		init: function(options) {
			var map_options = $.extend({
				zoom: 15,
				scrollwheel: false
			}, options);

			var map_element = document.getElementById(exports.map_id);
			exports.map_object = new google.maps.Map(map_element, map_options);
		},

		show: function(landno_list) {
			if (exports.map_object == null) {
				exports.map.init();
			}

			landno_list = $.isArray(landno_list) ? landno_list : [landno_list];
			var query = { lands: landno_list };
			var json_url = exports.getAPIUrl(query);

			$.getJSON(json_url, function(geo_json){
				if (! $.isEmptyObject(geo_json)){
					var center = {
						lat: -1, 
						lng: -1
					};

					var features = geo_json.features;

					features.forEach(function(feature){
						exports.map_object.data.addGeoJson(feature);

						var lat = feature.properties.ycenter;
						var lng = feature.properties.xcenter;

						if (lat >0 && lng > 0) {
							center.lat = lat;
							center.lng = lng;
						}

					});
		 			// TODO : reset the map center
	 				exports.map_object.setCenter(new google.maps.LatLng(center.lat, center.lng));
				}
			});
		}
	};

	exports.init = function() {
		exports.page.init();
	};

	exports.init();

	return exports;
});
              
            
!
999px

Console