简体   繁体   English

谷歌地图切换层开始

[英]google maps toggle layer starting off

http://deepfrogphoto.com/Brett-Pelletier-Photography/Links/maps/wasatch/index07.html http://deepfrogphoto.com/Brett-Pelletier-Photography/Links/maps/wasatch/index07.html

My page above is working fine, but I would really like it if the black and white map kml layer would start as being off forcing the user to toggle it on.我上面的页面工作正常,但如果黑白地图 kml 图层开始关闭以强制用户打开它,我真的很喜欢它。 I have a lot going on with this map and I'm pretty lost with all the code.我在这张地图上有很多事情要做,我对所有的代码都感到很迷茫。 If you go to my site and click the layer button the first option is the BW MAP toggle.如果您转到我的站点并单击图层按钮,第一个选项是 BW MAP 切换。 I just want the page to load with the BW MAP kml layer off.我只想在关闭 BW MAP kml 层的情况下加载页面。 I've tried several of the options I found on this site, but still just trial and error with no luck.... I think this is most of the code you might need to help...我已经尝试了我在这个网站上找到的几个选项,但仍然只是反复试验,没有运气......我认为这是你可能需要帮助的大部分代码......

EDIT - it might be easier to 'not accept' the geolocation so you can see what is going on where I'm at.编辑 - “不接受”地理位置可能更容易,这样你就可以看到我所在的地方发生了什么。 the map will load in the area without it enabled....地图将在未启用的情况下加载到该区域....

var map, GeoMarker;

function HomeControl(controlDiv, map) {
controlDiv.style.padding = '5px';
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = 'white';
controlUI.style.borderStyle = 'solid';
controlUI.style.borderWidth = '1px';
controlUI.style.cursor = 'pointer';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to set the map to GPS Center';
controlDiv.appendChild(controlUI);
var controlText = document.createElement('div');
controlText.style.fontFamily = 'Arial,sans-serif';
controlText.style.fontSize = '11px';
controlText.style.paddingLeft = '4px';
controlText.style.paddingRight = '4px';
controlText.innerHTML = '<b>Home</b>';
controlUI.appendChild(controlText);

google.maps.event.addDomListener(controlUI, 'click', function() {
recenterMapOnGeoLoc()
});
}

function toggleLayer(this_layer) {
if (this_layer.getMap()) {
this_layer.setMap(null)
} else {
this_layer.setMap(map);
}
}

function recenterMapOnGeoLoc() {
map.setCenter(GeoMarker.getPosition());
}

function initialize() {
var mapDiv = document.getElementById('map_canvas');
var mapOptions = {
zoom: 20,
center: new google.maps.LatLng(40.563855, -111.675426),
mapTypeId: google.maps.MapTypeId.TERRAIN
};

map = new google.maps.Map(mapDiv, mapOptions);

GeoMarker = new GeolocationMarker();
GeoMarker.setCircleOptions({
fillColor: '#EBF4FA'
});

google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
map.setCenter(this.getPosition());
map.fitBounds(this.getBounds());
});

google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
alert('There was an error obtaining your position. Message: ' + e.message);
});

GeoMarker.setMap(map);

trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);

layer1 = new google.maps.FusionTablesLayer({
map: map,
heatmap: {
enabled: false
},
query: {
select: "skilines",
from: "1R5pCEyNN74N8Dt9MkfNXA6A9D1HbQESzOR1fYFa7",
 where: ""
 },
options: {
styleId: 2,
templateId: 2
}
});


layer2 = new google.maps.FusionTablesLayer({
map: map,
heatmap: {
enabled: false
},
query: {
from: "19iu58FDFcBIZZ-wU1iZcf89AI5ABDJ7YTv355su5",
where: ""
},
options: {
styleId: 2,
templateId: 2
}
});

layer3 = new google.maps.FusionTablesLayer({
map: map,
heatmap: {
enabled: false
},
query: {
select: "summerhiking",
from: "1t1XNnG7J7Zu1p5mIUpm6qIGVYwzhkCgPy_je0IKr",
where: ""
},
options: {
styleId: 2,
templateId: 2
}
});


layer5 = new google.maps.KmlLayer('http://deepfrogphoto.com/Brett-Pelletier-            Photography/Links/maps/kml/topobwkml.kml',
              {
                  suppressInfoWindows: true,
                  map: map,
                  preserveViewport: true
              });  

                                // Create the DIV to hold the control and
  // call the HomeControl() constructor passing
  // in this DIV.
  var homeControlDiv = document.createElement('div');
  var homeControl = new HomeControl(homeControlDiv, map);

  homeControlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);     

}

google.maps.event.addDomListener(window, 'load', initialize);

if (!navigator.geolocation) {
alert('Your browser does not support geolocation');
}

  //////////////And the menu code is....

  <li><a><input checked="checked" id="show_hide_layer5" onchange="toggleLayer(layer5)"      type="checkbox" value="ON" /> B+W Map</a> </li>
            <li><a><input checked="checked" id="show_hide_layer1" onchange="toggleLayer(layer1)"   type="checkbox" value="ON" /> Backcountry Ski Lines</a> </li>
            <li><a><input checked="checked" id="show_hide_layer2" onchange="toggleLayer(layer2)" type="checkbox" value="ON" /> Resort Lifts</a> </li>
                            <li><a><input checked="checked" id="show_hide_layer3" onchange="toggleLayer(layer3)" type="checkbox" value="ON" /> Summer Trails</a> </li>
                            <li><a><input checked="checked" id="show_hide_layer4" onchange="toggleLayer(layer4)" type="checkbox" value="ON" /> Snow Stations</a> </li>
                            <li><a><input checked="checked" id="show_hide_layer4" onchange="toggleLayer(trafficLayer)" type="checkbox" value="ON" /> Traffic</a> </li>"

