内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/27261346/custom-svg-markers-wont-display-in-ie-11
我试图使用Google数据层显示一些巴士路线,然后添加一些自定义图标标记.在Chrome和Firefox中效果很好,但在IE 11中,我只能获得路线.我在某些混淆的代码深处有一个InvalidStateError.
标记使用一些内联SVG的数据uri,该SVG转换为64个字符串.我也试过没有转换到64位;这不会产生任何明显的错误,但标记仍然不显示.
简化的JavaScript被粘贴在下面,您可以在 jsfiddle 看到它.
var map;
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 11,
center: {lat: 38.813605, lng: -89.957399}
});
var geoJsonRoutesUrl = 'https://storage.googleapis.com/gtfs-test/MCT-All-Bus-Routes.json';
var routesLayer = new google.maps.Data();
routesLayer.loadGeoJson(geoJsonRoutesUrl);
routesLayer.setMap(map);
routesLayer.setStyle(function(feature) {
return ({
strokeColor: feature.getProperty('color'),
fillColor: feature.getProperty('color'),
strokeWeight: 6
});
});
var geoJsonRouteMarkersUrl = 'https://storage.googleapis.com/gtfs-test/MCT-All-Bus-Route-Markers.json';
var routeMarkersLayer = new google.maps.Data();
routeMarkersLayer.loadGeoJson(geoJsonRouteMarkersUrl);
routeMarkersLayer.setMap(map);
routeMarkersLayer.setStyle(function(feature) {
var markerIcon = CreateRouteMarkersIconDefinition(
feature.getProperty('route'),
feature.getProperty('color'),
feature.getProperty('backColor'));
return ({icon: markerIcon});
});
function CreateRouteMarkersIconDefinition(route, color, backColor) {
var svgHtml = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" width="30" height="30">';
svgHtml += '<ellipse cx="15" cy="15" r="15" rx="15" ry="10" fill="' + backColor + '" />';
svgHtml += '<text x="15" y="20" style="text-anchor: middle;" font-family="Verdana" font-size="12px" font-weight = "bold" fill="' + color + '" >' + route + '</text>';
svgHtml += '</svg>';
var svgIcon = {
url: 'data:image/svg+xml;charset=UTF-8;base64,' + btoa(svgHtml),
anchor: new google.maps.Point(15, 15)
};
return svgIcon;
}
我有一个类似的问题,最终发现你可以得到SVG和数据URI SVG图像的工作,但SVG需要一些其他图像类型不需要的参数.
具体来说,一旦我对图标的定义(以及uri,origin和anchor值)的尺寸和缩放尺寸参数,错误就消失,标记被渲染.
我的样本标记如下(svg已被定义为SVG,我想要作为标记):
var bubbleImage = {
url: 'data:image/svg+xml;base64,' + Base64.encode(svg),
size: new google.maps.Size(192, 21),
scaledSize: new google.maps.Size(192,21),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(88, 53)
};
var bubbleMarker = new google.maps.Marker({
position: feature.position,
icon: bubbleImage,
map: window.map,
optimized: false,
zIndex: 1
});
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/27261346/custom-svg-markers-wont-display-in-ie-11
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- YAML,另一种标记语言?不止是标记语言
- html5 – 用于span标记的Twitter Bootstrap工具提示(不适用于标记)
- 开发 地图标记工具 后记
- WPF标记扩展的笔记
- IOS自动进行View标记
- xml – 在标记中嵌入XSL代码
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。