I searched a lot for creating a custom control for Google Maps Api v3, and I found that others use it as Google Documentation . They create divs and style it with JS, which I think is not good practice. I think this violates the separation of the design principle of the problems, I mean writing CSS code inside JS or HTML.
Besides the question of best practice, I tried my code examples from the above link, but it does not work, it caused the following error:
( **Uncaught TypeError: Cannot read property 'zIndex' of undefined** ) ..
Here is the code to set the [ Enlarge ] button.
HTML file
<div id="control-div" class="control-div"> <div id= "control-ui" class="control-ui" title = "Click to set the map to Home"> <div id="control-text" class="control-text"> <p> Zoom </p> </div> </div> </div>
CSS file
.control-ui{ background-color: white; border-style: solid; border-width: 2px; cursor: pointer; text-align: center; width: 90px; height: 30px; } .control-text{ front-family: Arial,sans-serif; font-size: 12px; padding: 4px 4px; }
JS file (Google map initiator)
var controlDiv =$("#control-div"); var controlUI = $("#control-ui"); var controlText = $("#control-text"); controlUI.click(function() { map.setZoom(11); }); controlDiv.index = 1; map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);
source share