Javascript Google Maps API imagePath本地图像不工作
我已经使用过,并且按照我的期望工作 然而,我在Javascript Google Maps API imagePath本地图像不工作,javascript,php,google-maps,google-maps-api-3,google-maps-markers,Javascript,Php,Google Maps,Google Maps Api 3,Google Maps Markers,我已经使用过,并且按照我的期望工作 然而,我在MarkerClusterer-imagePath中遇到了一个奇怪的问题。当我设置这个 imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m“, 工作正常。但是当我这么做的时候 var imgpath = '<?= SITE_ROOT_IMAGE_DEFAULT ; ?>m3.png'; ima
MarkerClusterer
-imagePath
中遇到了一个奇怪的问题。当我设置这个
imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m“,
工作正常。但是当我这么做的时候
var imgpath = '<?= SITE_ROOT_IMAGE_DEFAULT ; ?>m3.png';
imagePath: imgpath,
var-imgpath='m3.png';
imagePath:imgpath,
并提醒它给我正确的相对路径,/var/www/html/my-app/webroot/img/m3.png
我在哪里下载了这张图片。但它不起作用
我还尝试通过http
添加
imagePath:'http://localhost/my-app/img/m3.png“,
我可以看到我的图像,但它不工作
仅供参考,我还在本地服务器上下载了我的markerclusterer.js
库,并仅从本地服务器请求。我正在使用
我也尝试过不同的方法,比如
imagePath:“../img/m”,
但它也不工作
有人能告诉我我做错了什么吗?为什么没有拍摄我的imagePath
阅读,它说:要使用您自己的自定义群集图像,只需将图像命名为m[1-5].png
或将imagePath选项设置为图像的位置和名称,如下所示:imagePath:'customImages/cat'
对于图像cat1.png
到cat5.png
您应该对声明此路径的文件使用相对路径
下面是一个文件夹结构示例:
- cluster_images
- m1.png
- m2.png
- m3.png
- m4.png
- m5.png
- main.js
如果使用上述文件夹结构在文件main.js
中声明imagePath
,则它应该是:
var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'cluster_images/m'});
编辑:
如果要分别设置每个图像的样式并定义图像大小,则应使用样式
参数并分别声明每个簇图标
mcOptions = {
styles: [{
height: 53,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m1.png",
width: 53
},
{
height: 56,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m2.png",
width: 56
},
{
height: 66,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m3.png",
width: 66
},
{
height: 78,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m4.png",
width: 78
},
{
height: 90,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m5.png",
width: 90
}
]
}
//init clusterer with your options
var markerCluster = new MarkerClusterer(map, markers, mcOptions);
上面的代码使用默认图像。将URL再次替换为每个图像的相对路径,并更新大小以避免图像拉伸。阅读说明:要使用您自己的自定义群集图像,只需将图像命名为m[1-5].png
或将imagePath选项设置为图像的位置和名称,如下所示:imagePath:“customImages/cat”
对于图像cat1.png
设置为cat5.png
您应该对声明此路径的文件使用相对路径
下面是一个文件夹结构示例:
- cluster_images
- m1.png
- m2.png
- m3.png
- m4.png
- m5.png
- main.js
如果使用上述文件夹结构在文件main.js
中声明imagePath
,则它应该是:
var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'cluster_images/m'});
编辑:
如果要分别设置每个图像的样式并定义图像大小,则应使用样式
参数并分别声明每个簇图标
mcOptions = {
styles: [{
height: 53,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m1.png",
width: 53
},
{
height: 56,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m2.png",
width: 56
},
{
height: 66,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m3.png",
width: 66
},
{
height: 78,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m4.png",
width: 78
},
{
height: 90,
url: "https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images/m5.png",
width: 90
}
]
}
//init clusterer with your options
var markerCluster = new MarkerClusterer(map, markers, mcOptions);
上面的代码使用默认图像。将URL再次替换为每个图像的相对路径,并更新大小以避免图像拉伸