Installed leaflet in extlib
This commit is contained in:
56
extlib/leaflet/src/layer/marker/Icon.js
Normal file
56
extlib/leaflet/src/layer/marker/Icon.js
Normal file
@@ -0,0 +1,56 @@
|
||||
L.Icon = L.Class.extend({
|
||||
iconUrl: L.ROOT_URL + 'images/marker.png',
|
||||
shadowUrl: L.ROOT_URL + 'images/marker-shadow.png',
|
||||
|
||||
iconSize: new L.Point(25, 41),
|
||||
shadowSize: new L.Point(41, 41),
|
||||
|
||||
iconAnchor: new L.Point(13, 41),
|
||||
popupAnchor: new L.Point(0, -33),
|
||||
|
||||
initialize: function(iconUrl) {
|
||||
if (iconUrl) {
|
||||
this.iconUrl = iconUrl;
|
||||
}
|
||||
},
|
||||
|
||||
createIcon: function() {
|
||||
return this._createIcon('icon');
|
||||
},
|
||||
|
||||
createShadow: function() {
|
||||
return this._createIcon('shadow');
|
||||
},
|
||||
|
||||
_createIcon: function(name) {
|
||||
var size = this[name + 'Size'],
|
||||
src = this[name + 'Url'],
|
||||
img = this._createImg(src);
|
||||
|
||||
if (!src) { return null; }
|
||||
|
||||
img.className = 'leaflet-marker-' + name;
|
||||
|
||||
img.style.marginLeft = (-this.iconAnchor.x) + 'px';
|
||||
img.style.marginTop = (-this.iconAnchor.y) + 'px';
|
||||
|
||||
if (size) {
|
||||
img.style.width = size.x + 'px';
|
||||
img.style.height = size.y + 'px';
|
||||
}
|
||||
|
||||
return img;
|
||||
},
|
||||
|
||||
_createImg: function(src) {
|
||||
var el;
|
||||
if (!L.Browser.ie6) {
|
||||
el = document.createElement('img');
|
||||
el.src = src;
|
||||
} else {
|
||||
el = document.createElement('div');
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
}
|
||||
});
|
||||
28
extlib/leaflet/src/layer/marker/Marker.Popup.js
Normal file
28
extlib/leaflet/src/layer/marker/Marker.Popup.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Popup extension to L.Marker, adding openPopup & bindPopup methods.
|
||||
*/
|
||||
|
||||
L.Marker.include({
|
||||
openPopup: function() {
|
||||
this._popup.setLatLng(this._latlng);
|
||||
this._map.openPopup(this._popup);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
closePopup: function() {
|
||||
if (this._popup) {
|
||||
this._popup._close();
|
||||
}
|
||||
},
|
||||
|
||||
bindPopup: function(content, options) {
|
||||
options = L.Util.extend({offset: this.options.icon.popupAnchor}, options);
|
||||
|
||||
this._popup = new L.Popup(options);
|
||||
this._popup.setContent(content);
|
||||
this.on('click', this.openPopup, this);
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
123
extlib/leaflet/src/layer/marker/Marker.js
Normal file
123
extlib/leaflet/src/layer/marker/Marker.js
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* L.Marker is used to display clickable/draggable icons on the map.
|
||||
*/
|
||||
|
||||
L.Marker = L.Class.extend({
|
||||
|
||||
includes: L.Mixin.Events,
|
||||
|
||||
options: {
|
||||
icon: new L.Icon(),
|
||||
title: '',
|
||||
clickable: true,
|
||||
draggable: false
|
||||
},
|
||||
|
||||
initialize: function(latlng, options) {
|
||||
L.Util.setOptions(this, options);
|
||||
this._latlng = latlng;
|
||||
},
|
||||
|
||||
onAdd: function(map) {
|
||||
this._map = map;
|
||||
|
||||
this._initIcon();
|
||||
|
||||
map.on('viewreset', this._reset, this);
|
||||
this._reset();
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
this._removeIcon();
|
||||
|
||||
map.off('viewreset', this._reset, this);
|
||||
},
|
||||
|
||||
getLatLng: function() {
|
||||
return this._latlng;
|
||||
},
|
||||
|
||||
setLatLng: function(latlng) {
|
||||
this._latlng = latlng;
|
||||
this._reset();
|
||||
},
|
||||
|
||||
setIcon: function(icon) {
|
||||
this._removeIcon();
|
||||
|
||||
this._icon = this._shadow = null;
|
||||
this.options.icon = icon;
|
||||
|
||||
this._initIcon();
|
||||
},
|
||||
|
||||
_initIcon: function() {
|
||||
if (!this._icon) {
|
||||
this._icon = this.options.icon.createIcon();
|
||||
|
||||
if (this.options.title) {
|
||||
this._icon.title = this.options.title;
|
||||
}
|
||||
|
||||
this._initInteraction();
|
||||
}
|
||||
if (!this._shadow) {
|
||||
this._shadow = this.options.icon.createShadow();
|
||||
}
|
||||
|
||||
this._map._panes.markerPane.appendChild(this._icon);
|
||||
if (this._shadow) {
|
||||
this._map._panes.shadowPane.appendChild(this._shadow);
|
||||
}
|
||||
},
|
||||
|
||||
_removeIcon: function() {
|
||||
this._map._panes.markerPane.removeChild(this._icon);
|
||||
if (this._shadow) {
|
||||
this._map._panes.shadowPane.removeChild(this._shadow);
|
||||
}
|
||||
},
|
||||
|
||||
_reset: function() {
|
||||
var pos = this._map.latLngToLayerPoint(this._latlng).round();
|
||||
|
||||
L.DomUtil.setPosition(this._icon, pos);
|
||||
if (this._shadow) {
|
||||
L.DomUtil.setPosition(this._shadow, pos);
|
||||
}
|
||||
|
||||
this._icon.style.zIndex = pos.y;
|
||||
},
|
||||
|
||||
_initInteraction: function() {
|
||||
if (this.options.clickable) {
|
||||
this._icon.className += ' leaflet-clickable';
|
||||
|
||||
L.DomEvent.addListener(this._icon, 'click', this._onMouseClick, this);
|
||||
|
||||
var events = ['dblclick', 'mousedown', 'mouseover', 'mouseout'];
|
||||
for (var i = 0; i < events.length; i++) {
|
||||
L.DomEvent.addListener(this._icon, events[i], this._fireMouseEvent, this);
|
||||
}
|
||||
}
|
||||
|
||||
if (L.Handler.MarkerDrag) {
|
||||
this.dragging = new L.Handler.MarkerDrag(this);
|
||||
|
||||
if (this.options.draggable) {
|
||||
this.dragging.enable();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_onMouseClick: function(e) {
|
||||
L.DomEvent.stopPropagation(e);
|
||||
if (this.dragging && this.dragging.moved()) { return; }
|
||||
this.fire(e.type);
|
||||
},
|
||||
|
||||
_fireMouseEvent: function(e) {
|
||||
this.fire(e.type);
|
||||
L.DomEvent.stopPropagation(e);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user