V2, 구글 지도 API 의 경우 단순히 내가 하고 싶은 일을 모두 분리하십시오 맵핑에 대한 표시자는 같아.
map.clearOverlays();
참조입니다 apiu # 39 에 보면, it& 다는일은 분명하지 않다.
단순히 방법은 다음과 같습니다.
I. 너희가운데 전역 변수:
var markersArray = [];
II. 함수를 정의하는:
function clearOverlays() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
또는
google.maps.Map.prototype.clearOverlays = function() {
for (var i = 0; i < markersArray.length; i++ ) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
III. # 39, & # 39 는 누름식 표시자는 markerArray&. 호출하기 전에 다음과 같습니다.
markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});
IV. Security. ',' 또는 ' (), 언제 어디서나 마피클리어오버레이스 클라우버라이스 ()' 기능을 합니다.
동일한 문제입니다. 이 코드는 doesn& # 39 더 이상, 빗나갔다.
> set_map (null) -; 스트마프 (null)
google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i < this.markers.length; i++){
this.markers[i].setMap(null);
}
this.markers = new Array();
};
업데이트되었음 문서를 포함할 수 있는 세부 항목: https://developers.google.com/maps/documentation/javascript/markers # 분리하십시오
이러한 기능을 V3 아직 없는 것으로 보인다.
모든 사람들이 계속 참조입니다 제안하세요 표시자는 맵에서 어레이에서는 있습니다. Em, 그냥 통과 후 삭제할 때 모든 루프 (null) 메서드를 호출 오스트마프 스토리지 및 각 참조입니다.
내 버전:
google.maps.Map.prototype.markers = new Array();
google.maps.Map.prototype.getMarkers = function() {
return this.markers
};
google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i<this.markers.length; i++){
this.markers[i].setMap(null);
}
this.markers = new Array();
};
google.maps.Marker.prototype._setMap = google.maps.Marker.prototype.setMap;
google.maps.Marker.prototype.setMap = function(map) {
if (map) {
map.markers[map.markers.length] = this;
}
this._setMap(map);
}
장점
단점
이 대회는 당초 11일 3월 & # 39 는 모든 솔루션 중 가장 단순한 올린 잉양 당초 14 dell. 15:049 디렉토리보다 사용자에게 원래 질문 응답.
구글 지도 및 2.5 년 뒤 그의 동일한 솔루션을 사용하고 있는 것처럼 v3.18 작동하잖아 매력
markersArray.push(newMarker) ;
while(markersArray.length) { markersArray.pop().setMap(null); }
// No need to clear the array after that.
google.maps.Map.prototype.markers = new Array();
google.maps.Map.prototype.addMarker = function(marker) {
this.markers[this.markers.length] = marker;
};
google.maps.Map.prototype.getMarkers = function() {
return this.markers
};
google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i<this.markers.length; i++){
this.markers[i].setMap(null);
}
this.markers = new Array();
};
그래서 내가 중 1 위, don& # 39 는 사용자 정의 구현에 사용되는 V3 아니했다고 것 같지는 않다.
부인: I did it 를 유지할 수 있지만 이 코드를 기록하지 않고 I forgot 참조입니다 병합되었습니다 when I know where it came from # 39, 그래서 내 codebase don& 없다.
그들은 새 버전 v3 것이 적용부 배열입니다. 다음과 같이.
지켜보리니 샘플링합니다 dell. 오버레이로 개요.
var map;
var markersArray = [];
function initialize() {
var haightAshbury = new google.maps.LatLng(37.7699298, -122.4469157);
var mapOptions = {
zoom: 12,
center: haightAshbury,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
});
}
function addMarker(location) {
marker = new google.maps.Marker({
position: location,
map: map
});
markersArray.push(marker);
}
// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
}
// Shows any overlays currently in the array
function showOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(map);
}
}
}
// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}
이 솔루션은 매우 쉽습니다. 이 방법을 사용할 수 있습니다. 마르크리스트마프 (맵) ','. 여기 있는 정의한 매핑해야 핀 나타납니다.
그래서 설정하면 'null' 이 방법 (마르크리스트마프 (null) ','), 핀 사라지게 된다.
이제 사라질 수 있도록 모든 맵에 표시자는 마녀 낼수있지않나 함수를 작성할 수 있습니다.
방금 배열의 핀 모세야 네 추가합니까 선언하고 '또는' 마커스 오푸쉬 (your_new 핀) 이 코드를 가지고 그 예를 들면 다음과 같습니다.
// Adds a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
}
이는 해당 기능을 설정할 수 있는 모든 표시자는 어레이입니다 마녀 또는 사라질 지도:
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
사라질 수 있는 함수를 'null' 당신의 모든 표시자는 security. 합니다.
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
그리고 당신의 모든 표시자는 제거 및 사라질 경우, 다음과 같은 일련의 표시자는 너회의 재설정하지 합니다
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
이건 내 전체 코드. 그건 내가 할 수 있는 가장 간단한.
<!DOCTYPE html>
<html>
<head>
<title>Remove Markers</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<p>Click on the map to add markers.</p>
<script>
// In the following example, markers appear when the user clicks on the map.
// The markers are stored in an array.
// The user can then click an option to hide, show or delete the markers.
var map;
var markers = [];
function initMap() {
var haightAshbury = {lat: 37.769, lng: -122.446};
map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: haightAshbury,
mapTypeId: 'terrain'
});
// This event listener will call addMarker() when the map is clicked.
map.addListener('click', function(event) {
addMarker(event.latLng);
});
// Adds a marker at the center of the map.
addMarker(haightAshbury);
}
// Adds a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
}
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
// Shows any markers currently in the array.
function showMarkers() {
setMapOnAll(map);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js key=YOUR_API_KEY&callback=initMap">
</script>
</body>
</html>
[구글 개발자] [1] 또는 전체 문서에서 tjkdesign. 수 있습니다, 또한 [구글 개발자 perezhilton.] [2].
[1]: https://developers.google.com/maps/documentation/javascript/examples/marker-remove = en hl? [2]: https://developers.google.com/maps/documentation/javascript/markers = fr hl?
Google& # 39 의 데모 갤러리 방식에 대한 데모 가지고 있다.
http://code.google.com/apis/maps/documentation/javascript/examples/overlay-remove.html
그들이 어떻게 추가 표시자는 com/go/lrvid4005_ps_kr 소스 코드를 볼 수 있습니다.
그들은 긴 얘기를 파선-짧은 표시자는 계속 노드전역 어레이입니다. 그 때, 그들은 루프 선택해제한 / 삭제 및 매입옵션 " 오스트마프 (null) 를 통해 어레이입니다 "; 주어진 표시자가 객체에는 대한.
" Delete"; 이 어레이에는 비워집니다 잘 알려져 있다.
깨끗하고 쉽냐구요 애플리케이션 rolinger& # 39 의 그 답이 있다.
function placeMarkerAndPanTo(latLng, map) {
while(markersArray.length) { markersArray.pop().setMap(null); }
var marker = new google.maps.Marker({
position: latLng,
map: map
});
map.panTo(latLng);
markersArray.push(marker) ;
}
예를 들어 표시자가 제거하는 방법을 찾을 수 있습니다.
https://developers.google.com/maps/documentation/javascript/examples/marker-remove = es hl?
// Add a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
}
// Sets the map on all markers in the array.
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setAllMap(null);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
하지만, 곧 다음 작품을 통해 완벽하게 때 함께 반복적으로 깜박임 선택해제한 오벌레이.
단순히 방법은 다음과 같습니다.
var markersArray = [];
function clearOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
}
}
markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});
계기가 되기를 바라는 데 도움이 될 것입니다.
내가 찾은 마르케르만거 사용하여 라이브러리 프로젝트로 구글 지도 유틸리티에는 라이브러리란 v3 있는 가장 쉬운 방법은.
1. 마르케르만거 설정
mgr = new MarkerManager(map);
google.maps.event.addListener(mgr, 'loaded', function () {
loadMarkers();
});
2. 표시자는 마르케르만거 대한 추가
function loadMarkers() {
var marker = new google.maps.Marker({
title: title,
position: latlng,
icon: icon
});
mgr.addMarker(marker);
mgr.refresh();
}
3. 방금 선택해제하여 표시자는 security. MarkerManger& # 39 의 클레어 마르케스 () '기능을 하는'
mgr.clearMarkers();
깨끗한 반복할 맵 (map) 의 모든 기능을 수행할 수 있는 방법이 있다. 표시자는 (다각형, 함께 폴리라인을 e). [데이터 레이어에는] [1] 의 매핑해야 저장됩니다.
function removeAllMarkers() {
map.data.forEach((feature) => {
feature.getGeometry().getType() === 'Point' ? map.data.remove(feature) : null
});
}
이번 사건을 통해 해당 표시자는 추가되고, [2], [그리던건데 관리자] # 39 의 표시자는 노드전역 어레이입니다 만드시겠습니까 it& s best 를 데이터 생성 또는 밀기 등 표시자는 레이어에는 있습니다.
google.maps.event.addListener(drawingManager, 'overlaycomplete', (e) => {
var newShape = e.overlay;
newShape.type = e.type;
if (newShape.type === 'marker') {
var pos = newShape.getPosition()
map.data.add({ geometry: new google.maps.Data.Point(pos) });
// remove from drawing layer
newShape.setMap(null);
}
});
내가 추천하는 외곽진입 수 있기 때문에 다른 구글리마ps.다타 클래스 두 번째 방법을 사용할 수 있다. [1]: https://developers.google.com/maps/documentation/javascript/reference/data # 데이터 [2]: https://developers.google.com/maps/documentation/javascript/reference/drawing # 드라 윙만거
모든 오벌레이 선택해제하여 표시자는 폴리곤, 등 등.
단순히 사용:
'매핑해야 = new 구글리마ps.마프 (도쿠망스게테레멘트베이드 (map_canvas" ";), 모두),}'
이것은 내가 그렇게 할 수 있는 기능을 작성했습니까 폼 날 지도 애플리케이션:
function clear_Map() {
directionsDisplay = new google.maps.DirectionsRenderer();
//var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: HamptonRoads
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}
모든 생성 기능을 지루려면 표시자는 매핑해야 에서 이 같은 일이.
1.addMarker (위치): 이 기능을 추가하는 데 사용되는 표시자가 지도에
2.clearMarkers (): 이 함수는 모두 분리하십시오 표시자는 매핑해야 에서 어레이로부터 아닌
3.setMapOnAll (맵): 이 기능을 추가하는 데 사용되는 어레이당 표시자는 정보
4.deleteMarkers (): 이 함수는 모든 표시자는 이 어레이에는 Deletes 제거하여 참조입니다 그들에게.
// Adds a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
}
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
이는 구글이 직접 사용 방법을 하나 이상의 예제:
var markers = [];
// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];
자세한 샘플링합니다 확인란 구글 코드 예제:
https://developers.google.com/maps/documentation/javascript/examples/places-searchbox