Gmap3 - Forum

Gmap3 exchange platform

You are not logged in.

Ads
(server costs 27.50€ per month)

#1 2012-05-10 10:12:59

mahieux06
Member
Registered: 2012-05-07
Posts: 25

Conditional call to markerimage on map creation

Hi all
I discovered Gmap3 less than 1 week ago and got addicted too ;-)
I am loading a js file to populate my [data] array (started from the tags example), in there I have lat,lng,titles,infowindow contents,icon image file to call and most of this displays nicely ...
but the latter

this obviously works:

marker:{
		options:{
		icon :  new google.maps.MarkerImage('img/markergreen.png',null, null, null, new google.maps.Size(25,25 ))          
		},

not that : 
marker:{
		options:{
		icon :  new google.maps.MarkerImage(data.icon,null, null, null, new google.maps.Size(25,25 ))   
		},

where my data file show icon:"img/markergreen.png" and I pushed this into data.icon
any idea ?

thanks

Offline

Ads
(server costs 27.50€ per month)

#2 2012-05-10 23:04:32

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: Conditional call to markerimage on map creation

no reason it shouldn't work if data.icon is defined and is a string that is the correct value for image src and the path to that src is valid

Offline

#3 2012-05-11 03:40:55

rqx110
Member
Registered: 2012-04-26
Posts: 12

Re: Conditional call to markerimage on map creation

Offline

#4 2012-05-12 16:43:31

mahieux06
Member
Registered: 2012-05-07
Posts: 25

Re: Conditional call to markerimage on map creation

Charlietfl

My file 'clients'  feeds , icon:"img/markerred.png" or icon:"img/markergreen.png"
it is then fed as (spaces added for clarity)  data.icon = ' " ' + client.icon ' " '    I tried this on and off with or without simple or double quotes
I checked the data.icon value in a simple check loop and it displays exactly what I want with or without double or simple quotes

//	$.each(data, function(i, data){	alert(data.icon);		});

up to that point I master what the data.icon array is     

Precisely because I thought too there is no reason it shouldn't work
I tried everything from

options:{
icon :  new google.maps.MarkerImage(data.icon,null, null, null, new google.maps.Size(25,25 ))  
},

data.icon being in that latter case showing as 'img/markerred.png' or "img/markerred.png" (or green)
and yes the path exists

better,! I can force a fixed variable into it like thiscolor (= say 'img/markerred.png') in place of data.icon and it works
but it seems like the data array iteration is not supported in here for any reason which I try to understand
Actually it does NOT bug , but the icons aren't displayed

If there is a not to heavy method to do it in an alternate way , I'm a taker too

Offline

#5 2012-05-13 16:07:26

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: Conditional call to markerimage on map creation

There is likely something wrong in code not shown

Post a  link to live page or show more of the code

Offline

#6 2012-05-14 16:29:44

charlietfl
Moderator
Registered: 2011-11-24
Posts: 201

Re: Conditional call to markerimage on map creation

When using 'addMarkers' the marker options will be the same for all markers in that data grouping. There is no access to data for each individual marker within the marker.options.

You could loop over all of your input data and use 'addMarker' method within the loop instead. Or if you have multiple items that will use same marker, map your data to groups that use same marker and use 'addMarkers' for each group, changing the icon for each group.

Offline

#7 2012-05-15 10:47:28

mahieux06
Member
Registered: 2012-05-07
Posts: 25

Re: Conditional call to markerimage on map creation

Thanks Charlie,

This helped me realize it was WAY simpler than what I initially thought , leading me to way too complicated callback functions
my data file  did bring

   

 {lat:  xx.x  , lng:  yy.y , infowindowcontent: "blah" , title: 'my text' , icon:"img/markergreen.png"}, 

where actually it should have been built in an 'expected' way of :

   

 {lat:  xx.x  , lng:  yy.y , infowindowcontent: "blah" , title: 'my text' , options:{icon:"img/markergreen.png"}}, 

so when loading it into a data array as data.options

this simple code is sufficient :

     

 {action:'addMarkers', markers: data} 

JB your stuff is too smart !  :-)

Offline

Board footer

Powered by FluxBB