Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
- <meta charset="UTF-8">
- <title>Test</title>
- <script type="text/javascript"
- src="http://maps.google.com/maps/api/js?sensor=false&libraries=drawing,places"></script>
- <style type="text/css">
- #map, html, body {
- padding: 0;
- margin: 0;
- width: 100%;
- height: 100%;
- }
- #geoinfoboxes {
- //display: none;
- }
- #delete-button {
- position: absolute;
- margin-top: 5px;
- right: 0.5%;
- z-index: 5;
- text-align: center;
- border: none;
- border-radius: 30px 30px 30px 30px;
- font-family: 'Roboto','sans-serif';
- font-size: 100;
- //line-height: 40px;
- width: 200px;
- height: 35px;
- }
- #center-palette {
- position: absolute;
- //top: 1.5%;
- //left: 53.5%;
- z-index: 5;
- //padding: 5px;
- //text-align: center;
- //font-family: 'Roboto','sans-serif';
- //line-height: 30px;
- //padding-left: 10px;
- }
- #color-palette {
- clear: both;
- }
- .color-button {
- border-radius: 30px 30px 30px 30px;
- position: relative;
- width: 14px;
- height: 14px;
- font-size: 0;
- float: right;
- margin-top: 10px;
- cursor: pointer;
- }
- .controls {
- border: 1px solid transparent;
- border-radius: 30px 30px 30px 30px;
- box-sizing: border-box;
- -moz-box-sizing: border-box;
- height: 32px;
- outline: none;
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
- margin-top: 5px;
- }
- #pac-input {
- background-color: #fff;
- font-family: Roboto;
- font-size: 15px;
- font-weight: 300;
- margin-left: 12px;
- padding: 0 11px 0 13px;
- text-overflow: ellipsis;
- width: 400px;
- }
- #pac-input:focus {
- border-color: #4d90fe;
- }
- .pac-container {
- font-family: Roboto;
- }
- #type-selector {
- color: #fff;
- //background-color: #4d90fe;
- background-color: #FF4400;
- padding: 5px 11px 0px 11px;
- }
- #type-selector label {
- font-family: Roboto;
- font-size: 13px;
- font-weight: 300;
- }
- </style>
- <script type="text/javascript">
- /////////////////////////////////////////////////////////////
- //Map Specifications
- function initialize () {
- var map = new google.maps.Map(document.getElementById('map'), {
- zoom: 18,
- center: new google.maps.LatLng(33.27144940863937, -117.2983479390361),
- mapTypeId: google.maps.MapTypeId.HYBRID,
- disableDefaultUI: true,
- zoomControl: true,
- mapTypeControl: false,
- scaleControl: true,
- streetViewControl: true,
- rotateControl: true,
- fullscreenControl: false
- });
- var polyOptions = {
- strokeWeight: 0,
- fillOpacity: 0.45,
- editable: true,
- draggable: false
- };
- // Creates a drawing manager attached to the map that allows the user to draw
- // markers, lines, and shapes.
- drawingManager = new google.maps.drawing.DrawingManager({
- drawingControlOptions: {
- position: google.maps.ControlPosition.TOP_CENTER,
- drawingModes: [
- google.maps.drawing.OverlayType.POLYLINE,
- google.maps.drawing.OverlayType.POLYGON
- ]
- },
- markerOptions: {
- draggable: false
- },
- polylineOptions: {
- editable: true,
- draggable: false
- },
- //rectangleOptions: polyOptions,
- polygonOptions: polyOptions,
- map: map
- });
- ////////////////////////////////////////////////////////////////////////////////
- var drawingManager;
- var selectedShape;
- var colors = ['#1E90FF', '#FF1493', '#32CD32', '#FF8C00', '#4B0082'];
- var selectedColor;
- var colorButtons = {};
- function clearSelection () {
- if (selectedShape) {
- if (selectedShape.type !== 'marker') {
- selectedShape.setEditable(false);
- }
- selectedShape = null;
- }
- }
- function setSelection (shape) {
- if (shape.type !== 'marker') {
- clearSelection();
- shape.setEditable(true);
- selectColor(shape.get('fillColor') || shape.get('strokeColor'));
- }
- selectedShape = shape;
- }
- function deleteSelectedShape () {
- if (selectedShape) { selectedShape.setMap(null);}
- if (selectedShape.type == 'polygon') {
- document.getElementById("action_gon").value = ''
- document.getElementById("info").value = 'This box shows coords when a new POLYGON shape is added and/or vertex deleted'
- }
- else if (selectedShape.type == 'polyline') {
- document.getElementById("action_line").value = 'This box shows coords when a new POLYLINE shape is added and/or vertex deleted'
- }
- }
- function selectColor (color) {
- selectedColor = color;
- for (var i = 0; i < colors.length; ++i) {
- var currColor = colors[i];
- colorButtons[currColor].style.border = currColor == color ? '2px solid #789' : '2px solid #fff';
- }
- // Retrieves the current options from the drawing manager and replaces the
- // stroke or fill color as appropriate.
- var polylineOptions = drawingManager.get('polylineOptions');
- polylineOptions.strokeColor = color;
- drawingManager.set('polylineOptions', polylineOptions);
- //var rectangleOptions = drawingManager.get('rectangleOptions');
- //rectangleOptions.fillColor = color;
- //drawingManager.set('rectangleOptions', rectangleOptions);
- //var circleOptions = drawingManager.get('circleOptions');
- //circleOptions.fillColor = color;
- //drawingManager.set('circleOptions', circleOptions);
- var polygonOptions = drawingManager.get('polygonOptions');
- polygonOptions.fillColor = color;
- drawingManager.set('polygonOptions', polygonOptions);
- }
- function setSelectedShapeColor (color) {
- if (selectedShape) {
- if (selectedShape.type == google.maps.drawing.OverlayType.POLYLINE) {
- selectedShape.set('strokeColor', color);
- } else {
- selectedShape.set('fillColor', color);
- }
- }
- }
- function makeColorButton (color) {
- var button = document.createElement('span');
- button.className = 'color-button';
- button.style.backgroundColor = color;
- google.maps.event.addDomListener(button, 'click', function () {
- selectColor(color);
- setSelectedShapeColor(color);
- });
- return button;
- }
- function buildColorPalette () {
- var colorPalette = document.getElementById('color-palette');
- for (var i = 0; i < colors.length; ++i) {
- var currColor = colors[i];
- var colorButton = makeColorButton(currColor);
- colorPalette.appendChild(colorButton);
- colorButtons[currColor] = colorButton;
- }
- selectColor(colors[0]);
- }
- /////////////////////////////////////////////////////////////
- //Populate textboxes with geo data when new polygon and polyline shape added
- drawingManager.setMap(map);
- google.maps.event.addDomListener(drawingManager, 'markercomplete', function(marker) {
- document.getElementById("action").value += "#marker\n";
- document.getElementById("action").value += marker.getPosition() + "\n";
- });
- google.maps.event.addDomListener(drawingManager, 'polylinecomplete', function(line) {
- path = line.getPath();
- document.getElementById("action_line").value = ''
- document.getElementById("action_line").value += "#polyline shape added\n";
- for(var i = 0; i < path.length; i++) {
- document.getElementById("action_line").value += path.getAt(i) + "\n";
- }
- });
- google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {
- path = polygon.getPath();
- document.getElementById("action_gon").value = ''
- document.getElementById("action_gon").value += "#polygon shape added\n";
- for(var i = 0; i < path.length; i++) {
- document.getElementById("action_gon").value += path.getAt(i) + '\n';
- }
- });
- //////////////////////////////////////////////////////////////////////
- google.maps.event.addListener(drawingManager, 'overlaycomplete', function (e) {
- var newShape = e.overlay;
- newShape.type = e.type;
- if (e.type !== google.maps.drawing.OverlayType.MARKER) {
- // Switch back to non-drawing mode after drawing a shape.
- drawingManager.setDrawingMode(null);
- google.maps.event.addListener(newShape, 'polygoncomplete', function (e) {
- google.maps.event.addListener(newShape.getPath(), 'set_at', function() {
- google.maps.event.addListener(newShape.getPath(), 'insert_at', function() {
- var path = newShape.getPaths().getAt(e.path);
- document.getElementById("polygonEditTest").value += path.getAt(e.vertex) + '\n';
- })
- });
- });
- google.maps.event.addListener(newShape, 'polylinecomplete', function (e) {
- google.maps.event.addListener(newShape.getPath(), 'set_at', function(e) {
- google.maps.event.addListener(newShape.getPath(), 'insert_at', function(e) {
- var path = newShape.getPaths().getAt(e.path);
- document.getElementById("polylineEditTest").value += path.getAt(e.vertex) + '\n';
- })
- });
- });
- // Add an event listener that selects the newly-drawn shape when the user
- // clicks it.
- google.maps.event.addListener(newShape, 'click', function (e) {
- if (e.vertex !== undefined) {
- if (newShape.type === google.maps.drawing.OverlayType.POLYGON) {
- var path = newShape.getPaths().getAt(e.path);
- path.removeAt(e.vertex);
- /////////////////////////////////////////////////////////////
- //Update textboxes with geo data when polygon vertex deleted
- document.getElementById("action_gon").value = ''
- document.getElementById("action_gon").value += "#polygon vertex deleted\n";
- for(var i = 0; i < path.length; i++) {
- document.getElementById("action_gon").value += path.getAt(i) + '\n';
- }
- //
- if (path.length < 3) {
- newShape.setMap(null);
- document.getElementById("action_gon").value = 'This box shows coords when a new POLYGON shape is added and/or vertex deleted'
- }
- }
- if (newShape.type === google.maps.drawing.OverlayType.POLYLINE) {
- var path = newShape.getPath();
- path.removeAt(e.vertex);
- /////////////////////////////////////////////////////////////
- //Update textboxes with geo data when polyline vertex deleted
- document.getElementById("action_line").value = ''
- document.getElementById("action_line").value += "#polyline vertex deleted\n";
- for(var i = 0; i < path.length; i++) {
- document.getElementById("action_line").value += path.getAt(i) + '\n';
- }
- //
- if (path.length < 2) {
- newShape.setMap(null);
- document.getElementById("action_line").value = 'This box shows coords when a new POLYLINE shape is added and/or vertex deleted'
- }
- }
- }
- setSelection(newShape);
- });
- setSelection(newShape);
- }
- else {
- google.maps.event.addListener(newShape, 'click', function (e) {
- setSelection(newShape);
- });
- setSelection(newShape);
- }
- });
- // Link delete button to the UI element.
- var delbtn = /** @type {HTMLInputElement} */(
- document.getElementById('delete-button'));
- map.controls[google.maps.ControlPosition.TOP_RIGHT].push(delbtn);
- // Link color palette to the UI element.
- var colorpal = /** @type {HTMLInputElement} */(
- document.getElementById('color-palette'));
- map.controls[google.maps.ControlPosition.TOP_CENTER].push(colorpal);
- // Clear the current selection when the drawing mode is changed, or when the
- // map is clicked.
- google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);
- google.maps.event.addListener(map, 'click', clearSelection);
- // Listen for delete button click.
- google.maps.event.addDomListener(document.getElementById('delete-button'), 'click',deleteSelectedShape);
- /////////////////////////////////////////////////////////////////////
- buildColorPalette();
- /////////////////////////////////////////////////////////////////////
- var markers = [];
- //var defaultBounds = new google.maps.LatLngBounds(
- //new google.maps.LatLng(-33.8902, 151.1759),
- //new google.maps.LatLng(-33.8474, 151.2631));
- //map.fitBounds(defaultBounds);
- // Create the search box and link it to the UI element.
- var input = /** @type {HTMLInputElement} */(
- document.getElementById('pac-input'));
- map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
- var searchBox = new google.maps.places.SearchBox(
- /** @type {HTMLInputElement} */(input));
- // [START region_getplaces]
- // Listen for the event fired when the user selects an item from the
- // pick list. Retrieve the matching places for that item.
- google.maps.event.addListener(searchBox, 'places_changed', function() {
- var places = searchBox.getPlaces();
- if (places.length == 0) {
- return;
- }
- for (var i = 0, marker; marker = markers[i]; i++) {
- marker.setMap(null);
- }
- // For each place, get the icon, place name, and location.
- markers = [];
- var bounds = new google.maps.LatLngBounds();
- for (var i = 0, place; place = places[i]; i++) {
- var image = {
- url: place.icon,
- size: new google.maps.Size(71, 71),
- origin: new google.maps.Point(0, 0),
- anchor: new google.maps.Point(17, 34),
- scaledSize: new google.maps.Size(25, 25)
- };
- // Create a marker for each place.
- // var marker = new google.maps.Marker({
- // map: map,
- // icon: image,
- // title: place.name,
- // position: place.geometry.location
- // });
- //
- // markers.push(marker);
- //
- bounds.extend(place.geometry.location);
- }
- map.fitBounds(bounds);
- });
- }
- google.maps.event.addDomListener(window, 'load', initialize);
- </script>
- </head>
- <body>
- <input id="pac-input" class="controls" type="text" placeholder="Search...">
- <input id="delete-button" onclick="deleteSelectedShape();" type=button value="Delete Selected Shape">
- <div id="color-palette"></div>
- <div id="geoinfoboxes">
- <textarea id="action_line" rows="8" cols="46">This box shows coords when a new POLYLINE shape is added and/or vertex deleted</textarea>
- <textarea id="action_gon" rows="8" cols="46">This box shows coords when a new POLYGON shape is added and/or vertex deleted</textarea>
- <textarea id="polylineEditTest" rows="8" cols="46">This box shows coords for edited POLYLINES (ie. moving a vertex)</textarea>
- <textarea id="polygonEditTest" rows="8" cols="46">This box shows coords for edited POLYGONS (ie. moving a vertex)</textarea>
- </div>
- <div id="map"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement