Implementing google markerclusterer plus into stencil webcomponents - google-maps

I read a lot about how to implementing external files into stencil but nothing worked yet like I want it. The speciality is that stencil runs in a Liferay theme. But I think that shouldn't matter.
I installed the MarkerClustererPlus from google via npm and in the stencil config i copy the min file into an "asset" folder like this:
import { Config } from '#stencil/core';
import { sass } from '#stencil/sass';
import nodePolyfills from 'rollup-plugin-node-polyfills';
export const config: Config = {
namespace: 'gwkp-components',
srcDir: 'src/js/components',
plugins: [
sass({
injectGlobalPaths: [
'build/css/clay/_mixins.scss',
'build/css/fonts/font-awesome/scss/_mixins.scss',
'build/css/fonts/font-awesome/scss/_variables.scss',
'build/css/fonts/font-awesome/scss/_core.scss',
'src/js/components/utils/_stencilvars.scss',
'build/css/fonts/font-awesome/scss/regular.scss',
'build/css/fonts/font-awesome/scss/light.scss',
'build/css/fonts/font-awesome/scss/solid.scss',
'build/css/clay/bootstrap/_functions.scss',
'build/css/clay/bootstrap/_mixins.scss',
'build/css/clay/bootstrap/_variables.scss',
'src/css/gw/_colors.scss',
'src/css/gw/_variables.scss',
'src/css/gw/bem/_includes.scss'
]
})
],
outputTargets: [
{
type: 'www',
buildDir: '.',
dir: 'build/js/components',
serviceWorker: null, // disable service workers
copy: [
{ src: '../../../build/css/fonts/font-awesome/webfonts', dest: 'webfonts' },
{ src: '../../../node_modules/#google/markerclustererplus/dist/markerclustererplus.min.js', dest: 'assets/js/markerclustererplus.min.js' }
]
}
],
rollupPlugins: {
after: [
nodePolyfills()
]
}
};
Now the question arises how to get access to the min.js file? Do I need an import statement and declaring a variable or create a script tag? I tried both in some way but nothing worked so far. I need it only in one component.
At the end I wanna use the following code in the component:
var markerCluster = new MarkerClusterer(this.map, this.markerMap,
{imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});

