我需要代替传单中的基本视图(它是世界地图),卫星视图,但我仍然需要能够在它们之间切换?这是如何工作的,有人可以向我解释这个吗?
已安装的模块:
答案 0 :(得分:1)
不使用任何外部插件:
gpxpod.map = new L.Map('map', {
zoomControl: true
});
var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttribution = 'Map data © 2013 <a href="http://openstreetmap'+
'.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
var esriAerialUrl = 'https://server.arcgisonline.com/ArcGIS/rest/services'+
'/World_Imagery/MapServer/tile/{z}/{y}/{x}';
var esriAerialAttrib = 'Tiles © Esri — Source: Esri, i-cubed, '+
'USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the'+
' GIS User Community';
var esriAerial = new L.TileLayer(esriAerialUrl,
{maxZoom: 18, attribution: esriAerialAttrib});
var gUrl = 'http://mt0.google.com/vt/lyrs=s&x={x}&y={y}&z={z}';
var gAttribution = 'google';
var googlesat = new L.TileLayer(gUrl, {maxZoom: 18, attribution: gAttribution});
var baseLayers = {
'OpenStreetMap': osm,
'ESRI Aerial': esriAerial,
'Google map sat': googlesat
}
L.control.layers(baseLayers, {}).addTo(map);
这段代码添加了一个标准控件,用于在切片提供程序层之间切换。它包括两个卫星磁贴提供商。
更多信息:http://leafletjs.com/reference-1.0.3.html#control-layers
答案 1 :(得分:0)
我对我的问题做了一个更详细的例子,但是@JulienV接近我的意思,但这并不完全是我想要的,而且我已经在另一篇文章中找到了他的确切答案。我想要的是知道如何向视图添加更多或更少的地图:
var osmLink = '<a href=\"https://openstreetmap.org\">OpenStreetMap</a>',
thunLink = '<a href=\"https://thunderforest.com/\">Thunderforest</a>';
var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '© ' + osmLink + ' Contributors',
landUrl = 'https://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png',
thunAttrib = '© '+osmLink+' Contributors & '+thunLink;
var osmMap = L.tileLayer(osmUrl, {attribution: osmAttrib}),
landMap = L.tileLayer(landUrl, {attribution: thunAttrib});
var roadmap = L.tileLayer('https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
});
var satellite = L.tileLayer('https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
});
var sat_text = L.tileLayer('https://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',{
maxZoom: 20,
subdomains:['mt0','mt1','mt2','mt3']
});
然后我将每个地图添加到数组中:
if($map_layouts['get_roads']) {
$roads = "\"Roads\": roadmap";
if($baselist == "") {
$baselist = $roads;
} else {
$baselist = $baselist . "," . $roads;
}
}
然后我需要检查$baselist
是否为空:
if($baselist) {
$base_layout = "var baseLayers = {".$baselist."};";
} else {
$base_layout = "";
}
然后当然将图层添加到地图中:
L.control.layers(baseLayers).addTo(map);
我制作了包含google maps
的代码。 osm
和thun
地图是一个很好的例子,但基本上是这个代码的作用:
if
中发表php
个陈述,看看道路是否包含在我制作的按钮中。我在数组中传递get_roads
,以便if
语句返回true,然后将$roads
设置为roadmap
值,该值在{{1}中给出在这个答案的第一个代码中。map examples
是否为空,因为如果它是空的,则不需要$baselist
,但如果它不为空,则它会获得,
,这将是先前的设定值,然后是逗号,然后是新值。$baselist
作为这些值传递,如果选中按钮,将在baseLayers
视图内创建地图。