From 74099f8642d8837a8856a8d399d0c3c7f721a14f Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 4 Apr 2012 00:35:59 +0200 Subject: [PATCH] allow for dynamically colored and sized map markers --- source/Ox.UI/js/Map/Ox.MapMarker.js | 36 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/source/Ox.UI/js/Map/Ox.MapMarker.js b/source/Ox.UI/js/Map/Ox.MapMarker.js index a322e50b..22f329a7 100644 --- a/source/Ox.UI/js/Map/Ox.MapMarker.js +++ b/source/Ox.UI/js/Map/Ox.MapMarker.js @@ -15,10 +15,8 @@ Ox.MapMarker MapMarker Object Ox.MapMarker = function(options) { options = Ox.extend({ - color: [255, 0, 0], map: null, - place: null, - size: 16 + place: null }, options); var that = this, @@ -202,19 +200,31 @@ Ox.MapMarker = function(options) { function setOptions() { // workaround to prevent marker from appearing twice // after setting draggable from true to false (google maps bug) - var fix = that.marker.getDraggable() && !that.place.editing; + var fix = that.marker.getDraggable() && !that.place.editing, + color = that.map.options('markerColor'), + size = that.map.options('markerSize'); //Ox.Log('Map', 'setOptions, that.map: ', that.map) - if (that.map.options('showTypes')) { + if (color == 'auto') { that.color = typeColor[that.place.type]; + } else if (Ox.isArray(color)) { + that.color = color; + } else { + that.color = color(that.place); + } + if (size == 'auto') { + that.size = 8; + Ox.forEach(areaSize, function(size, area) { + if (that.place.area >= area) { + that.size = size; + } else { + return false; + } + }); + } else if (Ox.isNumber(size)) { + that.size = size; + } else { + that.size = size(that.place); } - that.size = 8; - Ox.forEach(areaSize, function(size, area) { - if (that.place.area >= area) { - that.size = size; - } else { - return false; - } - }); that.marker.setOptions({ // fixme: cursor remains pointer cursor: that.place.editing ? 'move' : 'pointer',