<html>
<head>
<title>Google Maps example</title>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { width: 1280px; height: 715px; }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false®ion=GB&libraries=drawing">
</script>
</head>
<body>
<div id="map_canvas" style="width:1280px; height:715px"></div>
</body>
</html>
var G = google.maps;
var zoom = 7;
var centerPoint = new G.LatLng(45.5, -100.5);
$(function() {
// create options object
var myOptions = {
center: centerPoint,
zoom: zoom,
mapTypeId: G.MapTypeId.ROADMAP
};
// create map with options
var map = new G.Map($("#map_canvas")[0], myOptions);
addPolygon(map);
});
function addPolygon(map){
var paths = [
new G.LatLng(45, -100),
new G.LatLng(45.5, -99.5),
new G.LatLng(46, -100),
new G.LatLng(46, -101),
new G.LatLng(45, -101)
];
poly = new G.Polygon({
clickable: false,
paths: paths,
map: map
});
poly.setEditable(true);
addDeleteButton(poly, 'http://i.imgur.com/RUrKV.png');
}
function addDeleteButton(poly, imageUrl) {
var path = poly.getPath();
path["btnDeleteClickHandler"] = {};
path["btnDeleteImageUrl"] = imageUrl;
google.maps.event.addListener(poly.getPath(),'set_at',pointUpdated);
google.maps.event.addListener(poly.getPath(),'insert_at',pointUpdated);
}
function pointUpdated(index) {
var path = this;
var btnDelete = getDeleteButton(path.btnDeleteImageUrl);
if(btnDelete.length === 0)
{
var undoimg = $("img[src$='http://maps.gstatic.com/mapfiles/undo_poly.png']");
undoimg.parent().css('height', '21px !important');
undoimg.parent().parent().append('<div style="overflow-x: hidden; overflow-y: hidden; position: absolute; width: 30px; height: 27px;top:21px;"><img src="' + path.btnDeleteImageUrl + '" class="deletePoly" style="height:auto; width:auto; position: absolute; left:0;"/></div>');
// now get that button back again!
btnDelete = getDeleteButton(path.btnDeleteImageUrl);
btnDelete.hover(function() { $(this).css('left', '-30px'); return false;},
function() { $(this).css('left', '0px'); return false;});
btnDelete.mousedown(function() { $(this).css('left', '-60px'); return false;});
}
// if we've already attached a handler, remove it
if(path.btnDeleteClickHandler)
btnDelete.unbind('click', path.btnDeleteClickHandler);
// now add a handler for removing the passed in index
path.btnDeleteClickHandler = function() {
path.removeAt(index);
return false;
};
btnDelete.click(path.btnDeleteClickHandler);
}
function getDeleteButton(imageUrl) {
return $("img[src$='" + imageUrl + "']");
}
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |