From your above additional code, it looks like you are loading Leaflet.markercluster script before Leaflet script:
<script src="leaflet.markercluster-src.js">
<script src="http://code.jquery.com/jquery-1.12.0.min.js">
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js">
You should rather load it after:
<script src="http://code.jquery.com/jquery-1.12.0.min.js">
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js">
<script src="leaflet.markercluster-src.js">
You should learn to use your browser console (on Windows / Linux browsers, press F12; on Mac OS browsers, press Command ⌘+Option ⌥+i) to look for potential errors.
In your case, I suspect there should be something like "ReferenceError: L is not defined
" due to Leaflet.markercluster trying to attach some code to Leaflet's L
namespace, but could not find it because it is not loaded yet.
The two plugins can be combined by using the same points source for both.
Since you didn't describe the format/structure of your data, the example below uses [lat, lng, alt]
structure for point.
Code could then look something like this:
var map = L.map('map').setView([46.2, 14.5], 8);
var points = [[46.0, 14.0, 700], [46.3, 14.2, 950], [46.2, 14.4, 1250], [46.3, 14.8, 1550], [46.5, 15, 1750]];
var altThresholds = [800, 900, 1000, 1100, 1200, 1300, 1400, 1500];
L.multiOptionsPolyline(points, {
multiOptions: {
optionIdxFn: function (latLng) {
var i;
for (i = 0; i < altThresholds.length; ++i) {
if (latLng[2] <= altThresholds[i]) return i;
}
return altThresholds.length;
},
options: [
{color: '#0000FF'}, {color: '#0040FF'}, {color: '#0080FF'},
{color: '#00FFB0'}, {color: '#00E000'}, {color: '#80FF00'},
{color: '#FFFF00'}, {color: '#FFC000'}, {color: '#FF0000'}
]
},
weight: 5,
lineCap: 'butt',
opacity: 0.75,
smoothFactor: 1
}).addTo(map);
L.motion.polyline(points, {
color: "transparent"
}, {
auto: true,
duration: 3000,
easing: L.Motion.Ease.easeInOutQuart
}, {
removeOnEnd: true,
showMarker: true,
icon: L.divIcon({html: "<i class='fa fa-car fa-2x' aria-hidden='true'></i>", iconSize: L.point(27.5, 24)})
}).addTo(map);
This gives the following result:
Best Answer
I am not sure about the
Leaflet.PolylineOffset
repository, but another way would be to useturf
using thebuffer
andpolygonToLine
functions. The difference would be that the polyline would not change with the zoom-level. If that is needed you could run a function when the zoom-level changes and recalculate the buffer every time.See: jsfiddle