Leafletjs突出特定的街道

时间:2015-07-21 14:49:13

标签: javascript google-maps leaflet

我想使用leaflet.js突出显示地图上的特定街道,我目前正在使用带有数组数据的折线。

<!DOCTYPE html>
<html>
<head>
    <title>Nairobi Map</title>
    <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
    <script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
</head>
<body onload="initmap();">
<div id="map"></div>
<style>
    #map { height: 480px; }
</style>
<script>
        var mbAttr = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
                '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
                'Imagery © <a href="http://mapbox.com">Mapbox</a>',
            mbUrl = 'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6IjZjNmRjNzk3ZmE2MTcwOTEwMGY0MzU3YjUzOWFmNWZhIn0.Y8bhBaUMqFiPrDRW9hieoQ';

        var grayscale   = L.tileLayer(mbUrl, {id: 'mapbox.light', attribution: mbAttr}),
            streets  = L.tileLayer(mbUrl, {id: 'mapbox.streets',   attribution: mbAttr});

    var baseMaps = {
    "Grayscale": grayscale,
    "Streets": streets
};

function initmap () {
var map = L.map('map', {
    center: [-1.2833, 36.8167],
    zoom: 12,
    layers: [grayscale]
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.control.layers(baseMaps).addTo(map);
var polyline = L.polyline([
    [-1.26135173, 36.84151411],
    [-1.25879889, 36.84619188],
    [-1.25824112, 36.84779048],
    [-1.25815531, 36.8516314],
    [-1.25781207, 36.85304761],
    [-1.25714704, 36.85439944],
    [-1.25410078, 36.85798287]
    ]
            ).addTo(map);
}

</script>
</body>
</html>

从上面的例子可以看出,我已经能够选择Thika路的一部分,但由于我一点一点地定义,我需要定义超过100条道路/街道,这将是乏味的。 有走动吗?

0 个答案:

没有答案