I'm using the old AngularJS Material Design Data Table and would like to know how to adjust the column width.
https://github.com/daniel-nagy/md-data-table
For instance if I wanted to change the 'fat' column in the demo to a fixed width of 40px how would I go about this?
Demo: http://codepen.io/anon/pen/BjvLVJ
There is a fixed padding which seems to be the main problem.
table.md-table.md-row-select td.md-cell:nth-child(n+3):nth-last-child(n+2), table.md-table.md-row-select th.md-column:nth-child(n+3):nth-last-child(n+2) {
 padding: 0 56px 0 0;
}
You could use the following css class.
.width-override{
width:40px !important;
padding:0px !important;
}
You will need to add it to the th and td tags of the respective column like so.
<th md-column md-numeric md-order-by="fat.value" class="width-override"><span>Fat (g)</span></th>
<td md-cell class="width-override">{{dessert.fat.value | number: 2}}</td>
Please checkout the below example!
Note: The contents are of width 56px so the column is of that width, you might want to use the same, since we do not want to clip the contents inside the column.
angular.module('demoApp', ['ngMaterial', 'md.data.table'])
.config(['$mdThemingProvider', function ($mdThemingProvider) {
'use strict';
$mdThemingProvider.theme('default')
.primaryPalette('blue');
}])
.controller('nutritionController', ['$mdEditDialog', '$q', '$scope', '$timeout', function ($mdEditDialog, $q, $scope, $timeout) {
'use strict';
$scope.selected = [];
$scope.limitOptions = [5, 10, 15];
$scope.options = {
rowSelection: true,
multiSelect: true,
autoSelect: true,
decapitate: false,
largeEditDialog: false,
boundaryLinks: false,
limitSelect: true,
pageSelect: true
};
$scope.query = {
order: 'name',
limit: 5,
page: 1
};
$scope.desserts = {
"count": 9,
"data": [
{
"name": "Frozen yogurt",
"type": "Ice cream",
"calories": { "value": 159.0 },
"fat": { "value": 6.0 },
"carbs": { "value": 24.0 },
"protein": { "value": 4.0 },
"sodium": { "value": 87.0 },
"calcium": { "value": 14.0 },
"iron": { "value": 1.0 }
}, {
"name": "Ice cream sandwich",
"type": "Ice cream",
"calories": { "value": 237.0 },
"fat": { "value": 9.0 },
"carbs": { "value": 37.0 },
"protein": { "value": 4.3 },
"sodium": { "value": 129.0 },
"calcium": { "value": 8.0 },
"iron": { "value": 1.0 }
}, {
"name": "Eclair",
"type": "Pastry",
"calories": { "value": 262.0 },
"fat": { "value": 16.0 },
"carbs": { "value": 24.0 },
"protein": { "value": 6.0 },
"sodium": { "value": 337.0 },
"calcium": { "value": 6.0 },
"iron": { "value": 7.0 }
}, {
"name": "Cupcake",
"type": "Pastry",
"calories": { "value": 305.0 },
"fat": { "value": 3.7 },
"carbs": { "value": 67.0 },
"protein": { "value": 4.3 },
"sodium": { "value": 413.0 },
"calcium": { "value": 3.0 },
"iron": { "value": 8.0 }
}, {
"name": "Jelly bean",
"type": "Candy",
"calories": { "value": 375.0 },
"fat": { "value": 0.0 },
"carbs": { "value": 94.0 },
"protein": { "value": 0.0 },
"sodium": { "value": 50.0 },
"calcium": { "value": 0.0 },
"iron": { "value": 0.0 }
}, {
"name": "Lollipop",
"type": "Candy",
"calories": { "value": 392.0 },
"fat": { "value": 0.2 },
"carbs": { "value": 98.0 },
"protein": { "value": 0.0 },
"sodium": { "value": 38.0 },
"calcium": { "value": 0.0 },
"iron": { "value": 2.0 }
}, {
"name": "Honeycomb",
"type": "Other",
"calories": { "value": 408.0 },
"fat": { "value": 3.2 },
"carbs": { "value": 87.0 },
"protein": { "value": 6.5 },
"sodium": { "value": 562.0 },
"calcium": { "value": 0.0 },
"iron": { "value": 45.0 }
}, {
"name": "Donut",
"type": "Pastry",
"calories": { "value": 452.0 },
"fat": { "value": 25.0 },
"carbs": { "value": 51.0 },
"protein": { "value": 4.9 },
"sodium": { "value": 326.0 },
"calcium": { "value": 2.0 },
"iron": { "value": 22.0 }
}, {
"name": "KitKat",
"type": "Candy",
"calories": { "value": 518.0 },
"fat": { "value": 26.0 },
"carbs": { "value": 65.0 },
"protein": { "value": 7.0 },
"sodium": { "value": 54.0 },
"calcium": { "value": 12.0 },
"iron": { "value": 6.0 }
}
]
};
$scope.editComment = function (event, dessert) {
event.stopPropagation(); // in case autoselect is enabled
var editDialog = {
modelValue: dessert.comment,
placeholder: 'Add a comment',
save: function (input) {
if(input.$modelValue === 'Donald Trump') {
input.$invalid = true;
return $q.reject();
}
if(input.$modelValue === 'Bernie Sanders') {
return dessert.comment = 'FEEL THE BERN!'
}
dessert.comment = input.$modelValue;
},
targetEvent: event,
title: 'Add a comment',
validators: {
'md-maxlength': 30
}
};
var promise;
if($scope.options.largeEditDialog) {
promise = $mdEditDialog.large(editDialog);
} else {
promise = $mdEditDialog.small(editDialog);
}
promise.then(function (ctrl) {
var input = ctrl.getInput();
input.$viewChangeListeners.push(function () {
input.$setValidity('test', input.$modelValue !== 'test');
});
});
};
$scope.toggleLimitOptions = function () {
$scope.limitOptions = $scope.limitOptions ? undefined : [5, 10, 15];
};
$scope.getTypes = function () {
return ['Candy', 'Ice cream', 'Other', 'Pastry'];
};
$scope.loadStuff = function () {
$scope.promise = $timeout(function () {
// loading
}, 2000);
}
$scope.logItem = function (item) {
console.log(item.name, 'was selected');
};
$scope.logOrder = function (order) {
console.log('order: ', order);
};
$scope.logPagination = function (page, limit) {
console.log('page: ', page);
console.log('limit: ', limit);
}
}]);
body,
md-content {
background-color: #f5f5f5 !important;
}
body > md-toolbar {
z-index: 3;
}
md-toolbar.md-table-toolbar.alternate {
color: #1e88e5;
background-color: #e3f2fd;
}
md-toolbar.md-table-toolbar.alternate .md-toolbar-tools {
font-size: 16px;
}
md-card:first-child {
padding: 8px 8px 8px 24px;
}
.checkboxes > md-checkbox {
margin: 0;
padding: 16px;
min-width: 300px;
flex: 0 0 auto;
}
.width-override{
width:40px !important;
padding:0px !important;
overflow:hidden;
}
<html lang="en" ng-app="demoApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demo</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://rawgit.com/daniel-nagy/md-data-table/master/dist/md-data-table.css">
</head>
<body layout="column">
<md-toolbar class="md-whiteframe-1dp">
<div class="md-toolbar-tools">
<div class="md-title">Material Design Data Table</div>
</div>
</md-toolbar>
<md-content laout="column" flex ng-controller="nutritionController">
<md-card>
<div layout="row" layout-wrap class="checkboxes">
<md-checkbox ng-model="options.rowSelection">Row Selection</md-checkbox>
<md-checkbox ng-model="options.multiSelect">Multiple Selection</md-checkbox>
<md-checkbox ng-model="options.autoSelect">Auto Selection</md-checkbox>
<md-checkbox ng-model="options.decapitate">Decapitate</md-checkbox>
<md-checkbox ng-model="options.largeEditDialog">Lard Edit Dialogs</md-checkbox>
<md-checkbox ng-model="options.boundaryLinks">Pagination Boundary Links</md-checkbox>
<md-checkbox ng-model="options.limitSelect" ng-click="toggleLimitOptions()">Pagination Limit Select</md-checkbox>
<md-checkbox ng-model="options.pageSelect">Pagination Page Select</md-checkbox>
</div>
</md-card>
<md-card>
<md-toolbar class="md-table-toolbar md-default" ng-hide="options.rowSelection && selected.length">
<div class="md-toolbar-tools">
<span>Nutrition</span>
<div flex></div>
<md-button class="md-icon-button" ng-click="loadStuff()">
<md-icon>refresh</md-icon>
</md-button>
</div>
</md-toolbar>
<md-toolbar class="md-table-toolbar alternate" ng-show="options.rowSelection && selected.length">
<div class="md-toolbar-tools">
<span>{{selected.length}} {{selected.length > 1 ? 'items' : 'item'}} selected</span>
</div>
</md-toolbar>
<md-table-container>
<table md-table md-row-select="options.rowSelection" multiple="{{options.multiSelect}}" ng-model="selected" md-progress="promise">
<thead ng-if="!options.decapitate" md-head md-order="query.order" md-on-reorder="logOrder">
<tr md-row>
<th md-column md-order-by="name"><span>Dessert (100g serving)</span></th>
<th md-column md-order-by="type"><span>Type</span></th>
<th md-column md-numeric md-order-by="calories.value" md-desc><span>Calories</span></th>
<th md-column md-numeric md-order-by="fat.value" class="width-override"><span>Fat (g)</span></th>
<th md-column md-numeric md-order-by="carbs.value"><span>Carbs (g)</span></th>
<th md-column md-numeric md-order-by="protein.value"><span>Protein (g)</span></th>
<th md-column md-numeric md-order-by="sodium.value" hide-gt-xs show-gt-md><span>Sodium (mg)</span></th>
<th md-column md-numeric md-order-by="calcium.value" hide-gt-xs show-gt-lg><span>Calcium (%)</span></th>
<th md-column md-numeric md-order-by="iron.value" hide-gt-xs show-gt-lg><span>Iron (%)</span></th>
<th md-column md-order-by="comment">
<md-icon>comments</md-icon>
<span>Comments</span>
</th>
</tr>
</thead>
<tbody md-body>
<tr md-row md-select="dessert" md-on-select="logItem" md-auto-select="options.autoSelect" ng-disabled="dessert.calories.value > 400" ng-repeat="dessert in desserts.data | filter: filter.search | orderBy: query.order | limitTo: query.limit : (query.page -1) * query.limit">
<td md-cell>{{dessert.name}}</td>
<td md-cell>
<md-select ng-model="dessert.type" placeholder="Other">
<md-option ng-value="type" ng-repeat="type in getTypes()">{{type}}</md-option>
</md-select>
</td>
<td md-cell>{{dessert.calories.value}}</td>
<td md-cell class="width-override">{{dessert.fat.value | number: 2}}</td>
<td md-cell>{{dessert.carbs.value}}</td>
<td md-cell>{{dessert.protein.value | number: 2}}</td>
<td md-cell hide-gt-xs show-gt-md>{{dessert.sodium.value}}</td>
<td md-cell hide-gt-xs show-gt-lg>{{dessert.calcium.value}}%</td>
<td md-cell hide-gt-xs show-gt-lg>{{dessert.iron.value}}%</td>
<td md-cell ng-click="editComment($event, dessert)" ng-class="{'md-placeholder': !dessert.comment}">
{{dessert.comment || 'Add a comment'}}
</td>
</tr>
</tbody>
</table>
</md-table-container>
<md-table-pagination md-limit="query.limit" md-limit-options="limitOptions" md-page="query.page" md-total="{{desserts.count}}" md-page-select="options.pageSelect" md-boundary-links="options.boundaryLinks" md-on-paginate="logPagination"></md-table-pagination>
</md-card>
</md-content>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
<script src="https://rawgit.com/daniel-nagy/md-data-table/master/dist/md-data-table.js"></script>
</body>
</html>
Related
/* excuse my english i'm french my split is nginx.access.response_code.keyword
lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
mmmmmmmmmmmmmmmmmm
mmmmmmmmmmmmmmmmmmmmm
mmmmmmmmmmmmmmmm
*/
{
"aggs": {
"2": {
"significant_terms": {
"field": "nginx.access.response_code.keyword",
"size": 10
},
"aggs": {
"3": {
"date_histogram": {
"field": "#timestamp",
"fixed_interval": "12h",
"time_zone": "Europe/Paris",
"min_doc_count": 1
}
}
}
}
},
"size": 0,
"stored_fields": [
"*"
],
"script_fields": {},
"docvalue_fields": [
{
"field": "#timestamp",
"format": "date_time"
},
{
"field": "event.created",
"format": "date_time"
},
{
"field": "read_timestamp",
"format": "date_time"
}
],
"_source": {
"excludes": []
},
"query": {
"bool": {
"must": [],
"filter": [
{
"match_all": {}
},
{
"range": {
"#timestamp": {
"gte": "2020-11-07T14:57:01.503Z",
"lte": "2020-12-07T14:57:01.503Z",
"format": "strict_date_optional_time"
}
}
}
],
"should": [],
"must_not": [
{
"match_phrase": {
"nginx.access.response_code.keyword": {
"query": "200"
}
}
},
{
"match_phrase": {
"nginx.access.response_code.keyword": {
"query": "301"
}
}
},
{
"match_phrase": {
"nginx.access.response_code.keyword": {
"query": "304"
}
}
}
]
}
}
}
/* the result my buckets are empty */
{
"took": 302,
"timed_out": false,
"_shards": {
"total": 11,
"successful": 11,
"skipped": 10,
"failed": 0
},
"hits": {
"total": 6418480,
"max_score": null,
"hits": []
},
"aggregations": {
"2": {
"buckets": []
}
}
}
I found it. it did not exist in my data nginx.access.response_code.keyword. Be careful, Kibana does not show you your error.
How can I merge the data in stubs[] matched by port property.
{
"imposters": [
{
"protocol": "http",
"port": 9000,
"name": "sanc",
"stubs": []
},
{
"protocol": "http",
"port": 9001,
"name": "sanp",
"stubs": [
{
"predicates": [
{
"deepEquals": {
"path": "/user/access/resources"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA4yRQYvCMBCF="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/user/access/pilot"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA6quBQAAAP//AwBDv6ajAgAAAA=="
}
}
]
}
]
}
]
}
{
"imposters": [
{
"protocol": "http",
"port": 9000,
"name": "sanc",
"stubs": []
},
{
"protocol": "http",
"port": 9001,
"name": "sanp",
"stubs": [
{
"predicates": [
{
"deepEquals": {
"path": "/pay/resources"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA4yRQYvCMBCF="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/pay/5"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA6quBQAAAP//AwBDv6ajAgAAAA=="
}
}
]
}
]
}
]
}
Using the following command:
jq -s '
def merge:
{"protocol": .[0].protocol,
"port": .[0].port,
"name": .[0].name,
"stubs": (reduce .[].stubs as $item ([]; . + $item) | unique)};
[[.[].imposters[]] | group_by(.port) | .[] | merge] |
{"imposters": .}' a.json
This type of output can be generated:
{
"imposters": [
{
"protocol": "http",
"port": 9000,
"name": "sanc",
"stubs": []
},
{
"protocol": "http",
"port": 9001,
"name": "sanp",
"stubs": [
{
"predicates": [
{
"deepEquals": {
"path": "/pay/5"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA6quBQAAAP//AwBDv6ajAgAAAA=="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/pay/resources"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA4yRQYvCMBCF="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/user/access/pilot"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA6quBQAAAP//AwBDv6ajAgAAAA=="
}
}
]
},
{
"predicates": [
{
"deepEquals": {
"path": "/user/access/resources"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"body": "H4sIAAAAAAAAA4yRQYvCMBCF="
}
}
]
}
]
}
]
}
Currently query below removes duplicates on a single field - "name", but we need top_hits results for all fields:"name", "venueName", "venueTown". Is this possible to achieve within one query without sending 3 requests and setting "field" to be "venueName" and "venueTown"?
{
"aggs": {
"query": {
"terms": {
"field": "name"
}
,
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
}
},
"size": 0,
"query": {
"multi_match": {
"query": "LAURA",
"operator": "OR",
"fields": [
"name",
"venueName",
"venueTown"
]
}
}
}
If I understand correctly, you can write multiple aggregations with top hits.
{
"query": {
"multi_match": {
"query": "LAURA",
"fields": [
"name",
"venueName",
"venueTown",
]
}
},
"aggs": {
"name": {
"terms": {
"field": "name"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
},
"venue_name": {
"terms": {
"field": "venueName"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
},
"venue_town": {
"terms": {
"field": "venueTown"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
}
}
}
Been on this for a while now, I need to make the map height 100% of its container. And also keep it centred when its resizing.
I have tried nearly all of the examples on here with no avail..
The code example below shows what I am using, there's markers and infowindows in there and also custom marker symbols too. I don't get any errors in the console.
<script type="text/javascript">
var markers = [
{
"title": 'xxxxx School',
"lat": '53.004758',
"lng": '-2.241232',
"description": '<br/>View more info',
"type": 'UK Independent School'
},
{
"title": 'xxxxx Prep',
"lat": '51.470123',
"lng": '-0.209838',
"description": '<br/>View more info',
"type": 'UK Independent School'
},
{
"title": 'xxxxxx',
"lat": '46.709741',
"lng": '9.159625',
"description": '<br/>View more info',
"type": 'Swiss Boarding School'
},
{
"title": 'xxxxxxx independent College',
"lat": '51.512103',
"lng": '-0.308055',
"description": '83 New Broadway, <br/>London W5 5AL, <br/>United Kingdom <br/>View more info',
"type": 'UK Independent School'
},
{
"title": 'xxxxxxx Hill',
"lat": '51.007720',
"lng": '0.217913',
"description": 'Five Ashes, <br/>Mayfield, <br/>East Sussex <br/>TN20 6HR, <br/>United Kingdom <br/>View more info',
"type": 'UK Independent School'
}
];
var map;
function initMap() {
var mapOptions = {
center: new google.maps.LatLng(51.507351, -0.127758),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}]
};
var infoWindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var i = 0;
var interval = setInterval(function () {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var icon = "";
switch (data.type) {
case "UK Independent School":
icon = "orange";
break;
case "Swiss Boarding School":
icon = "green";
break;
}
icon = "http://fokn.temp-dns.com/images/site/icon-" + icon + ".png";
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title,
animation: google.maps.Animation.DROP,
icon: new google.maps.MarkerImage(icon)
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent("<div style = 'width:200px;min-height:40px'><strong>" + data.title + "</strong><br/>" + data.description + "</div>");
infoWindow.open(map, marker);
});
})(marker, data);
latlngbounds.extend(marker.position);
i++;
if (i == markers.length) {
clearInterval(interval);
var bounds = new google.maps.LatLngBounds();
map.setCenter(latlngbounds.getCenter());
map.fitBounds(latlngbounds);
}
}, 80);
}
</script>
<div style="width:100%; height:100%;">
<div id="dvMap" style="width:100%; height:100%;"></div>
</div>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY-API&callback=initMap"></script>
You need to give sizes to all the elements up to the <html> element:
html, body, #dvMap {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
Mike Williams' Google Maps Javascript API v2 page on this subject: Using a percentage height for the map div
proof of concept fiddle
code snippet:
var markers = [{
"title": 'xxxxx School',
"lat": '53.004758',
"lng": '-2.241232',
"description": '<br/>View more info',
"type": 'UK Independent School'
}, {
"title": 'xxxxx Prep',
"lat": '51.470123',
"lng": '-0.209838',
"description": '<br/>View more info',
"type": 'UK Independent School'
}, {
"title": 'xxxxxx',
"lat": '46.709741',
"lng": '9.159625',
"description": '<br/>View more info',
"type": 'Swiss Boarding School'
}, {
"title": 'xxxxxxx independent College',
"lat": '51.512103',
"lng": '-0.308055',
"description": '83 New Broadway, <br/>London W5 5AL, <br/>United Kingdom <br/>View more info',
"type": 'UK Independent School'
}, {
"title": 'xxxxxxx Hill',
"lat": '51.007720',
"lng": '0.217913',
"description": 'Five Ashes, <br/>Mayfield, <br/>East Sussex <br/>TN20 6HR, <br/>United Kingdom <br/>View more info',
"type": 'UK Independent School'
}];
var map;
function initMap() {
var mapOptions = {
center: new google.maps.LatLng(51.507351, -0.127758),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [{
"featureType": "landscape",
"stylers": [{
"saturation": -100
}, {
"lightness": 65
}, {
"visibility": "on"
}]
}, {
"featureType": "poi",
"stylers": [{
"saturation": -100
}, {
"lightness": 51
}, {
"visibility": "simplified"
}]
}, {
"featureType": "road.highway",
"stylers": [{
"saturation": -100
}, {
"visibility": "simplified"
}]
}, {
"featureType": "road.arterial",
"stylers": [{
"saturation": -100
}, {
"lightness": 30
}, {
"visibility": "on"
}]
}, {
"featureType": "road.local",
"stylers": [{
"saturation": -100
}, {
"lightness": 40
}, {
"visibility": "on"
}]
}, {
"featureType": "transit",
"stylers": [{
"saturation": -100
}, {
"visibility": "simplified"
}]
}, {
"featureType": "administrative.province",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "water",
"elementType": "labels",
"stylers": [{
"visibility": "on"
}, {
"lightness": -25
}, {
"saturation": -100
}]
}, {
"featureType": "water",
"elementType": "geometry",
"stylers": [{
"hue": "#ffff00"
}, {
"lightness": -25
}, {
"saturation": -97
}]
}]
};
var infoWindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var i = 0;
var interval = setInterval(function() {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var icon = "";
switch (data.type) {
case "UK Independent School":
icon = "orange";
break;
case "Swiss Boarding School":
icon = "green";
break;
}
icon = "http://maps.google.com/mapfiles/ms/micons/" + icon + ".png";
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title,
animation: google.maps.Animation.DROP,
icon: icon
});
(function(marker, data) {
google.maps.event.addListener(marker, "click", function(e) {
infoWindow.setContent("<div style = 'width:200px;min-height:40px'><strong>" + data.title + "</strong><br/>" + data.description + "</div>");
infoWindow.open(map, marker);
});
})(marker, data);
latlngbounds.extend(marker.position);
i++;
if (i == markers.length) {
clearInterval(interval);
var bounds = new google.maps.LatLngBounds();
map.setCenter(latlngbounds.getCenter());
map.fitBounds(latlngbounds);
}
}, 80);
}
google.maps.event.addDomListener(window, 'load', initMap);
html,
body,
#dvMap {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div style="width:100%; height:100%;">
<div id="dvMap"></div>
</div>
I am trying to direct multiple polylines to a particular marker in a map.
I am able to draw the polylines to the marker but when I try to animate the same only the last polyline is working. The link below shows the map I made.
http://jsbin.com/ihugur/1/edit
Also this is the code:
<html>
<head>
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0;
padding: 0
}
#map_canvas {
height: 100%
}
</style>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBdTuWJjEUMvQZ6VVPGksE12XNgQgs__Qk&sensor=false&libraries=visualization"></script>
<script language="javascript">
var line;
var myLatlng = new google.maps.LatLng(41.7833, 5.2167);
var marker;
function initialize(){
var styles = [
{
"featureType": "administrative.country",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "administrative",
"elementType": "geometry",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "landscape",
"stylers": [
{ "visibility": "on" },
{ "color": "#C0C0C0" }
]
},{
"featureType": "water",
"stylers": [
{ "visibility": "on" },
{ "color": "#FFFFFF" }
]
},{
"featureType": "landscape.man_made",
"stylers": [
{ "visibility": "off" },
{ "color": "#efffff" }
]
},{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "transit",
"stylers": [
{ "visibility": "off" }
]
}
];
var symbolOne = {
strokeColor: '#F00',
fillColor: '#F00',
fillOpacity: 1
};
var domain = [new google.maps.LatLng(11.2583, 75.1374)];
var markers = [];
var mapOptions = {
zoom:2,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
opacity: 0.2,
disableDefaultUI: true,
draggable: false,
styles: styles
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var lineCoordinates = [
new google.maps.LatLng(53.215556, 56.949219),
new google.maps.LatLng(75.797201, 125.003906),
new google.maps.LatLng(37.7833, 144.9667),
new google.maps.LatLng(-24.797201, 26.003906),
new google.maps.LatLng(27.797201, -101.003906)
];
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_OPEN_ARROW
};
for(i=0;i<lineCoordinates.length;i++){
markers.push(new google.maps.Marker({
position: lineCoordinates[i],
map: map,
}));
line = new google.maps.Polyline({
path: [lineCoordinates[i], domain[0]],
strokeOpacity: 0.8,
strokeWeight:2,
strokeColor: '#f00',
geodesic: true,
icons: [{
icon: lineSymbol,
offset: '100%',
repeat: '30px'
}]
});
line.setMap(map);
} //end of for loop
animate();
} //end of initialize function
function animate(){
var count = 0;
offsetId = window.setInterval(function(){
count = (count + 1) % 2000;
var icons = line.get('icons');
icons[0].offset = (count / 2) + '%';
line.set('icons', icons);
}, 200);
}// end of animate function
</script>
</head>
<body onLoad="initialize()">
<div id="map_canvas" style="width: 1000px; height: 675px; margin-left: 400px; margin-top: 38px;"></div>
</select>
</body>
</html>
Could anyone help me fixing this problem.
Thanks in advance.
Make an array to hold all your polylines:
var lines = [];
push your existing line(s) on that array:
lines.push(line);
Process through them updating the icons.
function animate(){
var count = 0;
offsetId = window.setInterval(function(){
count = (count + 1) % 2000;
for (var i=0; i<lines.length; i++) {
var icons = lines[i].get('icons');
icons[0].offset = (count / 2) + '%';
lines[i].set('icons', icons);
}
}, 200);
}// end of animate function
example
code snippet:
var line;
var lines = [];
var myLatlng = new google.maps.LatLng(41.7833, 5.2167);
var marker;
function initialize() {
var styles = [{
"featureType": "administrative.country",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "administrative",
"elementType": "geometry",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "landscape",
"stylers": [{
"visibility": "on"
}, {
"color": "#C0C0C0"
}]
}, {
"featureType": "water",
"stylers": [{
"visibility": "on"
}, {
"color": "#FFFFFF"
}]
}, {
"featureType": "landscape.man_made",
"stylers": [{
"visibility": "off"
}, {
"color": "#efffff"
}]
}, {
"featureType": "poi",
"elementType": "geometry",
"stylers": [{
"visibility": "off"
}]
}, {
"featureType": "transit",
"stylers": [{
"visibility": "off"
}]
}];
var symbolOne = {
strokeColor: '#F00',
fillColor: '#F00',
fillOpacity: 1
};
var domain = [new google.maps.LatLng(11.2583, 75.1374)];
var markers = [];
var mapOptions = {
zoom: 1,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
opacity: 0.2,
disableDefaultUI: true,
draggable: false,
styles: styles
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var lineCoordinates = [
new google.maps.LatLng(53.215556, 56.949219),
new google.maps.LatLng(75.797201, 125.003906),
new google.maps.LatLng(37.7833, 144.9667),
new google.maps.LatLng(-24.797201, 26.003906),
new google.maps.LatLng(27.797201, -101.003906)
];
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_OPEN_ARROW
};
for (i = 0; i < lineCoordinates.length; i++) {
markers.push(new google.maps.Marker({
position: lineCoordinates[i],
map: map
}));
line = new google.maps.Polyline({
path: [lineCoordinates[i], domain[0]],
strokeOpacity: 0.8,
strokeWeight: 2,
strokeColor: '#f00',
geodesic: true,
icons: [{
icon: lineSymbol,
offset: '100%',
repeat: '30px'
}]
});
line.setMap(map);
lines.push(line);
} //end of for loop
// alert(lines.length);
animate();
} //end of initialize function
function animate() {
var count = 0;
offsetId = window.setInterval(function() {
count = (count + 1) % 2000;
for (var i = 0; i < lines.length; i++) {
var icons = lines[i].get('icons');
icons[0].offset = (count / 2) + '%';
lines[i].set('icons', icons);
}
}, 200);
} // end of animate function
google.maps.event.addDomListener(window, 'load', initialize);
html {
height: 100%;
width: 100%;
}
body {
height: 100%;
width: 100% margin: 0;
padding: 0
}
#map_canvas {
height: 100%;
width: 100%;
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas" style="width: 100%; height: 100%; "></div>