Map Controls
How do I make an map controls?
A set of "map controls" - pan and zoom - I'm using for a project at work but I wanted to share these cause I think they're pretty cool. There are no images here, just CSS and JavaScript, and I'm using jQuery UI for the slider functionality.. What is a map controls? How do you make a map controls? This script and codes were developed by Ilia on 04 August 2022, Thursday.
Map Controls - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Map Controls</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="map"> <div id="mapControls"> <div id="mapZoom"> <div id="zoomIn" class="zoom-control" title="Zoom in the view"></div> <div id="zoomOut" class="zoom-control" title="Zoom out the view"></div> <div id="zoomSlider"></div> </div> <div id="mapPan"> <div class="pan-split" id="panSplitVert"></div> <div class="pan-split" id="panSplitHoriz"></div> <div id="panCentre"></div> <div class="pan-arrow" id="panTop" title="Pan view to the top"></div> <div class="pan-arrow" id="panRight" title="Pan view to the right"></div> <div class="pan-arrow" id="panBottom" title="Pan view to the bottom"></div> <div class="pan-arrow" id="panLeft" title="Pan view to the left"></div> </div> </div> <div id="debug"> <u>Position</u><br><br> X: <span id="posX">183</span> Y: <span id="posY">107</span><br> <br> <u>Zoom</u><br><br> Scale: <span id="zoomScale">1.0</span> </div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://code.jquery.com/ui/1.9.2/jquery-ui.js'></script> <script src="js/index.js"></script>
</body>
</html>
Map Controls - Script Codes CSS Codes
#map{ background:#1d2329; position:relative; width:100%; height:320px;
}
#mapControls { position:relative; height:260px; width:160px; background:-webkit-linear-gradient(-30deg, rgba(0,0,0,.3), rgba(0,0,0,0) 50%); background:linear-gradient(120deg, rgba(0,0,0,.3), rgba(0,0,0,0) 50%); z-index:999;
}
#mapPan { background:#47494b; width:65px; height:65px; border-radius:34px; position:absolute; top:20px; left:20px;
/* box-shadow:rgba(0,0,0,.3) 0 0 6px; */ border:solid 2px #1b2025;
}
#panCentre { background:#1d2329; width:21px; height:21px; border-radius:11px; position:absolute; top:22px; left:22px; box-shadow:inset rgba(0,0,0,.3) 0 0 4px;
}
.pan-split { background:#1d2329; box-shadow:inset rgba(0,0,0,.3) 0 0 4px; width:3px; height:67px; position:absolute; top:-1px; left:31px;
}
#panSplitVert { -webkit-transform:rotate(45deg); -moz-transform:rotate(45deg); transform:rotate(45deg);
}
#panSplitHoriz { -webkit-transform:rotate(135deg); -moz-transform:rotate(135deg); transform:rotate(135deg);
}
/***
this is the "hotspot" area for arrow
it's bigger than the arrows themselves
***/
.pan-arrow { width:25px; height:20px; position:absolute; cursor:pointer;
}
#panTop { top:1px; left:20px }
#panBottom { bottom:1px; left:20px }
#panRight { top:20px; right:1px; width:20px; height:25px }
#panLeft { top:20px; left:1px; width:20px; height:25px }
/* this is the first layer of the arrow */
.pan-arrow:before { content:''; width:0; height:0; border:solid 7px transparent; position:absolute; -webkit-transition:border-color .2s; -moz-transition:border-color .2s; transition:border-color .2s;
}
#panTop:before { top:3px; left:6px; border-bottom-color:#292929; border-top-width:0;
}
#panTop:hover:before { border-bottom-color:#44a8c7 }
#panRight:before { top:6px; right:3px; border-left-color:#292929; border-right-width:0;
}
#panRight:hover:before { border-left-color:#44a8c7 }
#panBottom:before { bottom:3px; left:6px; border-top-color:#292929; border-bottom-width:0;
}
#panBottom:hover:before { border-top-color:#44a8c7 }
#panLeft:before { top:6px; left:3px; border-right-color:#292929; border-left-width:0;
}
#panLeft:hover:before { border-right-color:#44a8c7 }
/* this is the second layer of the arrow */
.pan-arrow:after { content:''; display:block; width:0; height:0; border:solid 5px transparent; position:absolute;
}
#panTop:after { border-bottom-color:#47494b; border-top-width:0; top:5px; left:8px;
}
#panRight:after { border-left-color:#47494b; border-right-width:0; top:8px; right:5px;
}
#panBottom:after { border-top-color:#47494b; border-bottom-width:0; bottom:5px; left:8px;
}
#panLeft:after { border-right-color:#47494b; border-left-width:0; top:8px; left:5px;
}
#mapZoom { width:16px; height:150px; position:absolute; top:68px; left:22px;
}
.zoom-control { background:#47494b; border-radius:2px; position:absolute; left:0; width:16px; box-shadow:rgba(0,0,0,.3) 0 0 4px; cursor:pointer;
}
#zoomIn { height:34px; top:0 }
#zoomOut { height:16px; bottom:0 }
/* the plus and minus signs */
.zoom-control:before, #zoomIn:after { content:''; background:#222; position:absolute;
}
.zoom-control:before { width:8px; height:2px; left:4px; bottom:7px;
}
#zoomIn:after { width:2px; height:8px; left:7px; bottom:4px;
}
.zoom-control:hover:before, .zoom-control:hover:after { background:#44a8c7 !important;
}
/* zoom slider & scrubber */
#zoomSlider { background:#47494b; width:4px; height:95px; position:absolute; left:6px; top:34px; border:1px solid #47494b; border-width:5px 0;
}
.ui-slider-range { position:absolute; left:0; bottom:0; width:100%;
}
.ui-slider-handle { background:#676a6c; width:16px; height:5px; position:absolute; left:-6px; border-radius:1px; cursor:pointer; box-shadow:rgba(0,0,0,.3) 0 0 4px; -webkit-transition:background-color .2s; -moz-transition:background-color .2s; transition:background-color .2s;
}
.ui-slider-handle:focus { outline:none }
.ui-slider-handle:hover { background:#44a8c7 }
.ui-slider-handle:after { content:''; background:#292929; width:10px; height:1px; position:absolute; top:2px; left:3px;
}
#debug { position:absolute; top:107px; left:183px; background:#111; width:164px; height:102px; border:1px solid #444; color:#ccc; font-size:12px; font-family:"Andale Mono"; padding:4px 8px;
}
Map Controls - Script Codes JS Codes
var controls = $('#mapControls'), zoomStep = 10, zoom = $('#zoomSlider'), zoomOut = $('#zoomScale'), panStep = 10, totalPanX = 183, totalPanY = 107, panXOut = $('#posX'), panYOut = $('#posY'), debug = $('#debug');
controls.on('click', '.pan-arrow, .zoom-control', function(){ switch ( $(this).attr('id') ) { case 'panTop': panMap(0, -panStep); break; case 'panRight': panMap(panStep, 0); break; case 'panBottom': panMap(0, panStep); break; case 'panLeft': panMap(-panStep, 0); break; case 'zoomIn': zoom.slider('value', zoom.slider('value') + zoomStep); updateZoom(zoom.slider('value')); break; case 'zoomOut': zoom.slider('value', zoom.slider('value') - zoomStep); updateZoom(zoom.slider('value')); break; }
});
zoom.slider({ orientation:'vertical', range:'min', min:50, max:200, step:1, value:100, slide:function(e,ui) { updateZoom(ui.value); }
});
function updateZoom(rawZoom) { rawZoom /= 100; zoomOut.text( rawZoom ); debug.css('-webkit-transform', 'scale(' + rawZoom + ')'); debug.css('-moz-transform', 'scale(' + rawZoom + ')'); debug.css('transform', 'scale(' + rawZoom + ')');
}
function panMap(panX, panY) { totalPanX += panX; if (totalPanX < 0) totalPanX = 0; totalPanY += panY; if (totalPanY < 0) totalPanY = 0; panXOut.text( totalPanX ); panYOut.text( totalPanY ); debug.css({top:totalPanY, left:totalPanX});
}
Developer | Ilia |
Username | iliadraznin |
Uploaded | August 04, 2022 |
Rating | 3.5 |
Size | 3,721 Kb |
Views | 34,408 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Canvas drawing app | 5,828 Kb |
CSS3 Working Clock | 5,889 Kb |
Reproducing content box from RSI | 2,998 Kb |
A Pen by Ilia | 2,567 Kb |
Dynamic SVG creation | 5,075 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Pure CSS Tooltip | APinix | 2,815 Kb |
Cars going | Netoguimaraes | 1,699 Kb |
My Interests | Anshusaxenaarora | 2,015 Kb |
Portfolio Page | KaylaMT | 1,983 Kb |
A Pen by Brendan Skousen | Bskousen | 2,954 Kb |
Web Spiral - p5.js | TWAIN | 2,183 Kb |
Sticky div | Kaslab | 2,225 Kb |
Flex layout example | Mofny | 1,663 Kb |
Scoreboard.js basic usage | Tbleckert | 1,733 Kb |
Image grid with captions | Mchernin34 | 2,222 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!