leaflet-polylineoffset
Version:
Apply a relative pixel offset to polylines without changing their coordinates.
60 lines (51 loc) • 1.84 kB
HTML
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Leaflet Polyline Offset example</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
<style>
* { margin: 0; padding: 0; }
html, body { height: 100%; }
#map { width:100%; height:100%; }
</style>
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
<script src="../leaflet.polylineoffset.js"></script>
<script>
window.onload = function() {
var map = new L.Map('map', {
center: [58.0, -11.0],
zoom: 4,
layers: [
L.tileLayer('http://{s}.tile.openstreetmap.se/hydda/full/{z}/{x}/{y}.png', {
minZoom: 0,
maxZoom: 18,
attribution: 'Tiles courtesy of <a href="http://openstreetmap.se/" target="_blank">OpenStreetMap Sweden</a> — Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
})
]
});
var ll = [[58.44773, -28.65234], [53, -23.33496], [53, -14.32617], [58.1707, -10.37109], [59, -13], [57, -15], [57, -18], [60, -18], [63, -5], [59, -7], [58, -3], [56, -3], [60, -4]];
var orig = L.polyline(ll, {
weight: 2,
dashArray: '5,10',
color: 'black',
opacity: 0.3
}).addTo(map);
var leftPolyline = L.polyline(ll, {
color: '#f00',
opacity: 1,
offset: -5
}).addTo(map);
var rightPolyline = L.polyline(ll, {
color: '#080',
opacity: 1,
offset: 10
}).addTo(map);
};
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>