If you don't want your layers displayed when you create them, don't add them to the map (remove the {map: map} property (and don't set the checkboxes to "checked").如果您不希望在创建图层时显示图层,请不要将它们添加到地图(删除{map: map}属性(并且不要将复选框设置为“已选中”)。

 var map, GeoMarker, layer1, layer2, layer3, layer4, layer5; function HomeControl(controlDiv, map) { controlDiv.style.padding = '5px'; var controlUI = document.createElement('div'); controlUI.style.backgroundColor = 'white'; controlUI.style.borderStyle = 'solid'; controlUI.style.borderWidth = '1px'; controlUI.style.cursor = 'pointer'; controlUI.style.textAlign = 'center'; controlUI.title = 'Click to set the map to GPS Center'; controlDiv.appendChild(controlUI); var controlText = document.createElement('div'); controlText.style.fontFamily = 'Arial,sans-serif'; controlText.style.fontSize = '11px'; controlText.style.paddingLeft = '4px'; controlText.style.paddingRight = '4px'; controlText.innerHTML = '<b>Home</b>'; controlUI.appendChild(controlText); google.maps.event.addDomListener(controlUI, 'click', function() { recenterMapOnGeoLoc() }); } function toggleLayer(this_layer) { if (this_layer.getMap()) { this_layer.setMap(null) } else { this_layer.setMap(map); } } function recenterMapOnGeoLoc() { map.setCenter(GeoMarker.getPosition()); } function initialize() { var mapDiv = document.getElementById('map_canvas'); var mapOptions = { zoom: 20, center: new google.maps.LatLng(40.563855, -111.675426), mapTypeId: google.maps.MapTypeId.TERRAIN }; map = new google.maps.Map(mapDiv, mapOptions); GeoMarker = new GeolocationMarker(); GeoMarker.setCircleOptions({ fillColor: '#EBF4FA' }); google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() { map.setCenter(this.getPosition()); map.fitBounds(this.getBounds()); }); google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) { alert('There was an error obtaining your position. Message: ' + e.message); }); GeoMarker.setMap(map); trafficLayer = new google.maps.TrafficLayer(); // trafficLayer.setMap(map); layer1 = new google.maps.FusionTablesLayer({ // map: map, heatmap: { enabled: false }, query: { select: "skilines", from: "1R5pCEyNN74N8Dt9MkfNXA6A9D1HbQESzOR1fYFa7", where: "" }, options: { styleId: 2, templateId: 2 } }); layer2 = new google.maps.FusionTablesLayer({ // map: map, heatmap: { enabled: false }, query: { from: "19iu58FDFcBIZZ-wU1iZcf89AI5ABDJ7YTv355su5", where: "" }, options: { styleId: 2, templateId: 2 } }); layer3 = new google.maps.FusionTablesLayer({ // map: map, heatmap: { enabled: false }, query: { select: "summerhiking", from: "1t1XNnG7J7Zu1p5mIUpm6qIGVYwzhkCgPy_je0IKr", where: "" }, options: { styleId: 2, templateId: 2 } }); layer5 = new google.maps.KmlLayer('http://deepfrogphoto.com/Brett-Pelletier- Photography/Links/maps/kml/topobwkml.kml', { suppressInfoWindows: true, // map: map, preserveViewport: true }); // Create the DIV to hold the control and // call the HomeControl() constructor passing // in this DIV. var homeControlDiv = document.createElement('div'); var homeControl = new HomeControl(homeControlDiv, map); homeControlDiv.index = 1; map.controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv); } google.maps.event.addDomListener(window, 'load', initialize); if (!navigator.geolocation) { alert('Your browser does not support geolocation'); }
 <script src="https://maps.googleapis.com/maps/api/js"></script> <script src="https://cdn.rawgit.com/googlemaps/v3-utility-library/master/geolocationmarker/src/geolocationmarker.js"></script> <li> <a> <input id="show_hide_layer5" onchange="toggleLayer(layer5)" type="checkbox" value="ON" />B+W Map</a> </li> <li> <a> <input id="show_hide_layer1" onchange="toggleLayer(layer1)" type="checkbox" value="ON" />Backcountry Ski Lines</a> </li> <li> <a> <input id="show_hide_layer2" onchange="toggleLayer(layer2)" type="checkbox" value="ON" />Resort Lifts</a> </li> <li> <a> <input id="show_hide_layer3" onchange="toggleLayer(layer3)" type="checkbox" value="ON" />Summer Trails</a> </li> <li> <a> <input id="show_hide_layer4" onchange="toggleLayer(layer4)" type="checkbox" value="ON" />Snow Stations</a> </li> <li> <a> <input id="show_hide_layer4" onchange="toggleLayer(trafficLayer)" type="checkbox" value="ON" />Traffic</a> </li> <div id="map_canvas" style="height:500px; width:500px;"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM