Open eisensheng opened 11 years ago
I ended up having to use a raphael object to make a circle marker and extend it to produce the latlng callback needed - i used an edited version of the 'pulse' object:
R.Pulse = R.Layer.extend({
initialize: function(latlng, radius, attr, pulseAttr, options) {
R.Layer.prototype.initialize.call(this, options);
this._latlng = latlng;
this._radius = (typeof radius == 'number' ? radius : 6);
this._attr = (typeof radius == 'object' ? radius : (typeof attr == 'object' ? attr : {'fill': '#30a3ec', 'stroke': '#30a3ec'}));
this._pulseAttr = (typeof radius == 'object' ? attr : typeof pulseAttr == 'object' ? pulseAttr : {
'stroke-width': 3,
'stroke': this._attr.stroke
});
this._repeat = 3;
},
getLatLng: function(){
return this._latlng;
},
onRemove: function (map) {
R.Layer.prototype.onRemove.call(this, map);
if(this._marker) this._marker.remove();
if(this._pulse) this._pulse.remove();
},
projectLatLngs: function() {
if(this._marker) this._marker.remove();
if(this._pulse) this._pulse.remove();
var p = this._map.latLngToLayerPoint(this._latlng);
this._marker = this._paper.circle(p.x, p.y, this._radius).attr(this._attr);
var anim = Raphael.animation({
'0%': {transform: 's0.3', opacity: 0},
'100%': {transform: 's1.0', opacity: 1}
}, 200);
this._marker.animate(anim);
}
});
and then i could use it pretty much the same as the circle marker, even with tooltips:
var marker = new R.Pulse({lat:item.latitude,lng:item.longitude},
4,
{'stroke': activeRed, 'fill': activeRed},
{'stroke': activeRed, 'stroke-width': 1});
locs.addLayer(marker);
marker.bindTooltip(item.placeName,{
permanent: true,
direction: item.labelPosition,
className: 'toolTip '+item.placeName,
offset: [item.labelOffset[0],item.labelOffset[1]]
}).openTooltip();
Markers created with circleMarker behave oddly before and after RaphaelLayer Features are used.
It can be reproduced inside the demo by placing this little script into the index.js file: