@h21-map/google-drawing-manager
Advanced tools
Comparing version 2.0.5 to 2.0.6
872
index.js
@@ -5,2 +5,3 @@ | ||
let DRAWING_MODE_AREA = "area"; | ||
let DRAWING_MODE_FITBOUNDS = "fitbounds"; | ||
@@ -21,3 +22,2 @@ function DrawingManager(map, opts) { | ||
me._drawingType = null; | ||
me._fitBounds = opts._fitBounds || true; | ||
me.markerOptions = opts.markerOptions || {}; | ||
@@ -29,12 +29,10 @@ me.circleOptions = opts.circleOptions || {}; | ||
google.maps.event.addListener(me.map, 'idle', () => { | ||
google.maps.event.trigger(me, 'draw:zoom_map', me.map.getZoom()); | ||
}) | ||
} | ||
}; | ||
DrawingManager.prototype.onAdd = function () { | ||
let me = this; | ||
google.maps.event.addListener(me.map, 'click', function (event) { | ||
@@ -46,7 +44,4 @@ google.maps.event.trigger(me, 'click', event); | ||
DrawingManager.prototype.setDrawingMode = function (drawingType, opts) { | ||
let me = this; | ||
me.markerOptions = opts.markerOptions || {}; | ||
@@ -70,6 +65,4 @@ me.circleOptions = opts.circleOptions || {}; | ||
if (me._drawingType != drawingType) { | ||
switch (drawingType) { | ||
case DRAWING_MODE_MARKER: | ||
@@ -84,2 +77,5 @@ me._bindMarker(); | ||
break; | ||
case DRAWING_MODE_FITBOUNDS: | ||
me._fitBounds(); | ||
break; | ||
default: | ||
@@ -89,74 +85,143 @@ me._reset(); | ||
} | ||
if (drawingType == DRAWING_MODE_FITBOUNDS) { return false } | ||
me._drawingType = drawingType; | ||
} | ||
} | ||
}, | ||
DrawingManager.prototype._setPosition = function (e) { | ||
DrawingManager.prototype._fitBounds = function () { | ||
let me = this; | ||
if (me._centerMarker) { | ||
me._fitBoundsMarker(); | ||
} | ||
if (me._area) { | ||
me._fitBoundsArea(); | ||
} | ||
if (me._circle) { | ||
me._fitBoundsCircle(); | ||
} | ||
}, | ||
let me = this; | ||
me.position = null; | ||
DrawingManager.prototype._fitBoundsMarker = function () { | ||
let me = this; | ||
if (me._centerMarker) { | ||
me.map.setCenter(me._centerMarker.getPosition()); | ||
if (me.map.getZoom() < 9) { | ||
me.map.setZoom(9); | ||
} | ||
} | ||
}, | ||
if (e) { | ||
me.position = e.latLng; | ||
} | ||
} | ||
DrawingManager.prototype._fitBoundsArea = function (coordinates) { | ||
let me = this; | ||
let bounds = new google.maps.LatLngBounds(); | ||
for (var n = 0; n < coordinates.length; n++) { | ||
bounds.extend(coordinates[n]); | ||
} | ||
me.map.panToBounds(bounds); | ||
me.map.fitBounds(bounds); | ||
}, | ||
DrawingManager.prototype.setPosition = function (lat, lng) { | ||
DrawingManager.prototype._fitBoundsCircle = function () { | ||
let me = this; | ||
if (me._circle) { | ||
me.map.fitBounds(me._circle.getBounds()); | ||
} | ||
}, | ||
let me = this; | ||
me.position = null; | ||
me.position = new google.maps.LatLng(lat, lng); | ||
DrawingManager.prototype._setPosition = function (e) { | ||
let me = this; | ||
me.position = null; | ||
} | ||
if (e) { | ||
me.position = e.latLng; | ||
} | ||
}, | ||
DrawingManager.prototype._reset = function () { | ||
DrawingManager.prototype.setPosition = function (lat, lng) { | ||
let me = this; | ||
me.position = null; | ||
me.position = new google.maps.LatLng(lat, lng); | ||
let me = this; | ||
}, | ||
me._removeArea(); | ||
me._removeCenterMarker(); | ||
me._removeCircle(); | ||
} | ||
DrawingManager.prototype._reset = function () { | ||
let me = this; | ||
me._removeArea(); | ||
me._removeCenterMarker(); | ||
me._removeCircle(); | ||
}, | ||
DrawingManager.prototype._bindArea = function () { | ||
DrawingManager.prototype._bindArea = function () { | ||
let me = this; | ||
google.maps.event.clearListeners(me, 'click'); | ||
me._removeArea(); | ||
me._removeCenterMarker(); | ||
me._removeCircle(); | ||
let me = this; | ||
var createArea = () => { | ||
me._setDrawing(false); | ||
google.maps.event.clearListeners(me, 'click'); | ||
const polygonOptions = { | ||
map: me.map, | ||
strokeColor: me.areaOptions.strokeColor, | ||
strokeOpacity: me.areaOptions.strokeOpacity, | ||
fillColor: me.areaOptions.fillColor, | ||
fillOpacity: me.areaOptions.fillOpacity, | ||
strokeWeight: me.areaOptions.strokeWeight, | ||
clickable: false, | ||
editable: false | ||
} | ||
me._removeArea(); | ||
me._removeCenterMarker(); | ||
me._removeCircle(); | ||
me._area = new google.maps.Polyline(polygonOptions); | ||
var createArea = () => { | ||
var move = google.maps.event.addListener(me.map, 'mousemove', function (e) { | ||
if (typeof e.latLng !== "undefined") { | ||
me._area.getPath().push(e.latLng); | ||
} | ||
}); | ||
me._setDrawing(false); | ||
var moveUp = google.maps.event.addListenerOnce(me.map, 'mouseup', () => { | ||
google.maps.event.removeListener(move); | ||
google.maps.event.removeListener(moveUp); | ||
const polygonOptions = { | ||
map: me.map, | ||
strokeColor: me.areaOptions.strokeColor, | ||
strokeOpacity: me.areaOptions.strokeOpacity, | ||
fillColor: me.areaOptions.fillColor, | ||
fillOpacity: me.areaOptions.fillOpacity, | ||
strokeWeight: me.areaOptions.strokeWeight, | ||
clickable: false, | ||
editable: false | ||
} | ||
var path = me._area.getPath(); | ||
me._area.setMap(null); | ||
const opts = { | ||
map: me.map, | ||
strokeColor: me.areaOptions.strokeColor, | ||
strokeOpacity: me.areaOptions.strokeOpacity, | ||
fillColor: me.areaOptions.fillColor, | ||
fillOpacity: me.areaOptions.fillOpacity, | ||
strokeWeight: me.areaOptions.strokeWeight, | ||
clickable: false, | ||
path: path, | ||
editable: false | ||
} | ||
me.area = new google.maps.Polyline(polygonOptions); | ||
google.maps.event.trigger(me, 'draw:area_create', me._convertCoordinates(me._area.getPath().getArray())); | ||
me._area = new google.maps.Polygon(opts); | ||
google.maps.event.clearListeners(me.map.getDiv(), 'mousedown'); | ||
me._setDrawing(true); | ||
if (me.areaOptions.fitBounds) { | ||
me._fitBoundsArea(); | ||
} | ||
}); | ||
} | ||
var move = google.maps.event.addListener(me.map, 'mousemove', function (e) { | ||
me.area.getPath().push(e.latLng); | ||
}); | ||
if (this._enableDraw) { | ||
google.maps.event.addDomListener(me.map.getDiv(), 'mousedown', (e) => { | ||
createArea(); | ||
}); | ||
} | ||
else { | ||
me._redrawArea() | ||
} | ||
}, | ||
var moveUp = google.maps.event.addListenerOnce(me.map, 'mouseup', () => { | ||
DrawingManager.prototype._redrawArea = function () { | ||
let me = this; | ||
if (me.areaCoordinates) { | ||
let latlngs = me._convertlatlngs(); | ||
google.maps.event.removeListener(move); | ||
google.maps.event.removeListener(moveUp); | ||
var path = me.area.getPath(); | ||
me.area.setMap(null); | ||
const opts = { | ||
@@ -170,406 +235,326 @@ map: me.map, | ||
clickable: false, | ||
path: path, | ||
path: latlngs, | ||
editable: false | ||
} | ||
me._area = new google.maps.Polygon(opts); | ||
google.maps.event.trigger(me, 'draw:area_create', me._convertCoordinates(me.area.getPath().getArray())); | ||
google.maps.event.trigger(me, 'draw:area_create', me._convertCoordinates(me._area.getPath().getArray())); | ||
me._fitBoundsArea(); | ||
} | ||
}, | ||
me.area = new google.maps.Polygon(opts); | ||
DrawingManager.prototype._convertlatlngs = function () { | ||
let me = this; | ||
let latlngs = []; | ||
google.maps.event.clearListeners(me.map.getDiv(), 'mousedown'); | ||
if (me.areaCoordinates.length > 0) { | ||
for (var n = 0; n < me.areaCoordinates.length; n++) { | ||
let item = me.areaCoordinates[n]; | ||
latlngs.push(new google.maps.LatLng(item.latitude, item.longitude)); | ||
} | ||
return latlngs; | ||
} | ||
}, | ||
me._setDrawing(true); | ||
me._fitBoundsArea(me.area.getPath().getArray()); | ||
DrawingManager.prototype._setDrawing = function (enabled) { | ||
let me = this; | ||
me.map.setOptions({ | ||
draggable: enabled, | ||
scrollwheel: enabled, | ||
disableDoubleClickZoom: enabled | ||
}); | ||
} | ||
}, | ||
DrawingManager.prototype._fitBoundsArea = function () { | ||
let me = this; | ||
if (me._area) { | ||
let patchLatLng = me._area.getPath().getArray() | ||
let bounds = new google.maps.LatLngBounds(); | ||
for (var n = 0; n < patchLatLng.length; n++) { | ||
bounds.extend(patchLatLng[n]); | ||
} | ||
me.map.panToBounds(bounds); | ||
me.map.fitBounds(bounds); | ||
} | ||
if (this._enableDraw) { | ||
google.maps.event.addDomListener(me.map.getDiv(), 'mousedown', (e) => { | ||
createArea(); | ||
}); | ||
} | ||
else { | ||
me._redrawArea() | ||
} | ||
} | ||
}, | ||
DrawingManager.prototype._redrawArea = function () { | ||
let me = this; | ||
if (me.areaCoordinates) { | ||
let latlngs = me._convertlatlngs(); | ||
const opts = { | ||
map: me.map, | ||
strokeColor: me.areaOptions.strokeColor, | ||
strokeOpacity: me.areaOptions.strokeOpacity, | ||
fillColor: me.areaOptions.fillColor, | ||
fillOpacity: me.areaOptions.fillOpacity, | ||
strokeWeight: me.areaOptions.strokeWeight, | ||
clickable: false, | ||
path: latlngs, | ||
editable: false | ||
DrawingManager.prototype._convertCoordinates = function (coordinates) { | ||
let positions = []; | ||
for (var n = 0; n < coordinates.length; n++) { | ||
let item = coordinates[n]; | ||
let position = { | ||
latitude: item.lat(), | ||
longitude: item.lng(), | ||
} | ||
positions.push(position); | ||
} | ||
return positions; | ||
}, | ||
me.area = new google.maps.Polygon(opts); | ||
google.maps.event.trigger(me, 'draw:area_create', me._convertCoordinates(me.area.getPath().getArray())); | ||
me._fitBoundsArea(me.area.getPath().getArray()); | ||
} | ||
DrawingManager.prototype._bindMarker = function () { | ||
let me = this; | ||
me._removeArea(); | ||
me._removeCenterMarker(); | ||
google.maps.event.clearListeners(me, 'click'); | ||
google.maps.event.clearListeners(me, 'mousedown'); | ||
google.maps.event.clearListeners(me, 'mouseup'); | ||
me._removeCircle(); | ||
} | ||
var createCenterMarker = (e) => { | ||
let isIconSelected = false; | ||
me._removeCenterMarker(); | ||
me._removeCircle(); | ||
DrawingManager.prototype._convertlatlngs = function () { | ||
if (e) { | ||
me._setPosition(e); | ||
} | ||
let me = this; | ||
let latlngs = []; | ||
if (me.position) { | ||
me._centerMarker = new google.maps.Marker({ | ||
draggable: false, | ||
zIndex: 1000002, | ||
position: me.position, | ||
icon: me.markerOptions.iconUrl, | ||
raiseOnDrag: false, | ||
optimized: true, | ||
}); | ||
if (me.areaCoordinates.length > 0) { | ||
for (var n = 0; n < me.areaCoordinates.length; n++) { | ||
let item = me.areaCoordinates[n]; | ||
latlngs.push(new google.maps.LatLng(item.latitude, item.longitude)); | ||
} | ||
return latlngs; | ||
} | ||
} | ||
me._centerMarker.setMap(me.map); | ||
if (me.markerOptions.fitBounds) { | ||
me._fitBoundsMarker(); | ||
} | ||
DrawingManager.prototype._setDrawing = function (enabled) { | ||
google.maps.event.trigger(me, 'draw:marker_create', me._getPosition()); | ||
let me = this; | ||
google.maps.event.addListener(me._centerMarker, 'click', () => { | ||
google.maps.event.trigger(me, 'draw:marker_click', me._getPosition()); | ||
if (!isIconSelected) { | ||
me._setIconMarker(me.markerOptions.iconUrlSelected); | ||
isIconSelected = true; | ||
} | ||
}); | ||
me.map.setOptions({ | ||
draggable: enabled, | ||
scrollwheel: enabled, | ||
disableDoubleClickZoom: enabled | ||
}); | ||
} | ||
me._centerMarker.setCursor('pointer'); | ||
me.position = null; | ||
} | ||
} | ||
DrawingManager.prototype._fitBoundsArea = function (coordinates) { | ||
let me = this; | ||
let bounds = new google.maps.LatLngBounds(); | ||
for (var n = 0; n < coordinates.length; n++) { | ||
bounds.extend(coordinates[n]); | ||
} | ||
me.map.panToBounds(bounds); | ||
me.map.fitBounds(bounds); | ||
} | ||
DrawingManager.prototype._convertCoordinates = function (coordinates) { | ||
let positions = []; | ||
for (var n = 0; n < coordinates.length; n++) { | ||
let item = coordinates[n]; | ||
let position = { | ||
latitude: item.lat(), | ||
longitude: item.lng(), | ||
if (!this._enableDraw) { | ||
createCenterMarker(); | ||
google.maps.event.clearListeners(me, 'click'); | ||
} | ||
positions.push(position); | ||
} | ||
return positions; | ||
} | ||
this.markerListener = google.maps.event.addListener(me, 'click', (event) => { | ||
event.stop(); | ||
if (this._enableDraw) { | ||
createCenterMarker(event) | ||
} | ||
}); | ||
}, | ||
DrawingManager.prototype._bindMarker = function () { | ||
DrawingManager.prototype._bindCircle = function () { | ||
let me = this; | ||
me._removeCircle(); | ||
let me = this; | ||
if (me._centerMarker) { | ||
me._circle = new google.maps.Circle({ | ||
strokeColor: me.circleOptions.strokeColor, | ||
strokeOpacity: me.circleOptions.strokeOpacity, | ||
strokeWeight: me.circleOptions.strokeWeight, | ||
fillColor: me.circleOptions.fillColor, | ||
fillOpacity: me.circleOptions.fillOpacity, | ||
center: me._centerMarker.getPosition(), | ||
radius: me.radius, | ||
geodesic: false, | ||
optimized: true, | ||
}); | ||
me._removeArea(); | ||
me._removeCenterMarker(); | ||
me._circle.setMap(me.map); | ||
google.maps.event.clearListeners(me, 'click'); | ||
google.maps.event.clearListeners(me, 'mousedown'); | ||
google.maps.event.clearListeners(me, 'mouseup'); | ||
google.maps.event.trigger(me, 'draw:circle_create', this._getInfo()); | ||
me._removeCircle(); | ||
if (me.circleOptions.fitBounds) { | ||
me._fitBoundsCircle(); | ||
} | ||
var createCenterMarker = (e) => { | ||
me._createVertexMarker(); | ||
let isIconSelected = false; | ||
me._removeCenterMarker(); | ||
me._removeCircle(); | ||
me._centerMarker.setDraggable(true); | ||
me._centerMarker.setCursor('move'); | ||
me._setIconMarker(me.markerOptions.iconUrl); | ||
if (e) { | ||
me._setPosition(e); | ||
me._centerMarkerAddEventListener(); | ||
google.maps.event.clearListeners(me, 'click'); | ||
} | ||
}, | ||
DrawingManager.prototype._setIconMarker = function (iconUrl) { | ||
let me = this; | ||
if (me._centerMarker) { | ||
const icon = { | ||
url: iconUrl, | ||
}; | ||
me._centerMarker.setIcon(icon); | ||
} | ||
}, | ||
if (me.position) { | ||
me._centerMarker = new google.maps.Marker({ | ||
draggable: false, | ||
zIndex: 1000002, | ||
position: me.position, | ||
icon: me.markerOptions.iconUrl, | ||
raiseOnDrag: false, | ||
optimized: true, | ||
}); | ||
DrawingManager.prototype.setEnableDraw = function (enabled) { | ||
this._enableDraw = enabled; | ||
}, | ||
me._centerMarker.setMap(me.map); | ||
me.map.setCenter(me.position); | ||
if (me.map.getZoom() < 9) { | ||
me.map.setZoom(9); | ||
} | ||
DrawingManager.prototype._removeCircle = function () { | ||
let me = this; | ||
if (me._circle) { | ||
me._circle.setMap(null); | ||
me._circle = null; | ||
me._vertexMarker.setMap(null); | ||
google.maps.event.trigger(me, 'draw:circle_remove', null); | ||
} | ||
google.maps.event.trigger(me, 'draw:marker_create', me._getPosition()); | ||
}, | ||
google.maps.event.addListener(me._centerMarker, 'click', () => { | ||
google.maps.event.trigger(me, 'draw:marker_click', me._getPosition()); | ||
if (!isIconSelected) { | ||
me._setIconMarker(me.markerOptions.iconUrlSelected); | ||
isIconSelected = true; | ||
} | ||
}); | ||
me._centerMarker.setCursor('pointer'); | ||
me.position = null; | ||
DrawingManager.prototype._removeCenterMarker = function () { | ||
let me = this; | ||
if (me._centerMarker) { | ||
me._centerMarker.setMap(null); | ||
me._centerMarker = null; | ||
google.maps.event.trigger(me, 'draw:marker_remove', null); | ||
} | ||
} | ||
}, | ||
if (!this._enableDraw) { | ||
createCenterMarker(); | ||
google.maps.event.clearListeners(me, 'click'); | ||
} | ||
this.markerListener = google.maps.event.addListener(me, 'click', (event) => { | ||
event.stop(); | ||
if (this._enableDraw) { | ||
createCenterMarker(event) | ||
DrawingManager.prototype._removeArea = function () { | ||
let me = this; | ||
if (me._area) { | ||
me._area.setMap(null); | ||
me._area = null; | ||
google.maps.event.trigger(me, 'draw:area_remove', null); | ||
} | ||
}); | ||
} | ||
}, | ||
DrawingManager.prototype._bindCircle = function () { | ||
DrawingManager.prototype._createVertexMarker = function () { | ||
let me = this; | ||
me.to = null; | ||
me.to = me.destination(this._centerMarker.getPosition(), 90, this.radius); | ||
me.fillColor = 'white'; | ||
var me = this; | ||
let svg = [ | ||
`<?xml version="1.0"?>`, | ||
`<svg width="16px" height="16px" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">`, | ||
`<circle stroke="#003dd9" fill="${me.fillColor}" stroke-width="10" cx="50" cy="50" r="35"/>`, | ||
`</svg>` | ||
].join('\n'); | ||
me._removeCircle(); | ||
me._vertexMarker = new google.maps.Marker({ | ||
position: me.to, | ||
draggable: true, | ||
icon: { url: 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg), scaledSize: new google.maps.Size(15, 15) }, | ||
raiseOnDrag: false, | ||
optimized: true, | ||
if (me._centerMarker) { | ||
me.circle = new google.maps.Circle({ | ||
strokeColor: me.circleOptions.strokeColor, | ||
strokeOpacity: me.circleOptions.strokeOpacity, | ||
strokeWeight: me.circleOptions.strokeWeight, | ||
fillColor: me.circleOptions.fillColor, | ||
fillOpacity: me.circleOptions.fillOpacity, | ||
center: me._centerMarker.getPosition(), | ||
radius: me.radius, | ||
geodesic: false, | ||
optimized: true, | ||
}); | ||
me.circle.setMap(me.map); | ||
me._vertexMarker.setMap(me.map); | ||
me._vertexMarker.setCursor('col-resize'); | ||
me._vertexMarkerAddEventListener(); | ||
google.maps.event.trigger(me, 'draw:circle_create', this._getInfo()); | ||
}, | ||
me.map.fitBounds(me.circle.getBounds()); | ||
DrawingManager.prototype._vertexMarkerAddEventListener = function () { | ||
let me = this; | ||
google.maps.event.addListener(me._vertexMarker, 'drag', (event) => { | ||
let distance = me.getDistanceTo(me._centerMarker.getPosition(), event.latLng); | ||
me._createVertexMarker(); | ||
me.radius = distance; | ||
me._centerMarker.setDraggable(true); | ||
me._centerMarker.setCursor('move'); | ||
me._setIconMarker(me.markerOptions.iconUrl); | ||
if (me._circle) { | ||
me._circle.setRadius(distance); | ||
} | ||
me._centerMarkerAddEventListener(); | ||
google.maps.event.clearListeners(me, 'click'); | ||
} | ||
let pixel = me.getXYbyEvent(event); | ||
let ev = { | ||
pixel, | ||
radius: me._circle.getRadius() | ||
} | ||
} | ||
google.maps.event.trigger(me, 'draw:circle_radius_change', ev); | ||
DrawingManager.prototype._setIconMarker = function (iconUrl) { | ||
}); | ||
let me = this; | ||
if (me._centerMarker) { | ||
const icon = { | ||
url: iconUrl, | ||
}; | ||
me._centerMarker.setIcon(icon); | ||
} | ||
} | ||
google.maps.event.addListener(me._vertexMarker, 'dragend', () => { | ||
google.maps.event.trigger(me, 'draw:circle_radius_complete', this._getInfo()); | ||
}); | ||
DrawingManager.prototype.setEnableDraw = function (enabled) { | ||
}, | ||
this._enableDraw = enabled; | ||
} | ||
DrawingManager.prototype._removeCircle = function () { | ||
let me = this; | ||
if (me.circle) { | ||
me.circle.setMap(null); | ||
me.circle = null; | ||
me._vertexMarker.setMap(null); | ||
google.maps.event.trigger(me, 'draw:circle_remove', null); | ||
} | ||
} | ||
DrawingManager.prototype._removeCenterMarker = function () { | ||
let me = this; | ||
if (me._centerMarker) { | ||
me._centerMarker.setMap(null); | ||
me._centerMarker = null; | ||
google.maps.event.trigger(me, 'draw:marker_remove', null); | ||
} | ||
} | ||
DrawingManager.prototype._removeArea = function () { | ||
let me = this; | ||
if (me.area) { | ||
me.area.setMap(null); | ||
me.area = null; | ||
google.maps.event.trigger(me, 'draw:area_remove', null); | ||
} | ||
} | ||
DrawingManager.prototype._createVertexMarker = function () { | ||
let me = this; | ||
me.to = null; | ||
me.to = me.destination(this._centerMarker.getPosition(), 90, this.radius); | ||
me.fillColor = 'white'; | ||
let svg = [ | ||
`<?xml version="1.0"?>`, | ||
`<svg width="16px" height="16px" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">`, | ||
`<circle stroke="#003dd9" fill="${me.fillColor}" stroke-width="10" cx="50" cy="50" r="35"/>`, | ||
`</svg>` | ||
].join('\n'); | ||
me._vertexMarker = new google.maps.Marker({ | ||
position: me.to, | ||
draggable: true, | ||
icon: { url: 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg), scaledSize: new google.maps.Size(15, 15) }, | ||
raiseOnDrag: false, | ||
optimized: true, | ||
}); | ||
me._vertexMarker.setMap(me.map); | ||
me._vertexMarker.setCursor('col-resize'); | ||
me._vertexMarkerAddEventListener(); | ||
} | ||
DrawingManager.prototype._vertexMarkerAddEventListener = function () { | ||
let me = this; | ||
google.maps.event.addListener(me._vertexMarker, 'drag', (event) => { | ||
let distance = me.getDistanceTo(me._centerMarker.getPosition(), event.latLng); | ||
me.radius = distance; | ||
if (me.circle) { | ||
me.circle.setRadius(distance); | ||
DrawingManager.prototype.getXYbyEvent = function (event) { | ||
let me = this; | ||
let client = me.getProjection().fromLatLngToContainerPixel(event.latLng); | ||
return { | ||
clientX: client.x, | ||
clientY: client.y | ||
} | ||
}, | ||
let pixel = me.getXYbyEvent(event); | ||
let ev = { | ||
pixel, | ||
radius: me.circle.getRadius() | ||
} | ||
DrawingManager.prototype._centerMarkerAddEventListener = function () { | ||
let me = this; | ||
google.maps.event.addListener(me._centerMarker, 'drag', function (event) { | ||
google.maps.event.trigger(me, 'draw:circle_radius_change', ev); | ||
me._circle.setCenter(event.latLng); | ||
}); | ||
let to = me.destination(event.latLng, 90, me.radius); | ||
google.maps.event.addListener(me._vertexMarker, 'dragend', () => { | ||
google.maps.event.trigger(me, 'draw:circle_radius_complete', this._getInfo()); | ||
}); | ||
if (me._vertexMarker) { | ||
me._vertexMarker.setPosition(to); | ||
} | ||
} | ||
google.maps.event.trigger(me, 'draw:circle_centre_change', me._getInfo()); | ||
}); | ||
google.maps.event.addListener(me._centerMarker, 'dragend', function () { | ||
google.maps.event.trigger(me, 'draw:circle_center_complete', me._getInfo()); | ||
}); | ||
DrawingManager.prototype.getXYbyEvent = function (event) { | ||
google.maps.event.addListener(me._centerMarker, 'mouseover', function (event) { | ||
google.maps.event.trigger(me, 'draw:marker_mouseover', me._getInfo()); | ||
}); | ||
let me = this; | ||
google.maps.event.addListener(me._centerMarker, 'mouseout', function (event) { | ||
google.maps.event.trigger(me, 'draw:marker_mouseout', me._getInfo()); | ||
}); | ||
let client = me.getProjection().fromLatLngToContainerPixel(event.latLng); | ||
return { | ||
clientX: client.x, | ||
clientY: client.y | ||
} | ||
}; | ||
google.maps.event.clearListeners(me._centerMarker, 'click'); | ||
DrawingManager.prototype._centerMarkerAddEventListener = function () { | ||
}, | ||
let me = this; | ||
DrawingManager.prototype.destination = function (latlng, heading, distance) { | ||
heading = (heading + 360) % 360; | ||
var rad = Math.PI / 180, | ||
radInv = 180 / Math.PI, | ||
R = 6378137, | ||
lon1 = latlng.lng() * rad, | ||
lat1 = latlng.lat() * rad, | ||
rheading = heading * rad, | ||
sinLat1 = Math.sin(lat1), | ||
cosLat1 = Math.cos(lat1), | ||
cosDistR = Math.cos(distance / R), | ||
sinDistR = Math.sin(distance / R), | ||
lat2 = Math.asin(sinLat1 * cosDistR + cosLat1 * | ||
sinDistR * Math.cos(rheading)), | ||
lon2 = lon1 + Math.atan2(Math.sin(rheading) * sinDistR * | ||
cosLat1, cosDistR - sinLat1 * Math.sin(lat2)); | ||
lon2 = lon2 * radInv; | ||
lon2 = lon2 > 180 ? lon2 - 360 : lon2 < -180 ? lon2 + 360 : lon2; | ||
return new google.maps.LatLng(lat2 * radInv, lon2) | ||
}, | ||
google.maps.event.addListener(me._centerMarker, 'drag', function (event) { | ||
DrawingManager.prototype.degreeToRad = function (degree) { | ||
return Math.PI * degree / 180; | ||
}, | ||
me.circle.setCenter(event.latLng); | ||
let to = me.destination(event.latLng, 90, me.radius); | ||
if (me._vertexMarker) { | ||
me._vertexMarker.setPosition(to); | ||
} | ||
google.maps.event.trigger(me, 'draw:circle_centre_change', me._getInfo()); | ||
}); | ||
google.maps.event.addListener(me._centerMarker, 'dragend', function () { | ||
google.maps.event.trigger(me, 'draw:circle_center_complete', me._getInfo()); | ||
}); | ||
google.maps.event.addListener(me._centerMarker, 'mouseover', function (event) { | ||
google.maps.event.trigger(me, 'draw:marker_mouseover', me._getInfo()); | ||
}); | ||
google.maps.event.addListener(me._centerMarker, 'mouseout', function (event) { | ||
google.maps.event.trigger(me, 'draw:marker_mouseout', me._getInfo()); | ||
}); | ||
google.maps.event.clearListeners(me._centerMarker, 'click'); | ||
} | ||
DrawingManager.prototype.destination = function (latlng, heading, distance) { | ||
heading = (heading + 360) % 360; | ||
var rad = Math.PI / 180, | ||
radInv = 180 / Math.PI, | ||
R = 6378137, | ||
lon1 = latlng.lng() * rad, | ||
lat1 = latlng.lat() * rad, | ||
rheading = heading * rad, | ||
sinLat1 = Math.sin(lat1), | ||
cosLat1 = Math.cos(lat1), | ||
cosDistR = Math.cos(distance / R), | ||
sinDistR = Math.sin(distance / R), | ||
lat2 = Math.asin(sinLat1 * cosDistR + cosLat1 * | ||
sinDistR * Math.cos(rheading)), | ||
lon2 = lon1 + Math.atan2(Math.sin(rheading) * sinDistR * | ||
cosLat1, cosDistR - sinLat1 * Math.sin(lat2)); | ||
lon2 = lon2 * radInv; | ||
lon2 = lon2 > 180 ? lon2 - 360 : lon2 < -180 ? lon2 + 360 : lon2; | ||
return new google.maps.LatLng(lat2 * radInv, lon2) | ||
}; | ||
DrawingManager.prototype.degreeToRad = function (degree) { | ||
return Math.PI * degree / 180; | ||
}, | ||
DrawingManager.prototype._getRange = function (v, a, b) { | ||
if (a != null) { | ||
@@ -582,75 +567,66 @@ v = Math.max(v, a); | ||
return v; | ||
}; | ||
}, | ||
DrawingManager.prototype._getLoop = function (v, a, b) { | ||
DrawingManager.prototype._getLoop = function (v, a, b) { | ||
while (v > b) { | ||
v -= b - a | ||
} | ||
while (v < a) { | ||
v += b - a | ||
} | ||
return v; | ||
}, | ||
while (v > b) { | ||
v -= b - a | ||
} | ||
while (v < a) { | ||
v += b - a | ||
} | ||
return v; | ||
}; | ||
DrawingManager.prototype.getDistanceTo = function (point1, point2) { | ||
DrawingManager.prototype.getDistanceTo = function (point1, point2) { | ||
let me = this; | ||
point1.ln = me._getLoop(point1.lng(), -180, 180); | ||
point1.lt = me._getRange(point1.lat(), -74, 74); | ||
point2.ln = me._getLoop(point2.lng(), -180, 180); | ||
point2.lt = me._getRange(point2.lat(), -74, 74); | ||
let me = this; | ||
point1.ln = me._getLoop(point1.lng(), -180, 180); | ||
point1.lt = me._getRange(point1.lat(), -74, 74); | ||
point2.ln = me._getLoop(point2.lng(), -180, 180); | ||
point2.lt = me._getRange(point2.lat(), -74, 74); | ||
var x1, x2, y1, y2; | ||
x1 = this.degreeToRad(point1.ln); | ||
y1 = this.degreeToRad(point1.lt); | ||
x2 = this.degreeToRad(point2.ln); | ||
y2 = this.degreeToRad(point2.lt); | ||
var x1, x2, y1, y2; | ||
x1 = this.degreeToRad(point1.ln); | ||
y1 = this.degreeToRad(point1.lt); | ||
x2 = this.degreeToRad(point2.ln); | ||
y2 = this.degreeToRad(point2.lt); | ||
return 6370996.81 * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1) * Math.cos(y2) * Math.cos(x2 - x1))); | ||
}, | ||
return 6370996.81 * Math.acos((Math.sin(y1) * Math.sin(y2) + Math.cos(y1) * Math.cos(y2) * Math.cos(x2 - x1))); | ||
}; | ||
DrawingManager.prototype.extend = function (obj1, obj2) { | ||
return (function (object) { | ||
var property; | ||
for (property in object.prototype) { | ||
this.prototype[property] = object.prototype[property]; | ||
} | ||
return this; | ||
}).apply(obj1, [obj2]); | ||
}, | ||
DrawingManager.prototype._getInfo = function () { | ||
let me = this; | ||
let position = { | ||
latitude: me._centerMarker.getPosition().lat(), | ||
longitude: me._centerMarker.getPosition().lng() | ||
} | ||
let info = { | ||
radius: me._circle.getRadius(), | ||
position | ||
}; | ||
return info; | ||
}, | ||
DrawingManager.prototype.extend = function (obj1, obj2) { | ||
return (function (object) { | ||
var property; | ||
for (property in object.prototype) { | ||
this.prototype[property] = object.prototype[property]; | ||
DrawingManager.prototype._getPosition = function () { | ||
let me = this; | ||
let position = { | ||
latitude: me._centerMarker.getPosition().lat(), | ||
longitude: me._centerMarker.getPosition().lng() | ||
} | ||
return this; | ||
}).apply(obj1, [obj2]); | ||
}; | ||
DrawingManager.prototype._getInfo = function () { | ||
let me = this; | ||
let position = { | ||
latitude: me._centerMarker.getPosition().lat(), | ||
longitude: me._centerMarker.getPosition().lng() | ||
} | ||
let info = { | ||
radius: me.circle.getRadius(), | ||
position | ||
return position; | ||
}; | ||
return info; | ||
} | ||
DrawingManager.prototype._getPosition = function () { | ||
let me = this; | ||
let position = { | ||
latitude: me._centerMarker.getPosition().lat(), | ||
longitude: me._centerMarker.getPosition().lng() | ||
} | ||
return position; | ||
} | ||
if (typeof module == 'object') { | ||
module.exports = { default: DrawingManager, DrawingManager: DrawingManager }; | ||
} |
{ | ||
"name": "@h21-map/google-drawing-manager", | ||
"scope":"@h21-map", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "A library of Google Map JS API", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20875
514