All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.GoogleMapsMarker.js Maven / Gradle / Ivy

The newest version!
/**
 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

import {MarkerBase} from '@liferay/map-common';

/**
 * GoogleMapsMarker
 * @review
 */
class GoogleMapsMarker extends MarkerBase {

	/**
	 * If a marked has been created, sets the marker location to the given one
	 * @param {Object} location Location to set the native marker in
	 * @review
	 */
	setPosition(location) {
		if (this._nativeMarker) {
			this._nativeMarker.setPosition(location);
		}
	}

	/**
	 * @inheritDoc
	 * @review
	 */
	_getNativeMarker(location, map) {
		if (!this._nativeMarker) {
			this._nativeMarker = new google.maps.Marker({
				draggable: true,
				map,
				position: location,
			});

			google.maps.event.addListener(
				this._nativeMarker,
				'click',
				this._getNativeEventFunction('click')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'dblclick',
				this._getNativeEventFunction('dblclick')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'drag',
				this._getNativeEventFunction('drag')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'dragend',
				this._getNativeEventFunction('dragend')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'dragstart',
				this._getNativeEventFunction('dragstart')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'mousedown',
				this._getNativeEventFunction('mousedown')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'mouseout',
				this._getNativeEventFunction('mouseout')
			);

			google.maps.event.addListener(
				this._nativeMarker,
				'mouseover',
				this._getNativeEventFunction('mouseover')
			);
		}

		return this._nativeMarker;
	}

	/**
	 * @inheritDoc
	 * @review
	 */
	_getNormalizedEventData(nativeEvent) {
		return {
			location: {
				lat: nativeEvent.latLng.lat(),
				lng: nativeEvent.latLng.lng(),
			},
		};
	}
}

export default GoogleMapsMarker;
export {GoogleMapsMarker};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy