Drupal에서 Google지도를 사용하고 있습니다 (하지만 내 문제와 관련이 없다고 생각합니다). 보기 (Drupal의 페이지 표시)에서 Google지도에 마커를 표시하고 있습니다. 외부 블록에지도의 마커 링크를 표시하고 있습니다.google.map 객체의 'marker'객체에 어떻게 액세스합니까?
this example을 보았습니다. 그러나 다른 방법은 없습니다. 지도 표시를 클릭하면 관련 링크 (및 추가 데이터)를 표시하고 싶습니다.
Object {text: "mytext", latitude: "46.3611897222", longitude: "1.60658955574", title: "Title of mymarker", markername: "mymarkername"…}
"": "mytext"
latitude: "46.3611897222"
longitude: "1.60658955574"
|> marker: Vl
markername: "mymarkername"
offset: ""
|> opts: Object
text: "mytext"
title: "Title of mymarker"
PS : 삼각형 확장 아이콘
나는 그 마커 객체를 대상으로 필요하지 mymarker의 |>
스탠드
(function ($) {
Drupal.behaviors.gmap = {
attach: function (context, settings) {
//'auto1map' is the name of my map
$.each(Drupal.settings.gmap.auto1map.markers, function(index, mymarker){
console.log(mymarker);
//using 'mymarker' doesn't trigger the mouseover
//I need the 'mymarker.marker' marker-object instead
var marker = ???;
//I want to do something like this
google.maps.event.addListener(marker, 'click', function(e){
console.log(index+' finally clicked');
});
// ...the rest of my code
});
}
}
})(jQuery);
mymarker 객체는 크롬 콘솔이 같다 대상
마커 부분은 다음을 포함합니다.
내가mymarker.latitude
을하려고하면 953,221,392,566,255,333,210
, 난 내가 $(mymarker).opts
을하려고하면, 내가 'OPTS'객체를 가져 위도 값
을 얻을
하지만 난는 '마커'부분을 얻을 것입니다 필요하지만, 내가 할 수있는 작업 't 그것을 얻을 : 내가
console.log(mymarker.marker)
console.log($(mymarker).marker)
=>는 $ 3,516,
console.log($(mymarker).get('marker))
=> 정의되지 않은
내가이며 어떻게 마커 객체의 type 것 같다 'VI의'에 캐스팅 모르는 ("마커"형?). 시도해 보았습니다 api guide이 데이터에 액세스하는 방법에 대한 도움말을 어디서든지 찾을 수 없었습니다.
편집 - 필요한 것을 보여주기 위해 js 코드를 편집했습니다.
편집 - @ Dr.Molle 덕분에 AlexK가 목표를 달성 할 수있었습니다.
이것은 업데이트 된 버전입니다. 마커가있는 Google지도를 표시하는 드루팔 (Drupal)보기가 있으며, 다른 블록의 HTML 목록에 동일한 마커를 표시하는 "첨부 파일"이 있습니다. 마커를 클릭하면 해당 목록 요소를 표시하고 다른 요소는 숨기려고합니다.
(function ($) {
//When click on marker, act on related link
Drupal.behaviors.gmap = {
attach: function (context, settings) {
//I get all the html list elements
var li = $('.view-content .views-field-title').parent();
//and hide them all
li.hide();
//Set index to associate list element and markers
var index = 0;
var lastindex = -1;
//reference for the map
var map=Drupal.gmap.getMap('auto1map');
//bind addmarker-handler, the marker is available as callback-argument
map.bind('addmarker', function (m) {
var element = $(li)[index];
m.marker.index=index;
//remove listeners set automatically by the library
google.maps.event.clearListeners(m.marker, 'click');
//add your custom listener
google.maps.event.addListener(m.marker, 'click',function(){
//Hide last shown element
if (lastindex != -1){
$($(li)[lastindex]).hide();
}
//Show the html element corresponding to the marker
$(element).show();
//Set new lastindex
lastindex = parseInt(m.marker.index);
});
index++;
});
}
};
})(jQuery);
이것은 절대적으로 뛰어나고, 자리를 잡습니다 : 이것은 실제로 올바른 청취자의 사용에 대한 문제였습니다! 아마 주제가 아니지만, 드루팔 (Drupal)을 모른다면 어떻게하면 addmarker listener에 관한 문제인지, 아마도 더 중요한지에 대해 알 수 있습니까? 콘솔의 마커 개체에 액세스 할 수 없지만 모든 올바른 값과 함께 사용할 수있었습니다. 이 두 사실과 addlistener를 사용하는 천재성을 어떻게 연관 지을 것입니다. 이런 종류의 두통 문제를 디버깅하는 방법을 배우려합니다. 어쨌든 고마워. – Overdose
나는이 간단한 Drupal 페이지를지도와 마커 (http://www.drupal.manuals-now.com/map/node)와 함께 사용했으며 코드를 추가하여 그곳에서 일어나는 일을 확인했다. 마커가 다른 객체의 속성으로 표시되었지만 직접 액세스하려고 할 때 정의되지 않은 경우 타이밍 문제라고 분명했습니다 ([콘솔 동작 관련 질문] (http://stackoverflow.com/questions)./18098482/javascript-object-property-logged-in-google-chrome-console-before-declaration/18098661 # 18098661)). addmarker-listener 페이지 (GIcon 관리자)에로드 된 스크립트를 검사하여 찾았습니다. –
추가 설명 주셔서 감사합니다! 나는 단지 당신을 +1하기에 충분한 "크레딧"이 없다는 것을 후회한다. 마지막 문장이 어디서 나오는 지 알지 못했지만 내일 아침에 그걸 검사 할거야. – Overdose