No need to copy node_modules/#google/markerclustererplus/dist/markerclustererplus.min.js to assets/js/markerclustererplus.min.js.
In your component's tsx file just import MarkerCluster
import MarkerClusterer from "#google/markerclustererplus";
You'll need to have the google maps javascript library already loaded. As far as I'm aware you'll have to load it via a script tag but this can be done dynamically.
I'm using // #ts-ignore in my examples but you can install the Google Maps types if you prefer.
The final component should look something like the following:
import { h, Component, Host, Element, Listen } from "#stencil/core";
import MarkerClusterer from "#google/markerclustererplus";
#Component({
tag: "my-component",
styles: `
:host {
position: absolute;
width: 100%;
height: 100%;
}
.map {
height: 100%;
}
`,
shadow: true,
})
export class MyComponent {
#Element() el: HTMLElement;
private googleMapsApiKey = "YOUR_API_KEY_HERE";
private locations = [
{ lat: -31.56391, lng: 147.154312 },
{ lat: -33.718234, lng: 150.363181 },
{ lat: -33.727111, lng: 150.371124 },
{ lat: -33.848588, lng: 151.209834 },
{ lat: -33.851702, lng: 151.216968 },
{ lat: -34.671264, lng: 150.863657 },
{ lat: -35.304724, lng: 148.662905 },
{ lat: -36.817685, lng: 175.699196 },
{ lat: -36.828611, lng: 175.790222 },
{ lat: -37.75, lng: 145.116667 },
{ lat: -37.759859, lng: 145.128708 },
{ lat: -37.765015, lng: 145.133858 },
{ lat: -37.770104, lng: 145.143299 },
{ lat: -37.7737, lng: 145.145187 },
{ lat: -37.774785, lng: 145.137978 },
{ lat: -37.819616, lng: 144.968119 },
{ lat: -38.330766, lng: 144.695692 },
{ lat: -39.927193, lng: 175.053218 },
{ lat: -41.330162, lng: 174.865694 },
{ lat: -42.734358, lng: 147.439506 },
{ lat: -42.734358, lng: 147.501315 },
{ lat: -42.735258, lng: 147.438 },
{ lat: -43.999792, lng: 170.463352 },
];
private _mapEl: HTMLElement;
componentDidLoad() {
if (document.getElementById("maps-script")) {
this.initMap();
return;
}
// Create the script tag, set the appropriate attributes
var script = document.createElement("script");
script.id = "maps-script";
script.src = `https://maps.googleapis.com/maps/api/js?key=${this.googleMapsApiKey}&callback=initMap`;
script.defer = true;
// Attach your callback function to the `window` object
// #ts-ignore
window.initMap = () => this.initMap();
// Append the 'script' element to 'head'
document.head.appendChild(script);
}
initMap() {
// #ts-ignore
const map = new google.maps.Map(this._mapEl, {
zoom: 3,
center: { lat: -28.024, lng: 140.887 },
});
// Create an array of alphabetical characters used to label the markers.
const labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
const markers = this.locations.map((location, i) => {
// #ts-ignore
return new google.maps.Marker({
position: location,
label: labels[i % labels.length],
});
});
// Add a marker clusterer to manage the markers.
const markerCluster = new MarkerClusterer(map, markers, {
imagePath:
"https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m",
});
}
render() {
return (
<Host>
<div class="map" ref={(el) => (this._mapEl = el)}></div>
</Host>
);
}
}
Here is a Working example on webcomponents.dev

Related

need to get an external button to link to maps when clicked on

I need help linking buttons to cities. When clicked, opens a new map which then zooms in and I can have places of interest also. This is my file below and I am not the best at coding so help appreciated please.
I haven't included the HTML file as its so basic and was more what I needed to add here.
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
zoom: 3,
center: {
lat: 50.7436337,
lng: 18.4208039
}
});
to loop around
Need help to link buttons to cities that when clicked upon opens up to a map of that city
var labels = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
My places are outlined below of the cities I want in my buttons:
function addMarker(feature) {
var marker = new google.maps.Marker({
position: feature.position,
map: map,
icon: icons[feature.type].icon,
});
}
The map of the world:
var map;
var InforObj = [];
var centerCords = {
lat: 50.7436337,
lng: 18.4208039
};
var markersOnMap = [{
placeName: "Amsterdam (Johan Cryuff Arena)",
LatLng: [{
lat: 52.314371,
lng: 4.941964
}],
},
{ placeName: "Baku (Olympic Stadium)",
LatLng: [{
lat: 40.4300,
lng: 49.9196
}]
},
{ placeName: "Bilbao (San Mames)",
LatLng: [{
lat: 43.2641,
lng: -2.9494
}]
},
{ placeName: "Bucharest (Arena Nationala)",
LatLng: [{
lat: 44.437139,
lng: 26.152579
}]
},
{ placeName: "Budapest (Puskas Arena)",
LatLng: [{
lat: 47.503172,
lng: 19.097022
}]
},
{ placeName: "Copenhagen (Parken Stadium)",
LatLng: [{
lat: 55.702701,
lng: 12.572433
}]
},
{ placeName: "Dublin (Aviva Stadium)",
LatLng: [{
lat: 53.335232,
lng: -6.228457
}]
},
{ placeName: "Glasgow (Hampden Park)",
LatLng: [{
lat: 55.825842,
lng: -4.252048
}]
},
{ placeName: "London (Wembley Stadium)",
LatLng: [{
lat: 51.556021,
lng: -0.279519
}]
},
{ placeName: "Munich (Allianz Arena)",
LatLng: [{
lat: 48.2188,
lng: 11.624707
}]
},
{ placeName: "Rome (Stadio Olimpico)",
LatLng: [{
lat: 41.934077,
lng: 12.454725
}]
},
{ placeName: "Saint Petersburg (Krestovsky Stadium)",
LatLng: [{
lat: 59.972728,
lng: 30.221405
}]
},
];
List of the cities above:
window.onload = function () {
initMap();
};
function addMarkerInfo() {
for (var i = 0; i < markersOnMap.length; i++) {
var contentString = '<div id="content"><h1>' + markersOnMap[i].placeName +
'</h1><p>Lorem ipsum dolor sit amet, vix mutat posse suscipit id, vel ea tantas omittam detraxit.</p></div>';
const marker = new google.maps.Marker({
position: markersOnMap[i].LatLng[0],
map: map,
});
const infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 200
});
marker.addListener('click', function () {
closeOtherInfo();
infowindow.open(marker.get('map'), marker);
InforObj[0] = infowindow;
});
}
}
All part of the same code and I am not sure how its done properly
function closeOtherInfo() {
if (InforObj.length > 0) {
// detach the info-window from the marker ... undocumented in the API docs
InforObj[0].set("marker", null);
// and close it
InforObj[0].close();
// blank the array
InforObj.length = 0;
}
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: centerCords
});
addMarkerInfo();
}
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(48.1293954, 12.556663), //Setting Initial Position
zoom: 10
});
}
my file path
var markerCluster = new MarkerClusterer(map, markers, {
imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
}
This is my javascript code

How to save a google maps edited polygon path in Vue

I have a Vue component BaseMap that contains a marker component Location.
The Location component has a Polygon marker that can be edtited.
// BaseMap
<GmapMap>
<Location :location="location" />
</GmapMap>
// Location
<gmap-marker>
<gmap-polygon
ref="polyMarker"
:editable="true"
:path="location.path"
#mouseup="updatePath('polyMarker')"
/>
</gmap-marker>
<script>
methods: {
updatePath(ref_name){
console.log(this.$refs[ref_name].path) // same array as origin
}
}
</script>
How do I access the new edited points of the polygon? If I use this.$ref.polyMarker.path I keep getting the original array of points not the new ones.
EDIT
After discussion with MrUpsidown I went ahead and coded the minimum app in codesandbox. The same problem exist.
Dependancies:
- vue
- vue2-gmap-cuspom-marker
//////////////////////////////////////////////////////////////
// main.js
import Vue from "vue";
import App from "./App.vue";
import * as VueGoogleMaps from "vue2-google-maps";
Vue.config.productionTip = false;
Vue.use(VueGoogleMaps, {
load: {
// libraries: "places", // This is required if you use the Autocomplete plugin
key: "[USE YOUR OWN KEY]"
}
// autobindAllEvents: false,
// installComponents: true
});
new Vue({
render: h => h(App)
}).$mount("#app");
//////////////////////////////////////////
//App.vue
<template>
<div id="app">
<HelloWorld />
</div>
</template>
<script>
import HelloWorld from "./components/HelloWorld";
export default {
name: "App",
components: {
HelloWorld
}
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
</style>
//////////////////////////////////////////////////////
// HelloWorld.vue
<template>
<div>
<baseMap/>
</div>
</template>
<script>
import baseMap from "#/components/baseMap";
export default {
name: "HelloWorld",
components: { baseMap },
props: {
msg: String
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
</style>
////////////////////////////////////////////////////
//baseMap.vue
<template>
<div>
<GmapMap :style="'height:500px'" :center="center" :zoom="zoom">
<Location :location="location"/>
</GmapMap>
</div>
</template>
<script>
import Location from "#/components/Location";
export default {
name: "baseMap",
components: { Location },
data: function() {
return {
center: { lat: -33.9249, lng: 18.4241 },
zoom: 12,
location: {
path: [
{ lat: -33.91170210440241, lng: 18.422548745513268 },
{ lat: -33.90993912517883, lng: 18.422806237578698 },
{ lat: -33.90874597713464, lng: 18.42422244393856 },
{ lat: -33.90482806012767, lng: 18.42952248895199 },
{ lat: -33.90073186345211, lng: 18.42428681695492 },
{ lat: -33.90128397100101, lng: 18.420596097350426 },
{ lat: -33.90256627151344, lng: 18.417656396270104 },
{ lat: -33.90367045927834, lng: 18.416454766631432 },
{ lat: -33.90532671411109, lng: 18.417913888335534 },
{ lat: -33.908389810302396, lng: 18.413579438567467 },
{ lat: -33.91084733115123, lng: 18.41703412377865 },
{ lat: -33.91170210440241, lng: 18.422548745513268 }
]
}
};
},
props: {
msg: String
}
};
</script>
<style>
</style>
/////////////////////////////////////////////////////////
// Location.vue
<template>
<div>
<gmap-marker>
<gmap-polygon
ref="polyMarker"
:editable="true"
:path="location.path"
#mouseup="updatePath('polyMarker')"
/>
</gmap-marker>
</div>
</template>
<script>
import GmapCustomMarker from "vue2-gmap-custom-marker";
export default {
name: "Location",
components: {
GmapCustomMarker
},
props: {
location: {
type: Object,
default() {
return {};
}
}
},
methods: {
updatePath(name) {
console.log(this.$refs[name].path);
}
}
};
</script>
<style>
</style>
First replace :path with :paths:
:paths="location.path"
Then replace the #mouseup event with #paths_changed using $event as parameter:
#paths_changed="updatePath($event)"
Finally log your path; you'll see how it's getting updated now.
updatePath(mvcArray) {
for (let i = 0; i < mvcArray.getLength(); i++) {
for (let j = 0; j < mvcArray.getAt(i).getLength(); j++) {
console.log(mvcArray.getAt(i).getAt(j).lat() + "," + mvcArray.getAt(i).getAt(j).lng());
}
}
console.log("-------")
}
For further guidance I recommend you check out the library's examples such as this one.
Hope this helps you!

add multiple gmap marker

i have a vue2-google-map apps that display map.
before this i using this code
<GmapMarker
ref="myMarker"
:position="google && new google.maps.LatLng(1.38, 103.8)"
/>
<GmapMarker
ref="myMarker"
:position="google && new google.maps.LatLng(3.1488976, 101.6126774)"
/>
to display multiple marker, but if the latlng data is too many, it will be many need to be create.
my idea is to take data from
const latlng = [
{
lat: value,
lng: value,
},
{
lat: value,
lng: value,
},
and apply {{latlng}} into <GmapMarker :position="google && new google.maps.LatLn({{latlng.lng}},{{latlng.lat}})">
but i have problem to apply that {{latlng}} into the marker.
can someone explain how to apply them?
For generating multiple markers your need to push latitude and longitude in the marker collection and then iterate the marker.i have updated code as per the requirement.
<template>
<div>
<GmapMap
ref="gmap"
:center="getCenter()"
:zoom="11"
style="height: 500px;margin: 0px -8px;"
class="no-padding"
:options="getOptions()"
>
<GmapMarker
:key="index"
v-for="(m, index) in getMarkers()"
:position="m.position"
:clickable="true"
:draggable="false"
:title="m.title"
:icon="m.icon"
#click="clicked()"
/>
</GmapMap>
</div>
</template>
<script>
import MarkerClusterer from "marker-clusterer-plus";
export default {
name: "SiteMap",
props: [],
methods: {
getOptions() {
return {
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
rotateControl: false,
fullscreenControl: false,
disableDefaultUi: false
};
},
clicked() {
// after click
},
getCenter() {
return {
lat: 37.12523,
lng: -122.1252
};
},
getMarkers() {
// generating markers for site map
var markers = [];
// remove this after lat long received from api.
const tempLatLong = [
{ lat: 37.9068361, lng: -122.116971 },
{ lat: 37.9168362, lng: -122.076972 },
{ lat: 37.9268363, lng: -122.136973 },
{ lat: 37.9368364, lng: -122.146974 },
{ lat: 37.9468365, lng: -122.106975 },
{ lat: 37.9568366, lng: -122.166976 },
{ lat: 37.9668367, lng: -122.176977 },
{ lat: 37.9768368, lng: -122.016978 },
{ lat: 37.9868369, lng: -122.196979 }
];
for(let i=0;i<tempLatLong.length;i++){
markers.push({
position: tempLatLong[i],
title: 'test title',
icon: this.getSiteIcon(1) // if you want to show different as per the condition.
});
}
return markers;
},
getSiteIcon(status) {
try {
switch (status) {
case 1:
return require("#/assets/images/icons/map-marker-online.svg");
break;
case 2:
return require("#/assets/images/icons/map-marker-critical.svg");
break;
case 3:
return require("#/assets/images/icons/map-marker-offline.svg");
break;
case 4:
return require("#/assets/images/icons/map-marker-lifesafety.svg");
break;
default:
return require("#/assets/images/icons/map-marker-online.svg");
}
} catch (e) {
return null;
}
},
},
components: {},
created() {},
mounted() {
}
};
</script>
<style scoped></style>

How to correctly add a square grid inside a polygon using turfjs?

So i'm currently playing around with turfjs. And i'm trying to add a squaregrid inside a polygon.
So here's the code
var triangleCoords = [
{ lat: 25.774, lng: -80.19 },
{ lat: 18.466, lng: -66.118 },
{ lat: 32.321, lng: -64.757 },
{ lat: 25.774, lng: -80.19 }
];
// Construct the polygon.
var bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
const geoJSON = {
type: 'Polygon',
coordinates: []
};
// convert to bermudaTriangle path to geojson
for (let point of bermudaTriangle.getPath().getArray()) {
geoJSON.coordinates.push([point.lat(), point.lng()]);
}
const feature = turf.feature(geoJSON);
const bbox = turf.bbox(feature);
// ERROR: this one's showing Infinity values
console.table(bbox);
const grid = turf.squareGrid(bbox, 50, {
units: "miles",
mask: feature
});
map.data.addGeoJson(grid);
and looking at the console, it shows Infinity values for bbox as commented on the code.
I've added a link for the code
https://codepen.io/chan-dev/pen/yrdRoM
geoJSON is not a valid GeoJSON object for Polygon in the provided example, that's the reason why turf.bbox returns invalid result. GeoJSON for polygon could be constructed via turf.polygon like this:
var triangleCoords = [
{ lat: 25.774, lng: -80.19 },
{ lat: 18.466, lng: -66.118 },
{ lat: 32.321, lng: -64.757 },
{ lat: 25.774, lng: -80.19 }
];
var data = triangleCoords.map(coord => {
return [coord.lng, coord.lat];
});
var geojson = turf.polygon([data]);
and bounding box calculated like this:
const bbox = turf.bbox(geojson);
Modified CodePen

google maps roads api looping - how to stop

I've implemented the code seen at:
https://developers.google.com/maps/documentation/roads/inspector.
In each of the examples on this page, the marker animation loops.
How are you supposed to stop the looping so that the icon remains at the end point until more coordinates are fed to it, at which point I'll animate from the last gps coord to the newest gps coord which I just received?
I just don't want to see the course traveled over and over again.
To stop the animation, cancel the setInterval when the icon reaches the end of the polyline.
function animateCircle(polyline) {
var count = 0;
// fallback icon if the poly has no icon to animate
var defaultIcon = [
{
icon: lineSymbol,
offset: '100%'
}
];
handle = window.setInterval(function() {
if ((count+1) == 200)
window.clearInterval(handle);
count = (count + 1) % 200;
var icons = polyline.get('icons') || defaultIcon;
icons[0].offset = (count / 2) + '%';
polyline.set('icons', icons);
}, 20);
}
proof of concept fiddle
code snippet:
/**
* Animate an icon along a polyline
* #param {Object} polyline The line to animate the icon along
*/
function animateCircle(polyline) {
var count = 0;
// fallback icon if the poly has no icon to animate
var defaultIcon = [{
icon: lineSymbol,
offset: '100%'
}];
handle = window.setInterval(function() {
// when reaches end of polyline
if ((count + 1) == 200) {
// cancel the interval timer
window.clearInterval(handle);
// hide the circle
var icons = polyline.get('icons') || defaultIcon;
icons[0].icon.strokeOpacity = 0;
polyline.set('icons', icons);
}
count = (count + 1) % 200;
var icons = polyline.get('icons') || defaultIcon;
icons[0].offset = (count / 2) + '%';
polyline.set('icons', icons);
}, 20);
}
// Icons for markers
var RED_MARKER = 'https://maps.google.com/mapfiles/ms/icons/red-dot.png';
var GREEN_MARKER = 'https://maps.google.com/mapfiles/ms/icons/green-dot.png';
var BLUE_MARKER = 'https://maps.google.com/mapfiles/ms/icons/blue-dot.png';
var YELLOW_MARKER = 'https://maps.google.com/mapfiles/ms/icons/yellow-dot.png';
// URL for places requests
var PLACES_URL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=';
// URL for Speed limits
var SPEED_LIMIT_URL = 'https://roads.googleapis.com/v1/speedLimits';
var coords;
/**
* Current Roads API threshold (subject to change without notice)
* #const {number}
*/
var DISTANCE_THRESHOLD_HIGH = 300;
var DISTANCE_THRESHOLD_LOW = 200;
/**
* #type Array<ExtendedLatLng>
*/
var originals = []; // the original input points, a list of ExtendedLatLng
var interpolate = true;
var map;
var placesService;
var originalCoordsLength;
// Settingup Arrays
var infoWindows = [];
var markers = [];
var placeIds = [];
var polylines = [];
var snappedCoordinates = [];
var distPolylines = [];
// Symbol that gets animated along the polyline
var lineSymbol = {
path: google.maps.SymbolPath.CIRCLE,
scale: 8,
strokeColor: '#005db5',
strokeWidth: '#005db5'
};
// Initialize
function initialize() {
// Centre the map on Sydney
var mapOptions = {
center: {
'lat': -33.870315,
'lng': 151.196532
},
zoom: 16
};
// Map object
map = new google.maps.Map(document.getElementById('map'), mapOptions);
// Places object
placesService = new google.maps.places.PlacesService(map);
drawSnappedPolyline();
// Draw the polyline for the snapToRoads API response
// Call functions to add markers and infowindows for each snapped
// point along the polyline.
function drawSnappedPolyline(snappedCoords) {
var snappedCoords = [{
lat: -33.87031296432842,
lng: 151.19649532278828,
originalIndex: 0,
interpolated: false
},
{
lat: -33.8702971,
lng: 151.1964966,
interpolated: true
},
{
lat: -33.8702971,
lng: 151.1964966,
interpolated: true
},
{
lat: -33.8700888,
lng: 151.19690029999998,
interpolated: true
},
{
lat: -33.8700888,
lng: 151.19690029999998,
interpolated: true
},
{
lat: -33.869997,
lng: 151.197091,
interpolated: true
},
{
lat: -33.8699822,
lng: 151.1971317,
interpolated: true
},
{
lat: -33.8699669,
lng: 151.1971912,
interpolated: true
},
{
lat: -33.8699669,
lng: 151.1971912,
interpolated: true
},
{
lat: -33.869954,
lng: 151.1972377,
interpolated: true
},
{
lat: -33.8699449,
lng: 151.1972855,
interpolated: true
},
{
lat: -33.86994270100937,
lng: 151.197353292079,
originalIndex: 1,
interpolated: false
},
{
lat: -33.8699414,
lng: 151.19739339999998,
interpolated: true
},
{
lat: -33.8699441,
lng: 151.1974702,
interpolated: true
},
{
lat: -33.8699507,
lng: 151.19755139999998,
interpolated: true
},
{
lat: -33.8699602,
lng: 151.1976302,
interpolated: true
},
{
lat: -33.86997848255702,
lng: 151.19772949764274,
originalIndex: 2,
interpolated: false
},
{
lat: -33.869981300000006,
lng: 151.19774479999998,
interpolated: true
},
{
lat: -33.8700129,
lng: 151.1978469,
interpolated: true
},
{
lat: -33.8700129,
lng: 151.1978469,
interpolated: true
},
{
lat: -33.8700458,
lng: 151.1979242,
interpolated: true
},
{
lat: -33.8700834,
lng: 151.1979993,
interpolated: true
},
{
lat: -33.8701059,
lng: 151.1980374,
interpolated: true
},
{
lat: -33.870184300000005,
lng: 151.1981381,
interpolated: true
},
{
lat: -33.8702143,
lng: 151.1981743,
interpolated: true
},
{
lat: -33.8702143,
lng: 151.1981743,
interpolated: true
},
{
lat: -33.8702902,
lng: 151.19825269999998,
interpolated: true
},
{
lat: -33.87031617902999,
lng: 151.19827540632983,
originalIndex: 3,
interpolated: false
},
{
lat: -33.8703672,
lng: 151.19832,
interpolated: true
},
{
lat: -33.870480199999996,
lng: 151.19839969999998,
interpolated: true
},
{
lat: -33.870480199999996,
lng: 151.19839969999998,
interpolated: true
},
{
lat: -33.8705388,
lng: 151.1984269,
interpolated: true
},
{
lat: -33.87057888561142,
lng: 151.19844125817298,
originalIndex: 4,
interpolated: false
},
{
lat: -33.870625219935086,
lng: 151.19845785457534,
originalIndex: 5,
interpolated: false
},
{
lat: -33.8706823,
lng: 151.1984783,
interpolated: true
},
{
lat: -33.8706823,
lng: 151.1984783,
interpolated: true
},
{
lat: -33.870718800000006,
lng: 151.1984865,
interpolated: true
},
{
lat: -33.8708181,
lng: 151.19850399999999,
interpolated: true
},
{
lat: -33.8708644,
lng: 151.1985081,
interpolated: true
},
{
lat: -33.870908899999996,
lng: 151.1985078,
interpolated: true
},
{
lat: -33.87095031058638,
lng: 151.19850565885983,
originalIndex: 7,
interpolated: false
},
{
lat: -33.8709998,
lng: 151.19850309999998,
interpolated: true
},
{
lat: -33.87103822739919,
lng: 151.1984996185936,
originalIndex: 8,
interpolated: false
},
{
lat: -33.8713497,
lng: 151.1984714,
interpolated: true
},
{
lat: -33.8713497,
lng: 151.1984714,
interpolated: true
},
{
lat: -33.8718054,
lng: 151.1984326,
interpolated: true
},
{
lat: -33.8719381,
lng: 151.1984352,
interpolated: true
},
{
lat: -33.87203169684805,
lng: 151.198429447748,
originalIndex: 9,
interpolated: false
}
];
var snappedPolyline = new google.maps.Polyline({
path: snappedCoords,
strokeColor: '#005db5',
strokeWeight: 6,
icons: [{
icon: lineSymbol,
offset: '100%'
}]
});
snappedPolyline.setMap(map);
animateCircle(snappedPolyline);
polylines.push(snappedPolyline);
var placeIds = [
"ChIJS6cYMjeuEmsRVxRklOwdF8o",
"ChIJS6cYMjeuEmsRVxRklOwdF8o",
"ChIJ-dDXMDeuEmsRSUxWOfxOpYA",
"ChIJ-dDXMDeuEmsRSUxWOfxOpYA",
"ChIJKVpuODeuEmsRjffu1J1v888",
"ChIJKVpuODeuEmsRjffu1J1v888",
"ChIJKVpuODeuEmsRjffu1J1v888",
"ChIJKVpuODeuEmsRjffu1J1v888",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJR6yfRDeuEmsRhllVwX6TMJ8",
"ChIJrV1uWzeuEmsR2N5RA6d2SEE",
"ChIJrV1uWzeuEmsR2N5RA6d2SEE",
"ChIJrV1uWzeuEmsR2N5RA6d2SEE",
"ChIJrV1uWzeuEmsR2N5RA6d2SEE",
"ChIJrV1uWzeuEmsR2N5RA6d2SEE",
"ChIJrV1uWzeuEmsR2N5RA6d2SEE",
"ChIJeUaSWTeuEmsRGB2FlgUyPzE",
"ChIJeUaSWTeuEmsRGB2FlgUyPzE",
"ChIJeUaSWTeuEmsRGB2FlgUyPzE",
"ChIJeUaSWTeuEmsRGB2FlgUyPzE",
"ChIJeUaSWTeuEmsRGB2FlgUyPzE",
"ChIJOU6hVzeuEmsRlJsTGD1vpqU",
"ChIJOU6hVzeuEmsRlJsTGD1vpqU",
"ChIJOU6hVzeuEmsRlJsTGD1vpqU",
"ChIJOU6hVzeuEmsRlJsTGD1vpqU",
"ChIJOU6hVzeuEmsRlJsTGD1vpqU",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJmRMQVTeuEmsRUH-faYDgJs0",
"ChIJ9SmzqTCuEmsRbkJlaklnr2s",
"ChIJ9SmzqTCuEmsRbkJlaklnr2s",
"ChIJ9SmzqTCuEmsRbkJlaklnr2s",
"ChIJ9SmzqTCuEmsRbkJlaklnr2s"
];
for (var i = 0; i < snappedCoords.length; i++) {
var marker = addMarker(snappedCoords[i]);
}
}
} // End init function
// Call the initialize function once everything has loaded
google.maps.event.addDomListener(window, 'load', initialize);
/**
* Add a marker to the map and check for special 'interpolated'
* and 'unsnapped' properties to control which colour marker is used
* #param {ExtendedLatLng} coords - Coords of where to add the marker
* #return {!Object} marker - the marker object created
*/
function addMarker(coords) {
var marker = new google.maps.Marker({
position: coords,
title: coords.lat + ',' + coords.lng,
map: map,
opacity: 0.5,
icon: RED_MARKER
});
// Coord should NEVER be interpolated AND unsnapped
if (coords.interpolated) {
marker.setIcon(BLUE_MARKER);
} else if (!coords.related) {
marker.setIcon(YELLOW_MARKER);
} else if (coords.originalIndex != undefined) {
marker.setIcon(RED_MARKER);
addCorrespondence(coords, marker);
} else {
marker.setIcon({
url: GREEN_MARKER,
scaledSize: {
width: 20,
height: 20
}
});
addCorrespondence(coords, marker);
}
// Make markers change opacity when the mouse scrubs across them
marker.addListener('mouseover', function(mevt) {
marker.setOpacity(1.0);
});
marker.addListener('mouseout', function(mevt) {
marker.setOpacity(0.5);
});
coords.marker = marker; // Save a reference for easy access later
markers.push(marker);
return marker;
}
/**
* Fit the map bounds to the current set of markers
* #param {Array<Object>} markers Array of all map markers
*/
function fitBounds(markers) {
var bounds = new google.maps.LatLngBounds;
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].getPosition());
}
map.fitBounds(bounds);
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
font-family: Roboto, Noto, sans-serif;
}
#map {
height: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places,geometry">
</script>
<div id="map">
</div>