Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
addMarker({ simplifiedMarker, map, options }: AddMarker ): void {
if (options.icon === 'default') {
options.icon = null;
}
// oluşturulacak markerin özelliklerini belirler.
const marker = new google.maps.Marker({
position: {
lat: simplifiedMarker.lat,
lng: simplifiedMarker.lng
},
label: {
text: this.labels[this.labelIndex++ % this.labels.length],
fontSize: '16px',
fontWeight: 'bold'
},
map: map,
icon: options.icon,
draggable: true
});
if (options.existing) {
marker.set('id', simplifiedMarker.id);
marker.set('lat', simplifiedMarker.lat);
marker.set('lng', simplifiedMarker.lng);
marker.set('title', simplifiedMarker.title);
marker.set('description', simplifiedMarker.description);
marker.set('sourceId', simplifiedMarker.sourceId);
marker.set('image', simplifiedMarker.image);
marker.set('createdAt', simplifiedMarker.createdAt);
marker.set('updatedAt', simplifiedMarker.updatedAt);
marker.set('source', simplifiedMarker.source);
marker.set('existing', options.existing)
} else {
marker.set('id', uuid.v4());
marker.set('lat', 'new');
marker.set('lng', 'new');
marker.set('title', 'new');
marker.set('description', 'new');
marker.set('sourceId', 'new');
marker.set('image', 'new');
marker.set('createdAt', 'new');
marker.set('updatedAt', 'new');
marker.set('source', { title: 'new' });
marker.set('existing', options.existing)
}
this.markers.push(marker);
this.mapMarkers();
// marker dblclick event
google.maps.event.addListener(marker, 'dblclick', () => {
this.removeMarker(marker);
});
// marker dragend event
marker.addListener('dragend', () => {
this.markers.forEach((element, index) => {
if (element.id === marker.id) {
this.markers[index] = marker; // dragend edilen markeri array içinde günceller.
}
});
this.mapMarkers();
});
const content = `<div class="content">
<b>${marker.title}</b><br>
${marker.description}<br>
${marker.source.title}<br>
</div>`;
const infowindow = new google.maps.InfoWindow({
content: content
});
// marker click event
marker.addListener('click', () => {
infowindow.open(map, marker);
});
}
@umutyerebakmaz

This comment has been minimized.

Copy link
Owner Author

@umutyerebakmaz umutyerebakmaz commented Aug 21, 2020

warning: Property 'id' does not exist on type 'Marker'.ts(2339)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment