- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究公交方向,并且已经能够使用 polylineOptions 属性更改为公交路线显示的多段线的颜色。
但是,我无法更改为步行路线显示的虚线颜色。
我确实遇到过这个解决方案,但它不适用于 v3(尝试使用 v3.22)
Similar StackOverflow Question
我在这个 JS Fiddle 中包含了一个工作示例
var directions = new google.maps.DirectionsService();
var renderer = new google.maps.DirectionsRenderer({
polylineOptions: {
strokeColor: '#C83939',
strokeOpacity: 0.8,
strokeWeight: 7
}
});
var map, transitLayer;
function initialize() {
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(40.7482333, -73.8681295),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
google.maps.event.addDomListener(document.getElementById('go'), 'click',
route);
var input = document.getElementById('from');
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
transitLayer = new google.maps.TransitLayer();
var control = document.getElementById('transit-wpr');
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(control);
google.maps.event.addDomListener(control, 'click', function() {
transitLayer.setMap(transitLayer.getMap() ? null : map);
});
addDepart();
route();
}
function addDepart() {
var depart = document.getElementById('depart');
for (var i = 0; i < 24; i++) {
for (var j = 0; j < 60; j += 15) {
var x = i < 10 ? '0' + i : i;
var y = j < 10 ? '0' + j : j;
depart.innerHTML += '<option>' + x + ':' + y + '</option>';
}
}
}
function route() {
var departure = document.getElementById('depart').value;
var bits = departure.split(':');
var now = new Date();
var tzOffset = (now.getTimezoneOffset() + 60) * 60 * 1000;
var time = new Date();
time.setHours(bits[0]);
time.setMinutes(bits[1]);
var ms = time.getTime() - tzOffset;
if (ms < now.getTime()) {
ms += 24 * 60 * 60 * 1000;
}
var departureTime = new Date(ms);
var request = {
origin: document.getElementById('from').value,
destination: '51 St, New York, NY 10022, USA',
travelMode: google.maps.DirectionsTravelMode.TRANSIT,
provideRouteAlternatives: true,
transitOptions: {
departureTime: departureTime
}
};
var panel = document.getElementById('panel');
panel.innerHTML = '';
directions.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
renderer.setDirections(response);
renderer.setMap(map);
renderer.setPanel(panel);
console.log(renderer.getDirections());
} else {
renderer.setMap(null);
renderer.setPanel(null);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body {
height: 100%;
padding: 0;
margin: 0;
color: black;
font-family: arial, sans-serif;
font-size: 13px;
}
#map {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 50%;
}
#panel-wpr {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
right: 0;
overflow: auto;
}
#panel {
font-family: arial;
padding: 0 5px;
}
#info {
padding: 5px;
}
#from {
width: 90%;
font-size: 1.2em;
}
.adp-directions {
width: 100%;
}
.input {
background-color: white;
padding-left: 8px;
border: 1px solid #D9D9D9;
border-top: 1px solid silver;
-webkit-border-radius: 1px;
-moz-border-radius: 1px;
border-radius: 1px;
}
.time {
margin: 0;
height: 17px;
border: 1px solid;
border-top-color: #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #CCC;
padding: 2px 15px 1px 1px;
}
button {
border: 1px solid #3079ED;
color: white;
background-color: #4D90FE;
background-image: -webkit-gradient(linear, left top, left bottom, from(#4D90FE), to(#4787ED));
background-image: -webkit-linear-gradient(top, #4D90FE, #4787ED);
background-image: -moz-linear-gradient(top, #4D90FE, #4787ED);
background-image: -ms-linear-gradient(top, #4D90FE, #4787ED);
background-image: -o-linear-gradient(top, #4D90FE, #4787ED);
background-image: linear-gradient(top, #4D90FE, #4787ED);
filter: progid: DXImageTransform.Microsoft.gradient(startColorStr='#4d90fe', EndColorStr='#4787ed');
display: inline-block;
min-width: 54px;
text-align: center;
font-weight: bold;
padding: 0 8px;
line-height: 27px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-transition: all 0.218s;
-moz-transition: all 0.218s;
-o-transition: all 0.218s;
transition: all 0.218s;
}
#info div {
line-height: 22px;
font-size: 110%;
}
.btn {} #panel-wpr {
border-left: 1px solid #e6e6e6;
}
#info {
border-bottom: 1px solid #E6E6E6;
margin-bottom: 5px;
}
h2 {
margin: 0;
padding: 0;
}
<title>Google Maps JavaScript API v3 Example: Transit</title>
<div id="transit-wpr">
<button id="transit">Toggle transit layer</button>
</div>
<div id="map"></div>
<div id="panel-wpr">
<div id="info">
<div>
<h2>Transit directions</h2>
</div>
<div>
<label>from:</label>
<input class="input" id="from" value="Grand Central 42, NY">
</div>
<div>
<label>to:</label>
<strong>51 St, New York, NY 10022, USA</strong>
</div>
<div>Depart at
<select id="depart"></select>
</div>
<div class="btn">
<button id="go">Get Directions</button>
</div>
</div>
<div id="panel"></div>
</div>
我错过了任何可用的属性,或者这是不可能的?
最佳答案
这些线的选项是固定的,不会受到 DirectionsRenderer 的 polylineOptions 的影响。
这些虚线的 polylineOptions 将(当前)由 API 设置为:
{
"icons": [{
"icon": {
"path": 0,
"scale": 3,
"fillOpacity": 0.7,
"fillColor": "#00b3fd",
"strokeOpacity": 0.8,
"strokeColor": "#3379c3",
"strokeWeight": 1
},
"repeat": "10px"
}],
"strokeColor": "#000000",
"strokeOpacity": 0,
"strokeWeight": 5
}
...DirectionsRenderer 的任何自定义 polylineOption 都将被忽略。
可能的解决方法(但只能为所有这些虚线设置一个固定值):
function initMap() {
var goo = google.maps,
map = new goo.Map(document.getElementById('map'), {
zoom: 7,
center: {lat: 41.85, lng: -87.65}
}),
directionsService = new goo.DirectionsService,
directionsDisplay = new goo.DirectionsRenderer({
map:map,
polylineOptions:{
strokeColor:'red'
}});
google.maps.Polyline.prototype.setMap=(function(f,r){
return function(map){
if(
this.get('icons')
&&
this.get('icons').length===1
&&
this.get('strokeOpacity')===0
&&
!this.get('noRoute')
){
if(r.get('polylineOptions')&& r.get('polylineOptions').strokeColor){
var icons=this.get('icons'),
color=r.get('polylineOptions').strokeColor;
icons[0].icon.fillOpacity=1;
icons[0].icon.fillColor=color;
icons[0].icon.strokeColor=color;
this.set('icons',icons);
}}
f.apply(this,arguments);
}
})(
google.maps.Polyline.prototype.setMap,
directionsDisplay);
directionsService.route({
origin: new google.maps.LatLng(52.549917, 13.42539669),
destination: new google.maps.LatLng(52.541843, 13.4206566),
travelMode: google.maps.TravelMode.TRANSIT
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
html, body,#map {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
async defer></script>
它覆盖 google.maps.Polyline
的 setMap
方法
它检查是否
noRoute
属性(如果您自己绘制符合前两个条件的折线,请将 noRoute
选项设置为 true ,否则他们也会受到影响)当所有 3 个条件都为真时,它将修改折线的图标属性。
关于javascript - 如何更改 Google map v3 方向上虚线的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35502342/
我正在使用 MapBox 绘制兴趣点,这些兴趣点是通过基于 Rails 构建的用户生成表单提交的。当前,用户输入一个地址,然后该地址通过 gem(地理编码器)计算出 Lat 和 Lng。从那里我通过
我正在纵向平板电脑上开发应用程序。 但是,当平板电脑转到横向模式时,应用程序也会转动,并且所有对齐方式都将被取消。那么有什么方法可以将我的 WPF 应用程序锁定到一个方向? 谢谢! 最佳答案 我必须同
我在我的应用程序中的 mkmapview 上显示了两点之间的路线,但我想显示这两点的方向。点的纬度和经度存储在 NSArray 中。 最佳答案 这可能为时已晚,您可能已经解决了它,但这是我已经测试过并
我正在处理一个小型 Unity3D 项目,我需要从另一个工具导入一些数据。该工具通过两个向量为我提供了对象方向,我需要将其移植到 Unity。 例如,我有这两个向量; x = Vector( 0.70
有没有办法以编程方式设置 UIActionSheet 的方向?我的 iPhone 方向是纵向,但 UIActionSheet 需要是横向。这可以吗? 编辑: 所以我的问题是我不想将 rootviewc
如何在 Python 中根据 2 个 GPS 坐标计算速度、距离和方向(度)?每个点都有纬度、经度和时间。 我在这篇文章中找到了半正矢距离计算: Calculate distance between
需要一个代码来更改 div 的属性,具体取决于 iPhone 设备的位置。在这段代码工作之前现在停止这样做了吗? @media all and (orientation:portrait) { .
在“View Did Load”中,我试图确定 View 的大小,以便我可以适本地调整 subview 的大小。我希望它始终围绕屏幕的长度和宽度拉伸(stretch),而不管方向如何。 quest *
如何根据对象的方向移动对象?我的意思是,我有一个处于某个位置的立方体,我想绕 Y 轴旋转并根据它们的方向移动。然后再次移动和旋转以改变方向。像这样的事情: 最佳答案 在 JS 中你可以尝试这样的事情:
我目前有一个处于横向模式的 SurfaceView。 目前我正在尝试使用添加操作栏/菜单栏 /*Action Bar */ //this.setRequestedOrientation(Activit
我正在使用 cocos2d,我想播放电影。为此,我创建了 MPMoviePlayerViewController 并将其作为 [[CCDirector sharedDirector] openGLVi
我在 cocos2d 中创建了一个游戏,因为我想使用我找到的一些 UIKit 元素 kobold2d。 我移植了游戏,但问题是我的 iPhone 刺激器旋转了, 但不是显示的节点。 必须使用: bac
我可以在 iOS 中的 UITabBarController 中更改方向吗?我有这样的东西: UITableViewController-> Team Tab -> UINavigationContr
我有 UINavigationController 和几个 View Controller 。这是他们的名单:主->相册->图片 现在,在第一个和第二个(主要和专辑)中,我希望 UINavigatio
人们普遍认为,在过去几年中,标准显示器的最佳网站宽度已从 800 像素增加到 1024+ 像素(网站通常为 960 像素宽),但随着移动设备的兴起,哪些分辨率被认为是“关键”迎合? 例如,this
我正在做一个 GTK+ 项目,我需要一个像这样的垂直 GtkLevelBar: 但我不知道如何从默认的水平 GtkLevelBar 翻转它: 这是我的 GtkLevelBar 代码。 GtkWidge
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我的 collectionView 以横向模式显示 20 个项目。在纵向模式下,我只想展示 8 个可重复使用的项目。我怎样才能做到这一点? collectionView 何时在数据源上调用 colle
可以在 list 文件中设置 Activity 的方向。 但是否也可以通过代码来实现?如果是,怎么办? 谢谢! 最佳答案 setRequestedOrientation(ActivityInfo.SC
我希望在纬度、经度和用户当前位置之间集成方向。我希望通过点击按钮将用户定向到已安装的 Google map /其他应用程序并显示方向。 我搜索了 SO 和谷歌,但找不到好的来源,因此我发布了这个问题。
我是一名优秀的程序员,十分优秀!