This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 386
/
marker.js
65 lines (55 loc) · 2.06 KB
/
marker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
var format_url = require('./format_url'),
util = require('./util'),
sanitize = require('sanitize-caja');
// mapbox-related markers functionality
// provide an icon from mapbox's simple-style spec and hosted markers
// service
function icon(fp, options) {
fp = fp || {};
var sizes = {
small: [20, 50],
medium: [30, 70],
large: [35, 90]
},
size = fp['marker-size'] || 'medium',
symbol = ('marker-symbol' in fp && fp['marker-symbol'] !== '') ? '-' + fp['marker-symbol'] : '',
color = (fp['marker-color'] || '7e7e7e').replace('#', '');
return L.icon({
iconUrl: format_url('/v4/marker/' +
'pin-' + size.charAt(0) + symbol + '+' + color +
// detect and use retina markers, which are x2 resolution
(L.Browser.retina ? '@2x' : '') + '.png', options && options.accessToken),
iconSize: sizes[size],
iconAnchor: [sizes[size][0] / 2, sizes[size][1] / 2],
popupAnchor: [0, -sizes[size][1] / 2]
});
}
// a factory that provides markers for Leaflet from Mapbox's
// [simple-style specification](https://github.com/mapbox/simplestyle-spec)
// and [Markers API](http://mapbox.com/developers/api/#markers).
function style(f, latlon, options) {
return L.marker(latlon, {
icon: icon(f.properties, options),
title: util.strip_tags(
sanitize((f.properties && f.properties.title) || ''))
});
}
// Sanitize and format properties of a GeoJSON Feature object in order
// to form the HTML string used as the argument for `L.createPopup`
function createPopup(f, sanitizer) {
if (!f || !f.properties) return '';
var popup = '';
if (f.properties.title) {
popup += '<div class="marker-title">' + f.properties.title + '</div>';
}
if (f.properties.description) {
popup += '<div class="marker-description">' + f.properties.description + '</div>';
}
return (sanitizer || sanitize)(popup);
}
module.exports = {
icon: icon,
style: style,
createPopup: createPopup
};