Google Maps настроен для обновления пути (не URL)

Вот одна хорошая статья SFINAE: Введение в концепцию SFINAE C ++: интроспекция времени компиляции члена класса .

Обозначьте это следующим образом:

/*
 The compiler will try this overload since it's less generic than the variadic.
 T will be replace by int which gives us void f(const int& t, int::iterator* b = nullptr);
 int doesn't have an iterator sub-type, but the compiler doesn't throw a bunch of errors.
 It simply tries the next overload. 
*/
template  void f(const T& t, typename T::iterator* it = nullptr) { }

// The sink-hole.
void f(...) { }

f(1); // Calls void f(...) { }

template // Default template version.
struct enable_if {}; // This struct doesn't define "type" and the substitution will fail if you try to access it.

template // A specialisation used if the expression is true. 
struct enable_if { typedef T type; }; // This struct do have a "type" and won't fail on access.

template  typename enable_if::value, std::string>::type serialize(const T& obj)
{
    return obj.serialize();
}

template  typename enable_if::value, std::string>::type serialize(const T& obj)
{
    return to_string(obj);
}

declval - это утилита, которая дает вам «поддельную ссылку» на объект типа, который не может быть легко сконструирован. declval действительно удобен для наших конструкций SFINAE.

struct Default {
    int foo() const {return 1;}
};

struct NonDefault {
    NonDefault(const NonDefault&) {}
    int foo() const {return 1;}
};

int main()
{
    decltype(Default().foo()) n1 = 1; // int n1
//  decltype(NonDefault().foo()) n2 = n1; // error: no default constructor
    decltype(std::declval().foo()) n2 = n1; // int n2
    std::cout << "n2 = " << n2 << '\n';
}

0
задан geocodezip 18 January 2019 в 15:48
поделиться

1 ответ

«Значок» является анонимным объектом. Вам нужно снова установить весь объект:

marker.addListener('click', function() {
  myIcon.fillOpacity = 0.5;
  this.setIcon(myIcon);
});

или:

marker.addListener('click', function() {
  myIcon.fillOpacity = 0.5;
  this.setOptions({
    icon: myIcon
  }); 
});

подтверждение концепции скрипта

[119 ] screenshot of map after clicking marker

фрагмент кода:

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {
      lat: -25.363882,
      lng: 131.044922
    }
  });
  var myIcon = {
    path: google.maps.SymbolPath.CIRCLE,
    scale: 5,
    fillColor: "#ff00ff",
    fillOpacity: 0,
    strokeColor: "#ff00ff",
    strokeWeight: 2
  };

  var marker = new google.maps.Marker({
    position: map.getCenter(),
    icon: myIcon,
    map: map,
    title: 'My Marker>'
  });

  marker.addListener('click', function() {
    myIcon.fillOpacity = 0.5;
    this.setIcon(myIcon);
  });
}
html,
body,
#map {
  height: 100%;
  margin: 0;
  padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"></script>
[ 1115]
0
ответ дан geocodezip 18 January 2019 в 15:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: