cre*_*ame 43 javascript svg google-maps google-maps-api-3
我的SVG地图标记在IE11上消失了.它在Chrome,Firefox,Safari,IE9和10中都可见,但不是11.我已经上传了我当前代码的JSfiddle.我不知道这是我还是谷歌地图的错误.
<html>
<head>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCyfFUUVxVyoCicnttJfj-w63wzfbTKV3Y&sensor=false">
</script>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script>
function initialize() {
var sanfrancisco = new google.maps.LatLng(37.78062,-122.397203);
var mapOptions = {
zoom: 18,
zIndex:0,
center: sanfrancisco,
mapTypeControl: true,
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'usroadatlas']
},zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
// var image = 'img/1p_marker3.png';
var image = 'http://firstperson.is/assets/img/contact/map_marker.svg';
var marker = new google.maps.Marker({
position: sanfrancisco,
map: map,
icon: image
});
var roadAtlasStyles = [
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "landscape",
"elementType": "geometry.fill",
"stylers": [
{ "color": "#003a70" }
]
},{
"featureType": "landscape",
"elementType": "geometry.stroke",
"stylers": [
{ "color": "#0075c9" }
]
},{
"featureType": "administrative.land_parcel",
"stylers": [
{ "visibility": "off" }
]
},{
"elementType": "labels.text.fill",
"stylers": [
{ "color": "#ffffff" }
]
},{
"elementType": "labels.text.stroke",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [
{ "color": "#0075c9" }
]
},{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{ "color": "#ffffff" }
]
},{
"featureType": "road.local",
"elementType": "geometry",
"stylers": [
{ "color": "#0075c9" }
]
},{
"featureType": "road.highway",
"elementType": "geometry",
"stylers": [
{ "color": "#d0343a" }
]
},{
"featureType": "road.highway.controlled_access",
"elementType": "geometry",
"stylers": [
{ "color": "#ff4539" }
]
},{
"featureType": "transit.line",
"elementType": "geometry",
"stylers": [
{ "color": "#0075c9" }
]
},{
"featureType": "transit",
"elementType": "labels.text.fill",
"stylers": [
{ "color": "#ffffff" }
]
},{
"featureType": "poi",
"elementType": "labels.icon",
"stylers": [
{ "invert_lightness": true },
{ "hue": "#0077ff" }
]
},{
"featureType": "poi",
"elementType": "labels.text",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "poi",
"elementType": "labels",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "poi.park",
"elementType": "labels.text.fill",
"stylers": [
{ "visibility": "on" },
{"color":"#ffffff"}
]
},{
"featureType": "poi.park",
"elementType": "labels.icon",
"stylers": [
{ "visibility": "on" }
]
},{
"featureType": "poi.sports_complex",
"elementType": "labels.text.fill",
"stylers": [
{ "visibility": "on" },
{"color":"#ffffff"}
]
},{
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [
{ "color": "#ffffff" }
]
},{
"featureType": "administrative.neighborhood",
"elementType": "labels.text",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "administrative.province",
"elementType": "geometry",
"stylers": [
{ "visibility": "on" },
{ "weight": 0.9 }
]
}
];
var styledMapOptions = {
name: 'US Road Atlas'
};
var usRoadMapType = new google.maps.StyledMapType(
roadAtlasStyles, styledMapOptions);
map.mapTypes.set('usroadatlas', usRoadMapType);
map.setMapTypeId('usroadatlas');
// var transitLayer = new google.maps.TransitLayer();
// transitLayer.setMap(map);
};
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Joh*_*n B 98
添加scaledSize到图像/图标和optimized: false标记为我解决了它.
var image = {
url: 'https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/svgs/fi-marker.svg',
scaledSize: new google.maps.Size(100, 100),
}
var marker = new google.maps.Marker({
position: sanfrancisco,
map: map,
optimized: false,
icon: image
});
Run Code Online (Sandbox Code Playgroud)
Google Maps目前似乎不支持将SVG用于标记图像.但是,您可以使用Symbol对象来设置矢量标记图标.
我不确定这是否有帮助:
明智的做法是同时定义width地图区域。例如:
#map-canvas { height: 100%; width: 100%; }
Run Code Online (Sandbox Code Playgroud)
IE10 是唯一一个抱怨开头没有以下行的浏览器
<!DOCTYPE html>
Run Code Online (Sandbox Code Playgroud)
一条评论:标记很大,当您缩小时保持相同的大小。
没有帮助。在 BrowserStack 上运行代码(使用 DOCTYPE 行)我在控制台中收到消息:
InvalidStateError (line 39)
Run Code Online (Sandbox Code Playgroud)
这行不是来自脚本,因为如果我更改/删除某些内容,消息是相同的。
| 归档时间: |
|
| 查看次数: |
20623 次 |
| 最近记录: |