내장 된 Google지도에서 마우스 스크롤 휠 줌 비활성화
저자가 대부분의 게시물에 iFrame을 사용하여 Google지도를 삽입하는 WordPress 사이트에서 작업하고 있습니다.
Javascript를 사용하여 마우스 스크롤 휠을 통해 줌을 비활성화하는 방법이 있습니까?
같은 문제가 발생했습니다. 페이지를 스크롤하면 포인터가 맵 위에 오면 페이지를 계속 스크롤하는 대신 맵을 확대 / 축소하기 시작합니다. :(
그래서 이것은 퍼팅 해결 div
으로 .overlay
정확히 각 GMAP의 전에 iframe
삽입을 참조하십시오
<html>
<div class="overlay" onClick="style.pointerEvents='none'"></div>
<iframe src="https://mapsengine.google.com/map/embed?mid=some_map_id" width="640" height="480"></iframe>
</html>
내 CSS에서 클래스를 만들었습니다.
.overlay {
background:transparent;
position:relative;
width:640px;
height:480px; /* your iframe height */
top:480px; /* your iframe height */
margin-top:-480px; /* your iframe height */
}
div는지도를 덮어 포인터 이벤트가 도착하지 못하게합니다. 그러나 div를 클릭하면 포인터 이벤트가 투명 해져 맵이 다시 활성화됩니다!
나는 당신을 도울 수 있기를 바랍니다 :)
나는이 토론에서 첫 번째 답변을 시도했지만 내가 무엇을하든 나에게 도움이되지 않았습니다. 내 자신의 해결책을 생각해 냈습니다.
iframe을 클래스 (이 예제에서는 .maps)로 감싸고 이상적으로 코드를 포함시키는 것이 이상적입니다. http://embedresponsively.com/ — iframe의 CSS를 변경 pointer-events: none
한 다음 jQuery의 click 함수를 부모 요소로 사용하여 iframe CSS를 변경할 수 있습니다 에pointer-events:auto
HTML
<div class='embed-container maps'>
<iframe width='600' height='450' frameborder='0' src='http://foo.com'></iframe>
</div>
CSS
.maps iframe{
pointer-events: none;
}
jQuery
$('.maps').click(function () {
$('.maps iframe').css("pointer-events", "auto");
});
$( ".maps" ).mouseleave(function() {
$('.maps iframe').css("pointer-events", "none");
});
누군가가 자유롭게 느끼기를 원한다면 JavaScript 전용 방법이 있다고 확신합니다.
포인터 이벤트를 재 활성화하는 JavaScript 방법은 매우 간단합니다. iFrame에 ID를 제공 한 다음 (예 : "iframe") onclick 이벤트를 cointainer div에 적용하십시오.
onclick="document.getElementById('iframe').style.pointerEvents= 'auto'"
<div class="maps" onclick="document.getElementById('iframe').style.pointerEvents= 'auto'">
<iframe id="iframe" src="" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
@nathanielperales 솔루션을 확장했습니다.
동작 설명 아래 :
- 스크롤을 사용하려면지도를 클릭하십시오
- 마우스가지도를 떠날 때 스크롤 비활성화
자바 스크립트 코드 아래 :
// Disable scroll zooming and bind back the click event
var onMapMouseleaveHandler = function (event) {
var that = $(this);
that.on('click', onMapClickHandler);
that.off('mouseleave', onMapMouseleaveHandler);
that.find('iframe').css("pointer-events", "none");
}
var onMapClickHandler = function (event) {
var that = $(this);
// Disable the click handler until the user leaves the map area
that.off('click', onMapClickHandler);
// Enable scrolling zoom
that.find('iframe').css("pointer-events", "auto");
// Handle the mouse leave event
that.on('mouseleave', onMapMouseleaveHandler);
}
// Enable map zooming with mouse scroll when the user clicks the map
$('.maps.embed-container').on('click', onMapClickHandler);
그리고 여기 jsFiddle 예제가 있습니다.
#nathanielperales가 작성한 코드를 다시 편집하고 있습니다. 간단하고 잡기 쉽지만 한 번만 작동합니다. 그래서 JavaScript에 mouseleave ()를 추가했습니다. 아이디어는 #Bogdan에서 채택되었으며 이제는 완벽합니다. 이 시도. 크레딧은 #nathanielperales와 #Bogdan으로갑니다. 방금 두 아이디어를 결합했습니다. 감사합니다. 이것이 다른 사람들에게도 도움이되기를 바랍니다 ...
HTML
<div class='embed-container maps'>
<iframe width='600' height='450' frameborder='0' src='http://foo.com'> </iframe>
</div>
CSS
.maps iframe{
pointer-events: none;
}
jQuery
$('.maps').click(function () {
$('.maps iframe').css("pointer-events", "auto");
});
$( ".maps" ).mouseleave(function() {
$('.maps iframe').css("pointer-events", "none");
});
즉흥 연습-적응-극복
그리고 여기 jsFiddle 예제가 있습니다.
예, 아주 쉽습니다. 나는 비슷한 문제에 직면했다. CSS 속성 "pointer-events" 를 iframe div에 추가하고 'none'으로 설정하십시오 .
예 : <iframe style = "pointer-events : none"src = ........>
참고 :이 수정은지도에서 다른 모든 마우스 이벤트를 비활성화합니다. 우리는지도에서 사용자 상호 작용을 필요로하지 않았기 때문에 저에게 효과적이었습니다.
var mapOptions = {
scrollwheel: false,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
몇 가지 연구를 한 후에는 두 가지 옵션이 있습니다. iframe 삽입이 포함 된 새지도 API는 마우스 휠 비활성화를 지원하지 않는 것 같습니다.
먼저 오래된 Google지도를 사용하는 것입니다 ( https://support.google.com/maps/answer/3045828?hl=ko ).
두 번째 는 각 주석에 대한 맵 임베딩을 단순화하고 매개 변수를 사용하는 자바 스크립트 함수를 만드는 것입니다 (정확한 솔루션을 표시하지 않는 위치를 가리키는 샘플 코드입니다)
function createMap(containerid, parameters) {
var mymap = document.getElementById(containerid),
map_options = {
zoom: 13,
scrollwheel: false,
/* rest of options */
},
map = new google.maps.Map(mymap, map_options);
/* 'rest of code' to take parameters into account */
}
훌륭하고 쉬운 해결책이 있습니다.
캔버스에 none으로 매핑하기위한 포인터 이벤트를 설정하는 CSS에 사용자 정의 클래스를 추가해야합니다.
.scrolloff{
pointer-events: none;
}
그런 다음 jQuery를 사용하면 다른 이벤트를 기반으로 해당 클래스를 추가 및 제거 할 수 있습니다 (예 :
$( document ).ready(function() {
// you want to enable the pointer events only on click;
$('#map_canvas').addClass('scrolloff'); // set the pointer events to none on doc ready
$('#canvas').on('click', function() {
$('#map_canvas').removeClass('scrolloff'); // set the pointer events true on click
});
// you want to disable pointer events when the mouse leave the canvas area;
$( "#map_canvas" ).mouseleave(function() {
$('#map_canvas').addClass('scrolloff'); // set the pointer events to none when mouse leaves the map area
});
});
jsfiddle 에서 예제를 만들었습니다 .
그냥 developers.google.com에 하나의 계정을 등록 하고 Maps API 호출을위한 토큰을 얻은 후 다음과 같이 비활성화하십시오 (스크롤 휠 : false).
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('container_google_maps'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8,
scrollwheel: false
});
}
이것이 나의 접근법이다. 다양한 웹 사이트에서 쉽게 구현하고 항상 사용할 수 있습니다.
CSS와 자바 스크립트 :
<style type="text/css">
.scrolloff iframe {
pointer-events: none ;
}
</style>
<script type="text/javascript">
function scrollOn() {
$('#map').removeClass('scrolloff'); // set the pointer events true on click
}
function scrollOff() {
$('#map').addClass('scrolloff');
}
</script>
HTML에서는 iframe을 div로 감싸고 싶습니다. <div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" >
function scrollOn() {
$('#map').removeClass('scrolloff'); // set the pointer events true on click
}
function scrollOff() {
$('#map').addClass('scrolloff'); // set the pointer events true on click
}
.scrolloff iframe {
pointer-events: none ;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="map" class="scrolloff" onclick="scrollOn()" onmouseleave="scrollOff()" ><iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d23845.03946309692!2d-70.0451736316453!3d41.66373705082399!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x89fb159980380d21%3A0x78c040f807017e30!2sChatham+Tides!5e0!3m2!1sen!2sus!4v1452964723177" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen></iframe></div>
이것이 간단한 솔루션을 찾는 사람에게 도움이되기를 바랍니다.
간단한 해결책은 다음과 같습니다. 마우스 스크롤을 비활성화 하려면 pointer-events: none
CSS를로 설정하십시오 <iframe>
.
<div id="gmap-holder">
<iframe width="100%" height="400" frameborder="0" style="border:0; pointer-events:none"
src="https://www.google.com/maps/embed/v1/place?q=XXX&key=YYY"></iframe>
</div>
사용자가지도를 클릭 할 때 마우스 스크롤이 활성화되도록하려면 다음 JS 코드를 사용하십시오. 또한 마우스가지도 밖으로 이동하면 마우스 스크롤이 다시 비활성화됩니다.
$(function() {
$('#gmap-holder').click(function(e) {
$(this).find('iframe').css('pointer-events', 'all');
}).mouseleave(function(e) {
$(this).find('iframe').css('pointer-events', 'none');
});
})
내장 된 Google지도에서 마우스 스크롤 휠 줌을 비활성화하려면 iframe의 css 속성 포인터 이벤트를 none으로 설정하면됩니다.
<style>
#googlemap iframe {
pointer-events:none;
}
</style>
그게 다 .. 꽤 깔끔한 응?
<div id="googlemap">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3648.6714814904954!2d90.40069809681577!3d23.865796688563787!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3755c425897f1f09%3A0x2bdfa71343f07395!2sArcadia+Green+Point%2C+Rd+No.+16%2C+Dhaka+1230%2C+Bangladesh!5e0!3m2!1sen!2sin!4v1442184916780" width="400" height="300" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
글쎄, 나에게 가장 좋은 해결책은 단순히 다음과 같이 사용하는 것이 었습니다.
HTML :
<div id="google-maps">
<iframe frameborder="0" height="450" src="***embed-map***" width="100"</iframe>
</div>
CSS :
#google-maps iframe { pointer-events:none; }
JS :
<script>
$(function() {
$('#google-maps').click(function(e) {
$(this).find('iframe').css('pointer-events', 'auto');
}).mouseleave(function(e) {
$(this).find('iframe').css('pointer-events', 'none');
});
})
</script>
고려 사항 :
가장 좋은 방법은 텍스트가있는 어두운 투명도를 가진 오버레이를 추가하는 것입니다. 마우스 휠이 비활성화 될 때 " 클릭하여 찾아보기 " 그러나 활성화 된 경우 (클릭 한 후) 텍스트가있는 투명도가 사라지고 사용자가 찾아 볼 수 있습니다 예상대로지도. 그 방법에 대한 단서가 있습니까?
pointer-events:none;
잘 작동하는 스타일 추가
<iframe style="pointer-events:none;" src=""></iframe>
가장 간단한 방법은 :before
또는 같은 유사 요소를 사용하는 것 :after
입니다.
이 메소드에는 추가 html 요소 또는 jquery가 필요하지 않습니다.
우리가 예를 들어이 html 구조를 가지고 있다면 :
<div class="map_wraper">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d405689.7826944034!2d-122.04109805!3d37.40280355!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x808fb68ad0cfc739%3A0x7eb356b66bd4b50e!2sSilicon+Valley%2C+CA!5e0!3m2!1sen!2sro!4v1438864791455" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
</div>
그런 다음 스크롤을 방지하기 위해 생성 할 의사 요소를 기준으로 래퍼를 만들면됩니다.
.map_wraper{
position:relative;
}
그런 다음 스크롤을 방지하기 위해지도 위에 위치 할 의사 요소를 만듭니다.
.map_wraper:after{
background: none;
content: " ";
display: inline-block;
font-size: 0;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
top: 0;
width: 100%;
z-index: 9;
}
그리고 당신은 jquery없이 추가 html 요소가 없습니다! 다음은 작동하는 jsfiddle 예제입니다. http://jsfiddle.net/e6j4Lbe1/
여기 내 간단한 해결책이 있습니다.
예를 들어 "maps"라는 클래스가있는 div에 iframe을 넣습니다.
이것은 iframe의 CSS가 될 것입니다
.maps iframe { pointer-events: none }
그리고 여기에 div 요소를 적어도 1 초 동안 움직일 때 (나를 위해 가장 잘 작동합니다-원하는대로 설정하십시오) 시간 초과 / 마우스가 요소를 떠날 때 다시 "없음"으로 설정하십시오.
var maptimer;
$(".maps").hover(function(){
maptimer = setTimeout(function(){
$(".maps").find("iframe").css("pointer-events", "auto");
},1000);
},function(){
clearTimeout(maptimer);
$(".maps").find("iframe").css("pointer-events", "none");
});
건배.
문제를 해결하기 위해 매우 간단한 jQuery 플러그인을 만들었습니다. https://diazemiliano.github.io/googlemaps-scrollprevent 에서 확인 하십시오.
(function() {
$(function() {
$("#btn-start").click(function() {
$("iframe[src*='google.com/maps']").scrollprevent({
printLog: true
}).start();
return $("#btn-stop").click(function() {
return $("iframe[src*='google.com/maps']").scrollprevent().stop();
});
});
return $("#btn-start").trigger("click");
});
}).call(this);
Edit in JSFiddle Result JavaScript HTML CSS .embed-container {
position: relative !important;
padding-bottom: 56.25% !important;
height: 0 !important;
overflow: hidden !important;
max-width: 100% !important;
}
.embed-container iframe {
position: absolute !important;
top: 0 !important;
left: 0 !important;
width: 100% !important;
height: 100% !important;
}
.mapscroll-wrap {
position: static !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/diazemiliano/googlemaps-scrollprevent/v.0.6.5/dist/googlemaps-scrollprevent.min.js"></script>
<div class="embed-container">
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d12087.746318586604!2d-71.64614110000001!3d-40.76341959999999!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x9610bf42e48faa93%3A0x205ebc786470b636!2sVilla+la+Angostura%2C+Neuqu%C3%A9n!5e0!3m2!1ses-419!2sar!4v1425058155802"
width="400" height="300" frameborder="0" style="border:0"></iframe>
</div>
<p><a id="btn-start" href="#">"Start Scroll Prevent"</a> <a id="btn-stop" href="#">"Stop Scroll Prevent"</a>
</p>
@nathanielperales의 답변을 사용하여 호버 기능을 추가했습니다. 사용자가 다시 스크롤을 멈추기 위해 맵에 초점을 잃을 때 더 잘 작동합니다. :)
$(function(){
$('.mapa').hover(function(){
stopScroll();},
function () {
$('.mapa iframe').css("pointer-events", "none");
});
});
function stopScroll(){
$('.mapa').click(function () {
$('.mapa iframe').css("pointer-events", "auto");
});
}
테마의 변형 : jQuery를 사용한 간단한 솔루션으로 CSS 편집이 필요하지 않습니다.
// make iframe active on click, disable on mouseleave
$('iframe.google_map').each( function(i, iframe) {
$(iframe).parent().hover( // make inactive on hover
function() { $(iframe).css('pointer-events', 'none');
}).click( // activate on click
function() { $(iframe).css('pointer-events', 'auto');
}).trigger('mouseover'); // make it inactive by default as well
});
호버 리스너는 부모 요소에 연결되어 있으므로 현재 부모가 더 큰 경우 iframe을 3 번째 줄 앞에 div로 래핑하면됩니다.
누군가에게 도움이되기를 바랍니다.
나는이 문제를 스스로 발견 했고이 질문에 대한 두 가지 매우 유용한 답변 인 czerasz 의 답변과 massa 의 답변 중 일부를 사용했습니다.
둘 다 많은 진실을 가지고 있지만 내 테스트 어딘가에서 모바일에서 작동하지 않으며 IE 지원이 부족하다는 것을 알았습니다 (IE11에서만 작동 함). 이것은 nathanielperales의 솔루션이며 czerasz에 의해 확장됩니다 .czerasz는 포인터 이벤트 CSS에 의존하며 모바일에서는 작동하지 않으며 (모바일에는 포인터가 없음) v11이 아닌 IE 버전 에서는 작동하지 않습니다 . 일반적으로 덜 신경 쓰지 않지만 많은 사용자가 있으며 일관된 기능을 원하므로 래퍼를 사용하여 코딩하기 쉽도록 오버레이 솔루션을 사용했습니다.
내 마크 업은 다음과 같습니다.
<div class="map embed-container">
<div id="map-notice" style="display: block;"> {Tell your users what to do!} </div>
<div class="map-overlay" style="display: block;"></div>
<iframe style="width:100%" src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3785.684302567802!2d-66.15578327375803!3d18.40721382009222!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x8c036a35d02b013f%3A0x5962cad95b9ec7f8!2sPlaza+Del+Sol!5e0!3m2!1sen!2spr!4v1415284687548" width="633" height="461" frameborder="0"></iframe>
</div>
그런 다음 스타일은 다음과 같습니다.
.map.embed-container {
position:relative;
}
.map.embed-container #map-notice{
position:absolute;
right:0;
top:0;
background-color:rgb(100,100,100);/*for old IE browsers with no support for rgba()*/
background-color: rgba(0,0,0,.50);
color: #ccc;
padding: 8px;
}
.map.embed-container .map-overlay{
height:100%;
width:100%;
position:absolute;
z-index:9999;
background-color:rgba(0,0,0,0.10);/*should be transparent but this will help you see where the overlay is going in relation with the markup*/
}
마지막으로 스크립트 :
//using jquery...
var onMapMouseleaveHandler = function (event) {
$('#map-notice').fadeIn(500);
var elemento = $$(this);
elemento.on('click', onMapClickHandler);
elemento.off('mouseleave', onMapMouseleaveHandler);
$('.map-overlay').fadeIn(500);
}
var onMapClickHandler = function (event) {
$('#map-notice').fadeOut(500);
var elemento = $$(this);
elemento.off('click', onMapClickHandler);
$('.map-overlay').fadeOut(500);
elemento.on('mouseleave', onMapMouseleaveHandler);
}
$('.map.embed-container').on('click', onMapClickHandler);
또한 테스트 된 솔루션을 GitHub 요지 에 추가 했습니다.
이것은 CSS 및 Javascript 솔루션입니다 (예 : Jquery이지만 순수한 Javascript에서도 작동). 동시에 맵이 반응합니다. 스크롤 할 때지도를 확대 / 축소하지 말고 클릭하면지도를 활성화 할 수 있습니다.
HTML / JQuery 자바 스크립트
<div id="map" onclick="$('#googlemap').css('pointerEvents','auto'); return true;">
<iframe id="googlemap" src="http://your-embed-url" height="350"></iframe>
</div>
CSS
#map {
position: relative;
padding-bottom: 36%; /* 16:9 ratio for responsive */
height: 0;
overflow: hidden;
background:transparent; /* does the trick */
z-index:98; /* does the trick */
}
#map iframe {
pointer-events:none; /* does the trick */
position: absolute;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
z-index:97; /* does the trick */
}
즐기세요!
Google Maps v3에서는 스크롤하여 확대 / 축소를 사용 중지하여 훨씬 더 나은 사용자 환경을 제공 할 수 있습니다. 다른지도 기능은 여전히 작동하며 추가 div가 필요하지 않습니다. 또한 스크롤이 활성화 된 경우 사용자가 볼 수 있도록 피드백이 있어야한다고 생각했기 때문에지도 테두리를 추가했습니다.
// map is the google maps object, '#map' is the jquery selector
preventAccidentalZoom(map, '#map');
// Disables and enables scroll to zoom as appropriate. Also
// gives the user a UI cue as to when scrolling is enabled.
function preventAccidentalZoom(map, mapSelector){
var mapElement = $(mapSelector);
// Disable the scroll wheel by default
map.setOptions({ scrollwheel: false })
// Enable scroll to zoom when there is a mouse down on the map.
// This allows for a click and drag to also enable the map
mapElement.on('mousedown', function () {
map.setOptions({ scrollwheel: true });
mapElement.css('border', '1px solid blue')
});
// Disable scroll to zoom when the mouse leaves the map.
mapElement.mouseleave(function () {
map.setOptions({ scrollwheel: false })
mapElement.css('border', 'none')
});
};
그러면 iframe에서 스크롤이 중지되는 반응 형 Google지도가 제공되지만 클릭하면 확대 / 축소 할 수 있습니다.
이것을 복사하여 HTML에 붙여 넣으 되 iframe 링크를 자신의 것으로 바꾸십시오. 그는 예를 들어 기사를 작성했습니다 . 내장 된 Google Map iframe에서 마우스 스크롤 휠 확대 / 축소 비활성화
<style>
.overlay {
background:transparent;
position:relative;
width:100%; /* your iframe width */
height:480px; /* your iframe height */
top:480px; /* your iframe height */
margin-top:-480px; /* your iframe height */
}
</style>
<div class="overlay" onClick="style.pointerEvents='none'"></div>
<iframe src="https://mapsengine.google.com/map/embed?mid=some_map_id" width="100%" height="480"></iframe>
여기에 내 접근 방식이 있습니다.
이것을 main.js 또는 유사한 파일에 넣으십시오.
// Create an array of styles.
var styles = [
{
stylers: [
{ saturation: -300 }
]
},{
featureType: 'road',
elementType: 'geometry',
stylers: [
{ hue: "#16a085" },
{ visibility: 'simplified' }
]
},{
featureType: 'road',
elementType: 'labels',
stylers: [
{ visibility: 'off' }
]
}
],
// Lagitute and longitude for your location goes here
lat = -7.79722,
lng = 110.36880,
// Create a new StyledMapType object, passing it the array of styles,
// as well as the name to be displayed on the map type control.
customMap = new google.maps.StyledMapType(styles,
{name: 'Styled Map'}),
// Create a map object, and include the MapTypeId to add
// to the map type control.
mapOptions = {
zoom: 12,
scrollwheel: false,
center: new google.maps.LatLng( lat, lng ),
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP],
}
},
map = new google.maps.Map(document.getElementById('map'), mapOptions),
myLatlng = new google.maps.LatLng( lat, lng ),
marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: "images/marker.png"
});
//Associate the styled map with the MapTypeId and set it to display.
map.mapTypes.set('map_style', customMap);
map.setMapTypeId('map_style');
그런 다음 페이지에지도를 표시 할 빈 div를 삽입하십시오.
<div id="map"></div>
Google Maps API도 호출해야합니다. mapi.js라는 파일을 만들고 내 / js 폴더에 넣었습니다. 이 파일은 위의 자바 스크립트 전에 호출해야합니다.
`window.google = window.google || {};
google.maps = google.maps || {};
(function() {
function getScript(src) {
document.write('<' + 'script src="' + src + '"' +
' type="text/javascript"><' + '/script>');
}
var modules = google.maps.modules = {};
google.maps.__gjsload__ = function(name, text) {
modules[name] = text;
};
google.maps.Load = function(apiLoad) {
delete google.maps.Load;
apiLoad([0.009999999776482582,[[["http://mt0.googleapis.com/vt?lyrs=m@228000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=m@228000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@228000000"],[["http://khm0.googleapis.com/kh?v=135\u0026hl=en-US\u0026","http://khm1.googleapis.com/kh?v=135\u0026hl=en-US\u0026"],null,null,null,1,"135"],[["http://mt0.googleapis.com/vt?lyrs=h@228000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=h@228000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"h@228000000"],[["http://mt0.googleapis.com/vt?lyrs=t@131,r@228000000\u0026src=api\u0026hl=en-US\u0026","http://mt1.googleapis.com/vt?lyrs=t@131,r@228000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@131,r@228000000"],null,null,[["http://cbk0.googleapis.com/cbk?","http://cbk1.googleapis.com/cbk?"]],[["http://khm0.googleapis.com/kh?v=80\u0026hl=en-US\u0026","http://khm1.googleapis.com/kh?v=80\u0026hl=en-US\u0026"],null,null,null,null,"80"],[["http://mt0.googleapis.com/mapslt?hl=en-US\u0026","http://mt1.googleapis.com/mapslt?hl=en-US\u0026"]],[["http://mt0.googleapis.com/mapslt/ft?hl=en-US\u0026","http://mt1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["http://mt0.googleapis.com/vt?hl=en-US\u0026","http://mt1.googleapis.com/vt?hl=en-US\u0026"]],[["http://mt0.googleapis.com/mapslt/loom?hl=en-US\u0026","http://mt1.googleapis.com/mapslt/loom?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]]],["en-US","US",null,0,null,null,"http://maps.gstatic.com/mapfiles/","http://csi.gstatic.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/en_us/mapfiles/api-3/14/0","3.14.0"],[2635921922],1,null,null,null,null,0,"",null,null,0,"http://khm.googleapis.com/mz?v=135\u0026",null,"https://earthbuilder.googleapis.com","https://earthbuilder.googleapis.com",null,"http://mt.googleapis.com/vt/icon",[["http://mt0.googleapis.com/vt","http://mt1.googleapis.com/vt"],["https://mts0.googleapis.com/vt","https://mts1.googleapis.com/vt"],[null,[[0,"m",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],0],[null,[[0,"m",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],3],[null,[[0,"h",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],0],[null,[[0,"h",228000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],3],[null,[[4,"t",131],[0,"r",131000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],0],[null,[[4,"t",131],[0,"r",131000000]],[null,"en-US","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],3],[null,null,[null,"en-US","US",null,18],0],[null,null,[null,"en-US","US",null,18],3],[null,null,[null,"en-US","US",null,18],6],[null,null,[null,"en-US","US",null,18],0]]], loadScriptTime);
};
var loadScriptTime = (new Date).getTime();
getScript("http://maps.gstatic.com/intl/en_us/mapfiles/api-3/14/0/main.js");
})();`
mapi.js 파일을 호출 할 때 센서 false 속성을 전달하십시오.
즉 : <script type="text/javascript" src="js/mapi.js?sensor=false"></script>
API의 새로운 버전 3은 어떤 이유로 센서를 포함해야합니다. main.js 파일 앞에 mapi.js 파일을 포함시켜야합니다.
Google지도 v2-GMap2의 경우 :
ar map = new GMap2(document.getElementById("google_map"));
map.disableScrollWheelZoom();
다음과 같이 Google지도 내장 API를 사용하는 iframe이있는 경우 :
<iframe width="320" height="400" frameborder="0" src="https://www.google.com/maps/embed/v1/place?q=Cagli ... "></iframe>
이 CSS 스타일을 추가 할 수 있습니다 : pointer-event : none; ES.
<iframe width="320" height="400" frameborder="0" style="pointer-event:none;" src="https://www.google.com/maps/embed/v1/place?q=Cagli ... "></iframe>
@chams에 의해 확장 된 @nathanielperales 답변에 대한 나의 견해는 다음과 같습니다.
HTML
<div class='embed-container maps'>
<iframe width='600' height='450' frameborder='0' src='http://foo.com'></iframe>
</div>
jQuery
// we're doing so much with jQuery already, might as well set the initial state
$('.maps iframe').css("pointer-events", "none");
// as a safety, allow pointer events on click
$('.maps').click(function() {
$(this).find('iframe').css("pointer-events", "auto");
});
$('.maps').mouseleave(function() {
// set the default again on mouse out - disallow pointer events
$(this).find('iframe').css("pointer-events", "none");
// unset the comparison data so it doesn't effect things when you enter again
$(this).removeData('oldmousepos');
});
$('.maps').bind('mousemove', function(e){
$this = $(this);
// check the current mouse X position
$this.data('mousepos', e.pageX);
// set the comparison data if it's null or undefined
if ($this.data('oldmousepos') == null) {
$this.data('oldmousepos', $this.data('mousepos'));
}
setTimeout(function(){
// some left/right movement - allow pointer events
if ($this.data('oldmousepos') != $this.data('mousepos')) {
$this.find('iframe').css("pointer-events", "auto");
}
// set the compairison variable
$this.data('oldmousepos', $this.data('mousepos'));
}, 300);
console.log($this.data('oldmousepos')+ ' ' + $this.data('mousepos'));
});
가장 간단한 것 :
<div id="myIframe" style="width:640px; height:480px;">
<div style="background:transparent; position:absolute; z-index:1; width:100%; height:100%; cursor:pointer;" onClick="style.pointerEvents='none'"></div>
<iframe src="https://www.google.com/maps/d/embed?mid=XXXXXXXXXXXXXX" style="width:640px; height:480px;"></iframe>
</div>
이것을 스크립트에 추가하십시오 :
function initMap() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: uluru,
scrollwheel: false,
disableDefaultUI: true,
disableDoubleClickZoom: true
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
}
여기에 문제에 대한 해결책이 있습니다 .WP 사이트를 만들고 있었으므로 여기에 약간의 PHP 코드가 있습니다. 그러나 키는 scrollwheel: false,
지도 객체에 있습니다.
function initMap() {
var uluru = {lat: <?php echo $latitude; ?>, lng: <?php echo $Longitude; ?>};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 18,
scrollwheel: false,
center: uluru
});
var marker = new google.maps.Marker({
position: uluru,
map: map
});
}
이것이 도움이되기를 바랍니다. 건배
참고 URL : https://stackoverflow.com/questions/21992498/disable-mouse-scroll-wheel-zoom-on-embedded-google-maps
전체 응용 프로그램을 세로 모드로만 설정하는 방법은 무엇입니까?
응용 프로그램이 세로 모드로만 실행되도록 설정하려면 어떻게합니까? 응용 프로그램이 실행되는 동안 가로 모드를 비활성화하고 싶습니다. 프로그래밍 방식으로 어떻게합니까?
모든 안드로이드 버전
XML에서android:screenOrientation="portrait"
manifest.xml 파일에서 각 활동에 대해 지정할 수 있습니다 . application
태그 에는이 옵션을 지정할 수 없습니다 .
다른 옵션은 예를 들어 Activity
기본 클래스 에서 프로그래밍 방식으로 수행하는 것입니다 .
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Android 4 이상 (API 14 이상)
마지막 옵션은 Android 4.0 (API 14+) 이후에만 사용 가능한 활동 라이프 사이클 리스너로 수행하는 것입니다. 모든 것은 커스텀 Application
클래스 에서 발생합니다 :
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(new ActivityLifecycleAdapter() {
@Override
public void onActivityCreated(Activity a, Bundle savedInstanceState) {
a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
});
}
ActivityLifecycleAdapter
는 빈 구현이 될 생성 해야하는 도우미 클래스 일뿐입니다 ActivityLifecycleCallbacks
(따라서 단순히 인터페이스 중 하나가 필요할 때 해당 인터페이스의 모든 메소드를 재정의 할 필요는 없습니다).
예, 프로그래밍 방식과 모든 활동 모두 에서이 작업을 수행하여 모든 활동이 확장되는 AbstractActivity를 만들 수 있습니다.
public abstract class AbstractActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
이 추상 활동은 글로벌 메뉴에도 사용할 수 있습니다.
모든 활동을 공통 기본 클래스로 확장 하지 않고도 전체 애플리케이션에 대해이를 수행 할 수 있습니다 .
트릭은 먼저 Application
프로젝트에 서브 클래스 를 포함시키는 것 입니다. 에서 onCreate()
앱이 처음 시작될 때 호출되는 ActivityLifecycleCallbacks
활동 수명주기 이벤트 알림을 수신 하도록 객체 (API 레벨 14+)를 등록 합니다.
이렇게하면 때마다 자신의 코드를 실행할 수있는 기회를 제공합니다 모든 앱에서 활동이 시작 (또는 중지 또는 재개, 또는 무엇이든)됩니다. 이 시점 setRequestedOrientation()
에서 새로 생성 된 활동을 호출 할 수 있습니다 .
class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// register to be informed of activities starting up
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity,
Bundle savedInstanceState) {
// new activity created; force its orientation to portrait
activity.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
....
});
}
}
매니페스트 파일에서이를 설정할 수 있습니다.
android:name=".your launching activity name"
android:screenOrientation="portrait"
클래스 파일에 다음과 같이 코드를 작성하여 동일하게 달성 할 수도 있습니다.
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
AndroidManifest.xml의 활동에 android : screenOrientation = "portrait"를 추가하십시오. 예를 들면 다음과 같습니다.
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
사용하다:
android:screenOrientation="portrait"
세로 모드로만 표시하려는 각 활동의 응용 프로그램 매니페스트 파일에이 줄을 작성하십시오.
모든 활동에 대해 매니페스트 파일에 이것을 작성하십시오.
android:screenOrientation="portrait"
안드로이드 개발자 가이드에서와 같이 :
"orientation" The screen orientation has changed — the user has rotated the device. Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.
"screenSize" The current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device). Added in API level 13.
So, in the AndroidManifest.xml file, we can put:
<activity
android:name=".activities.role_activity.GeneralViewPagerActivity"
android:label="@string/title_activity_general_view_pager"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"
>
</activity>
Adding <preference name="orientation" value="portrait" />
under <widget>
in my config.xml worked for me.
(The other solutions either didn't work on my device, were overwritten during building or gave deprecation errors during the build process.)
in Manifest file which activity you want to use in "portrait" you must write these code in Activity tag
android:screenOrientation="portrait"
like this
android:icon="@drawable/icon"
android:name="com.zemkoapps.hd.wallpaper.AndroidGridLayoutActivity"
android:screenOrientation="portrait" >
but if u want screen in landscape use this code like this
android:screenOrientation="landscape"
If anyone was wondering , how you could do this for your entire application without having to make all your activities extend a common base class in Kotlin , see the example below :
class InteractiveStoryApplication: Application() {
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(object: ActivityLifecycleCallbacks {
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
override fun onActivityPaused(activity: Activity?) {
}
override fun onActivityResumed(activity: Activity?) {
}
override fun onActivityDestroyed(activity: Activity?) {
}
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {
}
override fun onActivityStarted(activity: Activity?) {
}
override fun onActivityStopped(activity: Activity?) {
}
})
}
}
and then you have to add your common base class in AndroidManifest like so:
<application android:allowBackup="true"
android:name=".InteractiveStoryApplication"
You can do it in two ways .
- Add
android:screenOrientation="portrait"
on your manifest file to the corresponding activity - Add
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
to your activity in `onCreate() method
Similar to Graham Borland answer...but it seems you dont have to create Application class if you dont want...just create a Base Activity in your project
public class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
And extend this class instead of AppCompatActivity where you want to use Potrait Mode
public class your_activity extends BaseActivity {}
For Xamarin Users:
If you extends all your activities to a BaseActivity
Just add:
this.RequestedOrientation = ScreenOrientation.Portrait;
This will resolve the problem. If you want any particular activity to be in landscape override this in OnActivityCreated
. As:
this.Activity.RequestedOrientation = ScreenOrientation.Landscape;
In your Manifest type this:
<activity
android:screenOrientation="portrait"
<!--- Rest of your application information ---!>
</activity>
참고URL : https://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only
'Programming' 카테고리의 다른 글
Type.GetType (“namespace.abClassName”)은 null을 반환합니다. (0) | 2020.05.09 |
---|---|
레일즈-컨트롤러 안에서 헬퍼를 사용하는 방법 (0) | 2020.05.09 |
jquery를 사용하여 특정 클래스 이름을 가진 모든 확인란을 선택하십시오. (0) | 2020.05.09 |
데이트에 하루를 추가하는 방법? (0) | 2020.05.09 |
PHP에서 다차원 배열을 정렬하는 방법 (0) | 2020.05.09 |