Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional marker colors and icons #17

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c9bef6b
add additional marker colors and icons
vikasrana1989 Apr 18, 2017
7475e50
add additional marker colors and icons
vikasrana1989 Apr 18, 2017
d45a787
add additional marker colors and icons
vikasrana1989 Apr 18, 2017
712b76b
custom color code removed
vikasrana1989 Apr 19, 2017
11691f0
Ember Bootstrap drop down component added and marker icon drop down c…
vikasrana1989 Apr 19, 2017
e7e0a87
comment update
vikasrana1989 Apr 19, 2017
a4f6de2
ember-bootstrap addon removed
vikasrana1989 Apr 20, 2017
5c2a92b
Icon drop down updated with select tag
vikasrana1989 Apr 20, 2017
cdef4b3
Dynamic image marker added on map
vikasrana1989 Apr 20, 2017
529c642
default option value is not getting updated
vidyadharbhatt Apr 21, 2017
bd2aad5
hover added
vidyadharbhatt Apr 21, 2017
e854818
Marker icon color dynamically set
vikasrana1989 Apr 21, 2017
10d8440
Marker hoever path updated
vikasrana1989 Apr 21, 2017
92dca5b
Marker hoever path updated
vikasrana1989 Apr 21, 2017
1e8f60f
default hover color
vidyadharbhatt Apr 21, 2017
6a8aa72
Icon drop down color updated
vikasrana1989 Apr 21, 2017
47bbc78
Merge branch 'marker-icon' of https://github.com/vikasrana1989/google…
vikasrana1989 Apr 21, 2017
16b628e
Marker Icon custom hover removed + Marker Icon Hover color set to red
vikasrana1989 Apr 24, 2017
d58cb39
Marker Icon last used to set default
vikasrana1989 Apr 24, 2017
ce48af9
color dropdown removed when default icon on marker
Ganesh4 Apr 25, 2017
0043f71
color dropdown removed when default icon on marker
Ganesh4 Apr 25, 2017
20f98a0
marker pin icon path updated
vidyadharbhatt Apr 26, 2017
f0258d0
ember power selected applied
Ganesh4 Apr 29, 2017
19a83de
ember power select applied
Ganesh4 May 1, 2017
1af63b9
ember power select applied on marker
Ganesh4 May 2, 2017
70f76f9
Marker Icon dynamic hover color set
vikasrana1989 May 3, 2017
af5cf3e
Merge branch 'marker-icon' of https://github.com/Ganesh4/google-maps-…
vikasrana1989 May 3, 2017
5e8fab4
jsHint error removed from marker icon
Ganesh4 May 3, 2017
51e9b65
Merge pull request #5 from Ganesh4/jshinterr-marker
vikasrana1989 May 3, 2017
95f7538
power select updated
vikasrana1989 May 4, 2017
163b8d7
ember power selection
Ganesh4 May 4, 2017
756b789
Merge branch 'marker-icon' of https://github.com/vikasrana1989/google…
vikasrana1989 May 4, 2017
de9dce8
drop_down class added
Ganesh4 May 4, 2017
b45a2c6
code merged with vikas marker icon
Ganesh4 May 4, 2017
2e94535
code merged
vikasrana1989 May 8, 2017
6c83041
Marker Icon updated with dropdown option
vikasrana1989 May 11, 2017
7d2c689
Merge pull request #7 from vikasrana1989/marker-icon-new
vikasrana1989 May 11, 2017
8c930d3
code merged
vikasrana1989 May 11, 2017
e329b53
code update
vikasrana1989 May 11, 2017
4800f39
code update
vikasrana1989 May 11, 2017
6a3e0ac
style updated
vidyadharbhatt May 12, 2017
3ae2bf4
New Marker drop down Added(#8)
Ganesh4 May 12, 2017
40c0b12
Marker Dropdown icon style updated (#9)
Ganesh4 May 16, 2017
35d7696
code update
vikasrana1989 May 19, 2017
a11ab0e
Marker Icon position issue fixed
vikasrana1989 May 19, 2017
31cc0bf
marker removed on clear all button
vikasrana1989 May 19, 2017
b826b8a
Merge branch 'marker-icon' of https://github.com/vikasrana1989/google…
vikasrana1989 May 19, 2017
4a99ac9
hover marker selected style fixed
vikasrana1989 May 19, 2017
349144e
Merge branch 'marker-icon' of https://github.com/vikasrana1989/google…
vikasrana1989 May 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 88 additions & 5 deletions addon/components/google-maps-markup/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import overlayToFeature from '../../utils/overlay-to-feature';
import featureCenter from '../../utils/feature-center';
import initMeasureLabel from '../../utils/init-measure-label';
import MapLabel from '../../utils/map-label';
import Marker from '../../utils/marker';
import DynamicLabel from '../../utils/dynamic-label';
import labelPlotter from '../../utils/label-plotter';
import hoverColor from '../../utils/hover-color';

if (!window.google) {
throw new Error('Sorry, but `google` defined globally is required for this addon');
Expand Down Expand Up @@ -191,7 +193,7 @@ export default Ember.Component.extend(ParentMixin, {
poly.getPath().push(e.latLng);
});

google.maps.event.addListenerOnce(map, 'mouseup', (e) => {
google.maps.event.addListenerOnce(map, 'mouseup', () => {
google.maps.event.removeListener(move);
poly.setMap(null);

Expand All @@ -214,6 +216,7 @@ export default Ember.Component.extend(ParentMixin, {
},

actions: {

updateOptionValue(tool, prop, value) {
set(tool, prop, value);
},
Expand All @@ -233,6 +236,9 @@ export default Ember.Component.extend(ParentMixin, {
},

changeTool(toolId) {
this.resetAllLayers();
this.clearListeners();

let markupDataService = this.get('markupData');
let activeLayer = this.get('activeLayer');
let map = this.get('map');
Expand All @@ -244,9 +250,6 @@ export default Ember.Component.extend(ParentMixin, {
this.set('drawFinished', false);
markupDataService.set('activeTool', tool.id);

this.resetAllLayers();
this.clearListeners();

if (activeLayer) {
if (tool.id === 'pan') {
activeLayer.data.setDrawingMode(null);
Expand All @@ -255,7 +258,6 @@ export default Ember.Component.extend(ParentMixin, {

let clickListener = activeLayer.data.addListener('click', event => {
let childComponents = this.get('childComponents');
let results = this.get('results');
let found = childComponents.find(function (comp) {
return comp.get('data').feature.getId() === event.feature.getId();
});
Expand All @@ -282,6 +284,8 @@ export default Ember.Component.extend(ParentMixin, {
event.stop();
});
listeners.pushObjects([ mapListener, dataListener ]);
} else if (tool.dataId === 'Point') {
activeLayer.data.setDrawingMode(tool.dataId);
} else if (tool.dataId) {
let style = Ember.copy(tool.style);

Expand Down Expand Up @@ -332,6 +336,8 @@ export default Ember.Component.extend(ParentMixin, {
if (result.type === 'text') {
textGeoJson.removeObject(result.geojson);
}
} else if (result.markerData) {
result.markerData.setMap(null);
}
});

Expand All @@ -352,6 +358,9 @@ export default Ember.Component.extend(ParentMixin, {
if (result.type === 'text') {
result.feature.setMap(null);
textGeoJson.removeObject(result.geojson);
} else if (result.type === 'marker') {
result.markerData.setMap(null);
layer.data.remove(result.feature);
} else {
layer.data.remove(result.feature);
}
Expand Down Expand Up @@ -462,6 +471,11 @@ export default Ember.Component.extend(ParentMixin, {
scaledSize: new google.maps.Size(22, 40),
}
};

if(data.hoverStyle){
style = data.hoverStyle;
}

} else if (data.type === 'text') {
data.feature.highlight();
} else {
Expand Down Expand Up @@ -707,16 +721,85 @@ export default Ember.Component.extend(ParentMixin, {
let plotter;

let onClick = run.bind(this, (event) => {
let activeLayer = this.get('activeLayer');
let toolId = this.get('toolId');
let tool = this.getTool(toolId);
let mode = this.get('mode');
let mapDiv = map.getDiv();
let target = event.target;
let withinMap = mapDiv.contains(target);
let results = this.get('results');

if (mode === 'draw') {
if (withinMap && toolId === 'freeFormPolygon') {
this.enableFreeFormPolygon();
} else if (withinMap && toolId === 'marker') {
let length = results.get('length');
let arrayIndexOffSet = 1;
let lastObjectIndex = length - arrayIndexOffSet;
let data = results.get('lastObject');

let iconObj = tool.icons.find(function(iconObj){
return iconObj.id === tool.icon.id;
});

let markerObj = tool.markers.find(function(markerObj){
return markerObj.id === tool.marker.id;
});

if (markerObj.id !== 'default') {

let style = {
icon: {
path: markerObj.path,
fillColor: tool.style.color,
fillOpacity: 1,
strokeColor: '',
strokeWeight: 0,
scaledSize: new google.maps.Size(22, 40)
},
map_icon_label: '<i class="material-icons">' + markerObj.id + '</i>'
};

let hoverStyle = {
icon: {
path: markerObj.path,
fillColor: hoverColor(tool.style.color),
fillOpacity: 1,
strokeColor: '',
strokeWeight: 0,
scaledSize: new google.maps.Size(22, 40)
}
};

if (tool.icon.id !== 'default') {
var marker = new Marker({
position: calculateLatLng(map, event),
map: map,
icon: {
path: markerObj.path,
fillColor: tool.style.color,
fillOpacity: 1,
strokeColor: '',
strokeWeight: 0,
scaledSize: new google.maps.Size(22, 40)
},
map_icon_label: '<i class="material-icons">' + iconObj.id + '</i>'
})

data.markerData = marker;

// To add the marker to the map, call setMap();
marker.setMap(map);
}

data.hoverStyle = hoverStyle;
data.style = style;
results[lastObjectIndex] = data;
activeLayer.data.overrideStyle(data.feature, style);
}
}

return;
}

Expand Down
35 changes: 35 additions & 0 deletions addon/components/google-maps-markup/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,50 @@
{{#each activeTool.options as |opt|}}
{{#if (is-equal opt.type 'color')}}
<div class="form-group">
{{#unless (is-equal activeTool.icon 'default')}}
<label>
{{#if opt.fillOptional}}
{{input type="checkbox" click=(action "fillColorTransparent") checked=(get activeTool opt.id)}}
{{/if}}
{{opt.name}}
</label>
{{color-palette selected=(get activeTool opt.id) onselect=(action 'updateOptionValue' activeTool opt.id)}}
{{/unless}}
</div>
{{/if}}
{{#if (is-equal opt.type 'Marker')}}
<div class="form-group drop_down">
<div><label>{{opt.name}}</label></div>
{{#power-select
options=activeTool.markers
selected=activeTool.marker
searchEnabled=false
onchange=(action "updateOptionValue" activeTool opt.id)
as |marker|
}}
<span>{{marker.display}}</span>
<svg baseProfile="basic" xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 48 48"><path d="{{marker.pathDropdown}}"></path></svg>
{{/power-select}}
</div>
{{/if}}
{{#unless (is-equal activeTool.marker.id 'default')}}
{{#if (is-equal opt.type 'icon')}}
<div class="form-group drop_down">
<div><label>{{opt.name}}</label></div>
{{#power-select
options=activeTool.icons
selected=activeTool.icon
searchEnabled=false
onchange=(action "updateOptionValue" activeTool opt.id)
as |icon|
}}
<span>{{icon.display}}</span>
<i class="material-icons">{{ icon.id }}</i>
{{/power-select}}
</div>
{{/if}}
{{/unless}}

{{/each}}
</form>
{{/if}}
Expand Down
1 change: 0 additions & 1 deletion addon/components/markup-result-item/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import featureCenter from '../../utils/feature-center';
const {
on,
run,
set,
computed
} = Ember;

Expand Down
87 changes: 87 additions & 0 deletions addon/utils/hover-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

/* hexToComplimentary : Converts hex value to HSL, shifts
* hue by 180 degrees and then converts hex, giving complimentary color
* as a hex value
* @param [String] hex : hex value
* @return [String] : complimentary color as hex value
*/
export default function hoverColor(hex) {
// Convert hex to rgb
var rgb = 'rgb(' + (hex = hex.replace('#', '')).match(new RegExp('(.{' + hex.length/3 + '})', 'g')).map(function(l) { return parseInt(hex.length%2 ? l+l : l, 16); }).join(',') + ')';

// Get array of RGB values
rgb = rgb.replace(/[^\d,]/g, '').split(',');

var r = rgb[0], g = rgb[1], b = rgb[2];

// Convert RGB to HSL
r /= 255.0;
g /= 255.0;
b /= 255.0;
var max = Math.max(r, g, b);
var min = Math.min(r, g, b);
var h, s, l = (max + min) / 2.0;

if(max === min) {
h = s = 0; //achromatic
} else {
var d = max - min;
s = (l > 0.5 ? d / (2.0 - max - min) : d / (max + min));

if(max === r && g >= b) {
h = 1.0472 * (g - b) / d ;
} else if(max === r && g < b) {
h = 1.0472 * (g - b) / d + 6.2832;
} else if(max === g) {
h = 1.0472 * (b - r) / d + 2.0944;
} else if(max === b) {
h = 1.0472 * (r - g) / d + 4.1888;
}
}

h = h / 6.2832 * 360.0 + 0;

// Shift hue to opposite side of wheel and convert to [0-1] value
h+= 180;
if (h > 360) { h -= 360; }
h /= 360;

// Convert h s and l values into r g and b values
if(s === 0){
r = g = b = l; // achromatic
} else {
var hue2rgb = function hue2rgb(p, q, t){
if(t < 0) {
t += 1;
}
if(t > 1){
t -= 1;
}
if(t < 1/6) {
return p + (q - p) * 6 * t;
}
if(t < 1/2) {
return q;
}
if(t < 2/3) {
return p + (q - p) * (2/3 - t) * 6;
}
return p;
};

var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;

r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}

r = Math.round(r * 255);
g = Math.round(g * 255);
b = Math.round(b * 255);

// Convert r b and g values to hex
rgb = b | (g << 8) | (r << 16);
return "#" + (0x1000000 | rgb).toString(16).substring(1);
}
65 changes: 65 additions & 0 deletions addon/utils/marker-label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
class MarkerLabel extends google.maps.OverlayView {
constructor(options) {
super(...arguments);

var self = this;
this.setValues(options);

this.position = options.position;

// Create the label container
this.div = document.createElement('div');
this.div.className = '';

// Trigger the marker click handler if clicking on the label
google.maps.event.addDomListener(this.div, 'click', function(e){
(e.stopPropagation) && e.stopPropagation();
google.maps.event.trigger(self.marker, 'click');
});
}

onAdd() {
var pane = this.getPanes().overlayImage.appendChild(this.div);
var self = this;

this.listeners = [
google.maps.event.addListener(this, 'position_changed', function() { self.draw(); }),
google.maps.event.addListener(this, 'text_changed', function() { self.draw(); }),
google.maps.event.addListener(this, 'zindex_changed', function() { self.draw(); })
];
}

// Marker Label onRemove
onRemove() {
this.div.parentNode.removeChild(this.div);

for (var i = 0, I = this.listeners.length; i < I; ++i) {
google.maps.event.removeListener(this.listeners[i]);
}
}

// Implement draw
draw() {
var projection = this.getProjection();
var position = projection.fromLatLngToDivPixel(this.get('position'));
var div = this.div;

this.div.innerHTML = this.get('text').toString();

div.style.zIndex = this.get('zIndex'); // Allow label to overlay marker
div.style.position = 'absolute';
div.style.display = 'block';
div.style.left = (position.x - (div.offsetWidth / 2) + 12) + 'px';
div.style.top = (position.y - (div.offsetHeight/2) - 24) + 'px';
}

set position(value) {
this.latlng = value;
}

get position() {
return this.latlng;
}
}

export default MarkerLabel;
Loading