Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将CustomMarker与MarkerClustererPlus一起使用?_Javascript_Css_Html_Google Maps_Canvas - Fatal编程技术网

Javascript 如何将CustomMarker与MarkerClustererPlus一起使用?

Javascript 如何将CustomMarker与MarkerClustererPlus一起使用?,javascript,css,html,google-maps,canvas,Javascript,Css,Html,Google Maps,Canvas,我有以下代码 我正在将MarkerClustererPlus与一起使用,但当我尝试创建集群时,控制台显示以下错误:未捕获类型错误:b.GetDragable不是一个函数 如何使markerCluster工作?将.getDragable方法添加到您的CustomMarker: CustomMarker.prototype.getDraggable = function() { return false; }; 代码片段: var-MC; var MC_Opc={ 网格大小:50, 最大缩放

我有以下代码

我正在将MarkerClustererPlus与一起使用,但当我尝试创建集群时,控制台显示以下错误:未捕获类型错误:b.GetDragable不是一个函数

如何使markerCluster工作?

将.getDragable方法添加到您的
CustomMarker

CustomMarker.prototype.getDraggable = function() { return false; };

代码片段:

var-MC;
var MC_Opc={
网格大小:50,
最大缩放:15,
imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
};
var标记;
var标记=[];
//范例
var映射;
var叠加;
函数初始化(){
变量选项={
缩放:9,
中心:新google.maps.LatLng(-34.397151.644),
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(“map_canvas”),opts);
overlay=newcustommarker(新的google.maps.LatLng(-34.345151.65),map,“hola”,null);
var overlay2=新的CustomMarker(新的google.maps.LatLng(-34.395151.644),map,“hello”,null;
MC=新标记聚类器(映射,[],MC_Opc);
标记。推(覆盖);
标记。推(覆盖2);
MC=新标记聚类器(地图、标记、MC_Opc);
}
google.maps.event.addDomListener(窗口,“加载”,函数(){
初始化();
});
功能画布(文本、高度、分区){
var语境;
var canvas=document.createElement(“canvas”);
canvas.style.cssText='颜色:黑色;背景:#ffffff;背景:url(数据:image/svg+xml;base64,PD94BWGDMVYC2LVBJ0IMS4WIIA/PGO8C3ZNIHHTBG5ZPSJODHRWOI8VD3D3LNCZYLM9YZYD8YMDAWL3N2ZYIGD2LKDGGG9IJEWMCUIIGDMLLD0JVED0IMCAWIDEGMCHC2VYDMV3BC3BLY3RYXYXYBRP00IBM9UZSI+CIAGPGG8BMVHBYCKYWYW5LKYKYW5LKYZZYGPZ2TZ2TZVUZ2VUZ2VZJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ9IJ9IJJJJJJJJJJJJ9IZZZZZYWIWIWIF9V9V9IJ9MCUIPGOGICAGPHN0B3AGB2ZMC2V0psiWJSIGC3RVCC1JB2xVCJ0II2ZMZMZMIIGC3RVCC1VCGFJAXR5psiXII8+CIAGICA8RCRVCCBVZMZZZZZZZZQ9IjewmcuiHn0B3BHY2L0ET0IMPGOGIdWfYR3JHLLbNq+CIAGPCHJGPLY3QGED0IMCIGE0IMCIGD2L2KDG9IJJJJJ9IJJJJZZZZZZJJJJJJ9IJJJJJJJJJJZZZZZZZZZZL9IJ9IJJJJJJJJJJJJJZZZZZZZZZZZZZZZZZZZZYYYYYYYYZZZZZZZZZ(顶部,#ffffffff 0%,#ffb442 100%);背景:-webkit渐变(线性,左上,左下,颜色停止(0%,#ffffffff),颜色停止(100%,#ffb442));背景:-webkit线性渐变(顶部,#ffffffffff 0%,#ffb442 100%);背景:-o线性渐变(顶部,#ffffffffffffff 0%,#ffb442 100%);背景:-ms线性渐变(顶部,#ffffb40%,#;背景:线性渐变(到底部,#ffffffff 0%,#ffb442 100%);过滤器:progid:DXImageTransform.Microsoft.gradient(startColorstr=“#ffffffff”,endColorstr=“#ffb442”,GradientType=0);边框宽度:1px;-moz边框半径:2px;-webkit边框半径:2px;边框半径:2px;字体系列:“Lucida Grande”,“Arial”,sans serif;指针事件:none;”;
var-txtWidth;
txtWidth=canvas.getContext(“2d”);
txtWidth.font=“12px无衬线”;
var-width\uxTwidth.measureText(texto).width;//计算宽度
//控制台.日志(宽度);
//canvas.style.border=“纯黑色”;
setAttribute(“width”,(width+px”);
setAttribute(“height”,(height+px”);
context=canvas.getContext(“2d”);
context.font=“12px无衬线”;
context.fillStyle=“黑色”;
context.fillText(texto,0,12);
返回div.appendChild(画布);
}
功能自定义标记(位置、地图、文本、图标){
此.latlng=位置;
this.text=text;
this.icon=图标;
//设置板条和文字后,将覆盖添加到地图中。这将
//触发对窗格的调用,该窗格将依次调用draw。
这个.setMap(map);
}
CustomMarker.prototype=new google.maps.overlyview();
CustomMarker.prototype.GetDragable=函数(){
返回false;
};
CustomMarker.prototype.draw=函数(){
var me=这个;
//检查是否已创建div。
var div=this.div_2;;
如果(!div){
//创建覆盖文本DIV
div=this.div=document.createElement('div');
//创建代表CustomMarker的DIV
div.style.border=“无”;
div.style.position=“绝对”;
div.style.paddingLeft=“0px”;
div.style.cursor='pointer';
游说团(本部,15,分区)
google.maps.event.addDomListener(div,“单击”,函数(事件){
google.maps.event.trigger(我,“点击”);
});
//然后将覆盖添加到DOM中
var panes=this.getPanes();
窗格。覆盖图像。追加子对象(div);
}
//定位覆盖层
var point=this.getProjection().fromLatLngToDivPixel(this.latlng_u2;);
如果(点){
div.style.left=点x+‘px’;
div.style.top=点.y+‘px’;
}
};
CustomMarker.prototype.remove=函数(){
//检查覆盖是否在地图上并且需要删除。
如果(此.div){
this.div\u.parentNode.removeChild(this.div\u);
this.div=null;
}
};
CustomMarker.prototype.getPosition=函数(){
将此文件退还给我;
};
函数addOverlay(){
覆盖.setMap(map);
}
函数removeOverlay(){
overlay.setMap(空);
}
html{
宽度:100%;
身高:100%;
}
身体{
宽度:100%;
身高:100%;
保证金:0;
}
#地图画布{
宽度:100%;
身高:100%;
}

CustomMarker.prototype.getDraggable = function() { return false; };