admin管理员组文章数量:1287892
I'm working with the drawing tool associated to Google Maps by using:
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.Marker,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.Top_Center,
drawingModes: [
google.maps.drawing.OverlayType.POLYGON,
]
},
});
drawingManager.setMap(map);
This works fine, but I was wondering how I could use a custom button instead of the default control for the Polygon tool. Such that when I press the button it is active and when I press it again it deactivates it.
This is my custom toolbar:
<div id="toolbar-container" class="toolbar-container">
<div class="toolbar no-select">
<div class="toolbar-button" id="clear-button">Clear Polygon</div>
<div class="toolbar-button" id="polygon-button">Polygon</div>
</div>
</div>
I tried looking through the api but I could not find anything.
For reference, this is the site I used:
Any help with this would be appreciated!
I'm working with the drawing tool associated to Google Maps by using:
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.Marker,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.Top_Center,
drawingModes: [
google.maps.drawing.OverlayType.POLYGON,
]
},
});
drawingManager.setMap(map);
This works fine, but I was wondering how I could use a custom button instead of the default control for the Polygon tool. Such that when I press the button it is active and when I press it again it deactivates it.
This is my custom toolbar:
<div id="toolbar-container" class="toolbar-container">
<div class="toolbar no-select">
<div class="toolbar-button" id="clear-button">Clear Polygon</div>
<div class="toolbar-button" id="polygon-button">Polygon</div>
</div>
</div>
I tried looking through the api but I could not find anything.
For reference, this is the site I used: https://developers.google./maps/documentation/javascript/examples/drawing-tools
Any help with this would be appreciated!
Share Improve this question asked Jan 26, 2015 at 17:45 Ryan SaylesRyan Sayles 3,44111 gold badges58 silver badges80 bronze badges 1- You may refer to here, and here to gain some custom button idea on google map. – bjiang Commented Jan 26, 2015 at 21:46
1 Answer
Reset to default 13There is a predefined method to create new custom control and event handling in Google Maps API.
I have created the new control in initialize() function
// Create the DIV to hold the control and call the HomeControl() constructor
var homeControlDiv = document.createElement('div');
var homeControl = new HomeControl(homeControlDiv, map);
homeControlDiv.index = 1;
map.controls[google.maps.ControlPosition.TOP_CENTER].push(homeControlDiv);
//To set CSS and handling event for the control
function HomeControl(controlDiv, map) {
// Set CSS for the control border.
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = 'blue';
controlUI.style.height = '23px';
controlUI.style.marginTop = '5px';
controlUI.style.marginLeft = '-9px';
controlUI.style.paddingTop = '1px';
controlUI.style.cursor = 'pointer';
controlUI.title = 'Your Custom function..';
controlDiv.appendChild(controlUI);
// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.style.padding = '11px';
controlText.innerHTML = 'Custom Text';
controlText.style.color = '#fff';
controlUI.appendChild(controlText);
// Setup the click event listeners
google.maps.event.addDomListener(controlUI, 'click', function () {
alert('Your Custom function..');
});
}
hope this will help you.. check out my fiddle here
本文标签: javascriptCustom button with Google Maps DrawingStack Overflow
版权声明:本文标题:javascript - Custom button with Google Maps Drawing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741304468a2371284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论