I have created two custom controlUIs in Google Maps based on existing default examples. They work nice but I realised they are displayed vertically:
But I want them displayed horizontally:
The CSS definintions for both custom Controls looks the same (except the image of course):
// Add marker control
var optionDiv = document.createElement('div');
// Same for second control UI (centerPlayer) but for simplicity reasons not added
var CenterMarker = new centerMarkerButton (optionDiv, this.map);
optionDiv.index = 1;
this.map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(optionDiv);
...
function centerMarkerButton (controlDiv, map) {
// Set CSS for the control border.
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = '#fff';
controlUI.style.border = '2px solid #fff';
controlUI.style.borderRadius = '3px';
controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
controlUI.style.cursor = 'pointer';
controlUI.style.marginBottom = '8px';
controlUI.style.marginRight = '10px';
controlUI.style.paddingTop = '3px';
controlUI.style.paddingLeft = '3px';
controlUI.style.paddingRight = '3px';
controlDiv.appendChild(controlUI);
// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.innerHTML = '<a><img src="https://www....centermarker.svg" height="28px" width="28px"</a>';
controlUI.appendChild(controlText);
// Add click event listener
controlUI.addEventListener('click', function() {
instance.centerGame();
});
}
}
// Set CSS for the control border.
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = '#fff';
controlUI.style.border = '2px solid #fff';
controlUI.style.borderRadius = '3px';
controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
controlUI.style.cursor = 'pointer';
controlUI.style.marginBottom = '8px';
controlUI.style.marginRight = '10px';
controlUI.style.paddingTop = '3px';
controlUI.style.paddingLeft = '3px';
controlUI.style.paddingRight = '3px';
controlUI.style.paddingRight = '3px';
controlDiv.appendChild(controlUI);
// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.innerHTML = '<a><img src="https://www..../centeruser.svg" height="28px" width="28px"</a>';
controlUI.appendChild(controlText);
Code analysis inside the displayed google maps in browser showed me there is a simple DIV around both custom Controls but it has no ID, so I can't access/modify it.
Anyone has an idea how I can set/display these two custom Controls vertically?
Dang, just found the answer by myself. I had to add these CSS styles to both controlUIs:
controlUI.style.cssFloat = 'left';
Now the controls appears horizontally (next to each other).
Related
I am using javascript for the editable div element.
var div = document.getElementById('htmlelement');
var ele = document.createElement('div');
ele.setAttribute('id','inputelement');
ele.style.display = 'inline-block';
ele.style.border = 'none';
ele.style.minHeight = '100px';
ele.style.maxHeight = '100px;'
ele.style.padding = '10px';
ele.style.fontSize = '12px';
ele.style.color = 'blue';
ele.setAttribute('contentEditable','true');
div.appendChild(ele);
ele.focus();
Now after focus black border shows over the div area automatically.
I want to remove and change that border color, but I think CSS will not work for this. because div element is dynamically created by javascript.
is any way to remove that black border or change that border color.
i am tryijng to use css but not working because of dynamic element creation
like,
[contenteditable] {
outline: 0px solid transparent;
}
When you talk about "border" you mean "outline"? You can just set it to none.
var div = document.getElementById('htmlelement');
var ele = document.createElement('div');
ele.id = 'inputelement';
ele.style.display = 'inline-block';
ele.style.border = 'none';
ele.style.minHeight = '100px';
ele.style.maxHeight = '100px;';
ele.style.padding = '10px';
ele.style.fontSize = '12px';
ele.style.color = 'blue';
ele.setAttribute('contentEditable', 'true');
div.appendChild(ele);
ele.focus();
div[contenteditable] {
outline: none;
}
<div id="htmlelement"></div>
I created a chrome extension that inserts some html into a page (see screenshot below of how it looks...top right corner is the inserted HTML).
I want to create functionality such that when the user clicks the "Skip for now" text, the inserted HTML should disappear or be hidden. I'm having a difficult time doing that within my current code.
Inject.js gets called through this function:
chrome.tabs.executeScript(tab.ib, {
file: 'inject.js'
});
Inject.js (I'm not sure how to write a new function to hide all the elements that were created below and how to call that function from the HTML section at the bottom):
(function() {
// Create div
var div = document.createElement('div');
// Div styling
// Positioning
div.style.position = 'fixed';
div.style.boxSizing = 'border-box';
div.style.display = 'block';
div.style.zIndex = 10000000;
div.style.top = '20px';
div.style.right = '20px';
// Size
div.style.height = '130px';
div.style.width = '330px';
// Padding
div.style.paddingTop = '20px';
div.style.paddingBottom = '20px';
div.style.paddingLeft = '20px';
div.style.paddingRight = '20px';
div.style.borderRadius = '25px';
// Text
div.style.textAlign = 'center';
div.style.fontSize = '11px';
// Color
div.style.backgroundColor = '#505F69';
div.style.color = 'white';
div.style.border = '2px solid grey';
// HTML
div.innerHTML += '<u>Click to activate your To a Cause donation.</u><br><br>';
div.innerHTML += '<u>Skip for now</u>';
// Append
document.body.appendChild(div);
})();
You should create the skip button as an HTML node (like you did for the div) and append it to the div. Then you can do:
skipButton.onclick = () => {
document.body.removeChild(div);
};
I have a google map and
I´m using a hacky solution for infowindows not to show up under a div that overlays the google map if a special user-interaction is done.
i execute this code after user-interaction :
var controlDiv = document.createElement('div');
controlDiv.style.width = '220px';
controlDiv.style.height = '500px';
map.controls[google.maps.ControlPosition.RIGHT_TOP].push(controlDiv);
that works wonderfully, but if the user closes the overlay i want to remove the element i pushed into the array.
i tryed to splice it out, but i have no idea how to select it, or what it´s index is.
map.controls[google.maps.ControlPosition.RIGHT_TOP].splice("?", 1);
other possibility may be
delete map.controls[google.maps.ControlPosition.RIGHT_TOP]
but i just dont get the element removed
plesea help
thanks in advance
map.controls[google.maps.ControlPosition.RIGHT_TOP] isn't a native array, it's a google.maps.MVCArray
When you add only this single custom control to the array you may simply call:
map.controls[google.maps.ControlPosition.RIGHT_TOP].clear();
When there are more custom controls iterate over the controls to find the index of controlDiv and call
map.controls[google.maps.ControlPosition.RIGHT_TOP].removeAt(index);
Another approach: instead of adding/removing the control add the control once and toggle the display of controlDiv.
I found that the setAt() and removeAt() methods do not work well for map controls. Google only uses push() and clear() methods in their code samples.
Also, the display property may result in controls on top of each other after hiding and re-showing them. I found that the visibility property works best. Below a custom control constructor with google map style and a method to show/hide the control.
function CustomControl(options) { // constructor
"use strict";
this.div = document.createElement('div');
this.div.style.visibility = "visible";
var controlUI = document.createElement('div'); // Set CSS for the control border
controlUI.style.backgroundColor = '#fff';
controlUI.style.backgroundClip = 'padding-box';
controlUI.style.border = '1px solid rgba(0, 0, 0, 0.15)';
controlUI.style.borderRadius = '2px';
controlUI.style.boxShadow = 'rgba(0,0,0,.3) 0px 1px 4px -1px';
controlUI.style.cursor = 'pointer';
controlUI.style.margin = '5px 5px 15px';
controlUI.style.minWidth = '120px';
controlUI.style.textAlign = 'left';
controlUI.style.position = 'relative';
if (options.title) {
controlUI.title = options.title;
}
if (options.visibility) { // "visible" or "hidden"
controlUI.style.visibility = options.visibility;
}
this.div.appendChild(controlUI);
var controlText = document.createElement('div'); //Set CSS for the control interior
controlText.style.color = 'rgb(25,25,25)';
controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
controlText.style.fontSize = '11px';
controlText.style.fontWeight = '500';
controlText.style.padding = '1px 6px';
if (options.text) {
controlText.innerHTML = options.text;
}
controlUI.appendChild(controlText);
if (options.index) {
this.div.index = options.index;
}
if (options.handler) {
google.maps.event.addDomListener(controlUI, 'click', options.handler);
}
if (options.position) {
this.position = options.position;
}
if (options.sequence) {
this.sequence = options.sequence;
}
this.setVisible = function(bolean) { // method
var visibility;
if (bolean) { //true
visibility = "visible";
} else {
visibility = "hidden";
}
controlUI.style.visibility = visibility;
}
}
I'm trying to create a control like the one on google maps to show different maps (Map, Satellite, Terrain). Basically, a button-like div that when I click it it displays a drop down list of checkboxes and a button. I can create the drop down list of checkboxes but I can't make the div to behave like that control of google maps.
What am I missing?
My list appears inside the "button" and not below.
Here is my code
function MyControl(controlDiv, map) {
controlDiv.style.padding = '5px';
var controlUI = document.createElement('DIV');
controlUI.style.backgroundColor = 'white';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '2px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'left';
controlUI.title = 'Click to show';
controlDiv.appendChild(controlUI);
var dropdown = document.createElement('DIV');
dropdown.style.width = '100px';
var chkOne = document.createElement( "input" );
chkOne.type = "checkbox";
chkOne.id = "chkOne";
chkOne.value = "One";
chkOne.checked = false;
var lblOne = document.createElement('label')
lblOne.htmlFor = "chkOne";
lblOne.appendChild(document.createTextNode('One'));
var chkTwo = document.createElement( "input" );
chkTwo.type = "checkbox";
chkTwo.id = "chkTwo";
chkTwo.value = "Two";
chkTwo.checked = false;
var lblTwo = document.createElement('label')
lblTwo.htmlFor = "chkTwo";
lblTwo.appendChild(document.createTextNode('Two'));
var btnDone = document.createElement( "input" );
btnDone.type = "button";
btnDone.name = "btnDone";
btnDone.value = "Done";
dropdown.appendChild(chkOne);
dropdown.appendChild(lblOne);
dropdown.appendChild(document.createElement( "BR" ));
dropdown.appendChild(chkTwo);
dropdown.appendChild(lblTwo);
dropdown.appendChild(document.createElement( "BR" ));
dropdown.appendChild(btnDone);
controlUI.appendChild(dropdown);
google.maps.event.addDomListener(controlUI, 'click', function() {
dropdown.visible = true;
});
btnDone.addEventListener("click", showList, false);
function showList() {
dropdown.visible = false;
}
}
// Create the DIV to hold the control and call the HomeControl() constructor
// passing in this DIV.
var accidentsToShowDiv = document.createElement('DIV');
// Set CSS for the control border.
accidentsToShowDiv.style.backgroundColor = 'white';
accidentsToShowDiv.style.borderStyle = 'solid';
accidentsToShowDiv.style.borderWidth = '2px';
accidentsToShowDiv.style.cursor = 'pointer';
accidentsToShowDiv.style.textAlign = 'left';
accidentsToShowDiv.title = 'Accidents to Show';
var homeControl = new MyControl(accidentsToShowDiv, mainMap);
accidentsToShowDiv.index = 1;
mainMap.controls[google.maps.ControlPosition.TOP_RIGHT].push(accidentsToShowDiv);
You forgot to add boxshadow
controlUI.style.boxShadow = '0 1px 3px rgba(0,0,0,0.5)';
I am trying to generate a div element in the corner of the screen from a bookmarklet.
I tried
var newdiv = document.createElement('div');
newdiv.id="blabal";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.style.width=300;
newdiv.style.heigth=200;
newdiv.style.position="fixed";
newdiv.style.top="20";
document.body.appendChild(newdiv);
to now avail.
Thanks.
You need to provide px with the values, and you got a typo in heigth:
var newdiv = document.createElement('div');
newdiv.id="blabal";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.style.width="300px";
newdiv.style.height="200px";
newdiv.style.position="fixed";
newdiv.style.top="20px";
document.body.appendChild(newdiv);
example: http://jsfiddle.net/niklasvh/gy9XJ/
This is mostly accurate, but you have a typo in height and you need to provide units for width, height and top. I'm assuming pixels, but the interpreter won't be so kind; 200 could be in ems, pixels, points, percents (200em, 200px, 200pt and 200%, respectively):
var newdiv = document.createElement('div');
newdiv.id="blabal";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.style.width="300px";
newdiv.style.height="200px";
newdiv.style.position="fixed";
newdiv.style.top="20px";
document.body.appendChild(newdiv);