H
H
heavy452020-06-15 17:16:33
Google Maps
heavy45, 2020-06-15 17:16:33

How to color a single marker from many on one layer in google maps?

Everyone is good!
There is a map on Google
There is a table with addresses and a sign of friend or foe (red or green)
I import data from the table to the layer
Question - how to paint markers in different colors (red and green), depending on the sign in the table?
or in extreme cases - how to manually color them?
And then you change the color on one, and everyone changes (
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Pautov, 2020-06-15
@bootd

Compose an array of objects from this table like this:

const map = new google.maps.Map(document.getElementById("map"), {
  center: new google.maps.LatLng(-33.91722, 151.23064), 
  zoom: 16
}); 
const markers = [
  {
    type: '', // тут свой алиас для красного и зелёного
    position: {
      lat: '55.0000',
      lng: '55.0000'
    }
  },
  {
    type: '', // тут свой алиас для красного и зелёного
    position: {
      lat: '55.0000',
      lng: '55.0000'
    }
  },
  {
    type: '', // тут свой алиас для красного и зелёного
    position: {
      lat: '55.0000',
      lng: '55.0000'
    }
  }
];

markers.forEach(data => {
  const marker = new google.maps.Marker({
    position: data.position,
    icon: data.type === 'алиас' ? 'путь к одной иконке' : 'или другой',
    map: map
  });
}

Well, when markers are put in the cycle, we look at the type flag and specify for the marker, for example, different pictures, green or red.
UPD: updated for better understanding. I could, of course, mess up, not add something, but I wrote right here, in the text field

A
Alexander Ivanov, 2020-06-16
@oshliaer

Each layer maintains its own color. Unfortunately import to My Maps does not support multiple layers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question