צבעים שונים ב-leaflet Markers

9 views
Skip to first unread message

Tom Haber

unread,
Jun 28, 2016, 5:04:58 AM6/28/16
to Israel R User Group

שלום לכולם ,

אני מעוניין להמטיע markers בשימוש במפה אינטראקטיבית של leaflet ד

כברירת מחדל מקבלים את זה בצבע כחול ,אני מעוניין שזה יהיה גם בצבע אחר , כלומר שחלק יהיו בכחול במצב מסוים וחלק באדום נגיד במצב אחר ,

איך ניתן לעשות את זה ולשנות צבעים במיקומים שונים ? 


 ולא מספקת התשובה שם , אשמח לעזרה בנושא 

תודה רבה :)

Michael Dorman

unread,
Jun 28, 2016, 10:49:23 AM6/28/16
to israel-r-...@googlegroups.com
לפי דף העזרה של icons, כדי לשנות את צבע ה-icon צריך לתת קישורים לקבצי PNG עם כל הגרסאות (למשל מרקר אדום וכחול), כמו בדוגמה להלן -

library(leaflet)


iconData = data.frame(
  lat = c(rnorm(10, 0), rnorm(10, 1), rnorm(10, 2)),
  lng = c(rnorm(10, 0), rnorm(10, 3), rnorm(10, 6)),
  group = rep(sort(c('green', 'red', 'orange')), each = 10),
  stringsAsFactors = FALSE
)

leaflet() %>% addMarkers(
  data = iconData,
  icon = ~ icons(
    iconUrl = sprintf('http://leafletjs.com/docs/images/leaf-%s.png', group),
    iconWidth = 38, iconHeight = 95, shadowWidth = 50, shadowHeight = 64,
    iconAnchorX = 22, iconAnchorY = 94, shadowAnchorX = 4, shadowAnchorY = 62,
    popupAnchorX = -3, popupAnchorY = -76
  )
)

אם הסמל לא חייב להיות כמו ב-addMarkers אלא יכול להיות גם עיגול פשוט, אז תמיד אפשר להוסיף עם addCircles או addCircleMarkers, ולשלוט בצבע של העיגולים עם הפרמטר color כפי שמתואר כאן -

 

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Haber

unread,
Jun 30, 2016, 3:43:38 AM6/30/16
to israel-r-...@googlegroups.com
תודה רבה על המענה ,

אבל האמת היא שאני מחפש דרך מבלי להשתמש בתמונות ששמורות מראש במחשב , שהכל יהיה בתוך הקוד

האם יש דרך כזאת ? 

בתאריך 28 ביוני 2016 בשעה 17:49, מאת Michael Dorman <michael...@mail.huji.ac.il>:

--
You received this message because you are subscribed to a topic in the Google Groups "Israel R User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/israel-r-user-group/ODpCJz3gSJw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to israel-r-user-g...@googlegroups.com.

Michael Dorman

unread,
Jun 30, 2016, 10:25:52 AM6/30/16
to israel-r-...@googlegroups.com
כדי להציג מרקרים בצבעים שונים אפשר להעלות את קבצי ה-PNG שלהם ל-Dropbox או GitHub וכד', ואז הקוד עדיין יהיה בלתי תלוי.

למשל כאן אפשר למצוא את המרקר המקורי -

ניתן לערוך אותו, לשמור גרסאות PNG בצבעים שונים, להעלות לאתר כלשהו, ולהשתמש בהם במפת leaflet.

פרטים נוספים כאן -

פתרון אחר כאמור הוא להשתמש בסמל של עיגול. צבע של עיגול במפת leaflet אפשר לשנות בקלות מתוך R, בלי צורך בקבצי PNG.
Reply all
Reply to author
Forward
0 new messages