- {/*render markers before map load done*/}
+ {/* render markers before map load done */}
{mapMarkerPrerender}
);
diff --git a/src/google_map_map.js b/src/google_map_map.js
index af76ddd..c2df4e3 100644
--- a/src/google_map_map.js
+++ b/src/google_map_map.js
@@ -7,7 +7,7 @@ const style = {
top: 0,
margin: 0,
padding: 0,
- position: 'absolute'
+ position: 'absolute',
};
export default class GoogleMapMap extends Component {
diff --git a/src/google_map_markers.js b/src/google_map_markers.js
index 68a085a..15ab7b1 100644
--- a/src/google_map_markers.js
+++ b/src/google_map_markers.js
@@ -9,7 +9,7 @@ const mainStyle = {
top: 0,
margin: 0,
padding: 0,
- position: 'absolute'
+ position: 'absolute',
};
const style = {
@@ -18,7 +18,7 @@ const style = {
left: 0,
top: 0,
backgroundColor: 'transparent',
- position: 'absolute'
+ position: 'absolute',
};
export default class GoogleMapMarkers extends Component {
@@ -31,15 +31,13 @@ export default class GoogleMapMarkers extends Component {
onChildMouseLeave: PropTypes.func,
onChildMouseEnter: PropTypes.func,
hoverDistance: PropTypes.number,
- projectFromLeftTop: PropTypes.bool
+ projectFromLeftTop: PropTypes.bool,
};
static defaultProps = {
- projectFromLeftTop: false
+ projectFromLeftTop: false,
};
- shouldComponentUpdate = shouldPureComponentUpdate;
-
constructor(props) {
super(props);
this.props.dispatcher.on('kON_CHANGE', this._onChangeHandler);
@@ -54,10 +52,20 @@ export default class GoogleMapMarkers extends Component {
this.state = {...this._getState(), hoverKey: null};
}
+ shouldComponentUpdate = shouldPureComponentUpdate;
+
+ componentWillUnmount() {
+ this.props.dispatcher.removeListener('kON_CHANGE', this._onChangeHandler);
+ this.props.dispatcher.removeListener('kON_MOUSE_POSITION_CHANGE', this._onMouseChangeHandler);
+ this.props.dispatcher.removeListener('kON_CLICK', this._onChildClick);
+
+ this.dimesionsCache_ = null;
+ }
+
_getState = () => {
return {
children: this.props.dispatcher.getChildren(),
- updateCounter: this.props.dispatcher.getUpdateCounter()
+ updateCounter: this.props.dispatcher.getUpdateCounter(),
};
}
@@ -138,7 +146,7 @@ export default class GoogleMapMarkers extends Component {
const mp = this.props.dispatcher.getMousePosition();
if (mp) {
- let distances = [];
+ const distances = [];
React.Children.forEach(this.state.children, (child, childIndex) => {
const childKey = child.key !== undefined && child.key !== null ? child.key : childIndex;
@@ -148,7 +156,7 @@ export default class GoogleMapMarkers extends Component {
{
key: childKey,
dist: dist,
- props: child.props
+ props: child.props,
});
}
});
@@ -176,24 +184,20 @@ export default class GoogleMapMarkers extends Component {
return this.dimesionsCache_[childKey];
}
- componentWillUnmount() {
- this.props.dispatcher.removeListener('kON_CHANGE', this._onChangeHandler);
- this.props.dispatcher.removeListener('kON_MOUSE_POSITION_CHANGE', this._onMouseChangeHandler);
- this.props.dispatcher.removeListener('kON_CLICK', this._onChildClick);
-
- this.dimesionsCache_ = null;
- }
-
render() {
const mainElementStyle = this.props.style || mainStyle;
this.dimesionsCache_ = {};
const markers = React.Children.map(this.state.children, (child, childIndex) => {
- const pt = this.props.geoService.project({lat: child.props.lat, lng: child.props.lng}, this.props.projectFromLeftTop);
+ const pt = this.props.geoService.project({
+ lat: child.props.lat,
+ lng: child.props.lng,
+ }, this.props.projectFromLeftTop);
+
const stylePtPos = {
left: pt.x,
- top: pt.y
+ top: pt.y,
};
let dx = 0;
@@ -206,9 +210,15 @@ export default class GoogleMapMarkers extends Component {
}
}
- // to prevent rerender on child element i need to pass const params $getDimensions and $dimensionKey instead of dimension object
+ // to prevent rerender on child element i need to pass
+ // const params $getDimensions and $dimensionKey instead of dimension object
const childKey = child.key !== undefined && child.key !== null ? child.key : childIndex;
- this.dimesionsCache_[childKey] = {x: pt.x + dx, y: pt.y + dy, lat: child.props.lat, lng: child.props.lng};
+ this.dimesionsCache_[childKey] = {
+ x: pt.x + dx,
+ y: pt.y + dy,
+ lat: child.props.lat,
+ lng: child.props.lng,
+ };
return (
@@ -217,7 +227,7 @@ export default class GoogleMapMarkers extends Component {
$getDimensions: this._getDimensions,
$dimensionKey: childKey,
$geoService: this.props.geoService,
- $onMouseAllow: this._onMouseAllow
+ $onMouseAllow: this._onMouseAllow,
})}
);
diff --git a/src/google_map_markers_prerender.js b/src/google_map_markers_prerender.js
index 6e6a3e6..fbc7c76 100644
--- a/src/google_map_markers_prerender.js
+++ b/src/google_map_markers_prerender.js
@@ -1,4 +1,4 @@
-import React, {PropTypes, Component} from 'react';
+import React, {/* PropTypes, */ Component} from 'react';
import GoogleMapMarkers from './google_map_markers.js';
const style = {
@@ -9,7 +9,7 @@ const style = {
// backgroundColor: 'red',
margin: 0,
padding: 0,
- position: 'absolute'
+ position: 'absolute',
// opacity: 0.3
};
diff --git a/src/utils/detect.js b/src/utils/detect.js
index c9d91ce..07efe9e 100644
--- a/src/utils/detect.js
+++ b/src/utils/detect.js
@@ -1,4 +1,4 @@
-// code here http://stackoverflow.com/questions/5899783/detect-safari-chrome-ie-firefox-opera-with-user-agent
+// http://stackoverflow.com/questions/5899783/detect-safari-chrome-ie-firefox-opera-with-user-agent
let detectBrowserResult_ = null;
export default function detectBrowser() {
@@ -26,6 +26,13 @@ export default function detectBrowser() {
return detectBrowserResult_;
}
- detectBrowserResult_ = {isChrome: true, isExplorer: false, isFirefox: false, isOpera: false, isSafari: false};
+ detectBrowserResult_ = {
+ isChrome: true,
+ isExplorer: false,
+ isFirefox: false,
+ isOpera: false,
+ isSafari: false,
+ };
+
return detectBrowserResult_;
}
diff --git a/src/utils/geo.js b/src/utils/geo.js
index 24af9c0..2aea36d 100644
--- a/src/utils/geo.js
+++ b/src/utils/geo.js
@@ -75,7 +75,7 @@ export default class Geo {
}
getCenter() {
- let ptRes = this.transform_.pointLocation({x: 0, y: 0});
+ const ptRes = this.transform_.pointLocation({x: 0, y: 0});
return ptRes;
}
@@ -87,12 +87,18 @@ export default class Geo {
const bndL = margins && margins[3] || 0;
if (this.getWidth() - bndR - bndL > 0 && this.getHeight() - bndT - bndB > 0) {
- const topLeftCorner = this.unproject({x: bndL - this.getWidth() / 2, y: bndT - this.getHeight() / 2});
- const bottomRightCorner = this.unproject({x: this.getWidth() / 2 - bndR, y: this.getHeight() / 2 - bndB});
+ const topLeftCorner = this.unproject({
+ x: bndL - this.getWidth() / 2,
+ y: bndT - this.getHeight() / 2,
+ });
+ const bottomRightCorner = this.unproject({
+ x: this.getWidth() / 2 - bndR,
+ y: this.getHeight() / 2 - bndB,
+ });
let res = [
topLeftCorner.lat, topLeftCorner.lng,
- bottomRightCorner.lat, bottomRightCorner.lng
+ bottomRightCorner.lat, bottomRightCorner.lng,
];
if (roundFactor) {
@@ -104,4 +110,3 @@ export default class Geo {
return [0, 0, 0, 0];
}
}
-
diff --git a/src/utils/lib_geo/lat_lng.js b/src/utils/lib_geo/lat_lng.js
index 78ee4a6..ab8cfcd 100644
--- a/src/utils/lib_geo/lat_lng.js
+++ b/src/utils/lib_geo/lat_lng.js
@@ -1,29 +1,25 @@
-'use strict';
+import { wrap } from './wrap.js';
-module.exports = LatLng;
+export default class LatLng {
+ static convert = (a) => {
+ if (a instanceof LatLng) {
+ return a;
+ }
+ if (Array.isArray(a)) {
+ return new LatLng(a[0], a[1]);
+ }
+ return a;
+ }
-var wrap = require('./wrap.js').wrap;
-
-function LatLng(lat, lng) {
+ constructor(lat, lng) {
if (isNaN(lat) || isNaN(lng)) {
- throw new Error('Invalid LatLng object: (' + lat + ', ' + lng + ')');
+ throw new Error('Invalid LatLng object: (' + lat + ', ' + lng + ')');
}
this.lat = +lat;
this.lng = +lng;
-}
+ }
-LatLng.prototype.wrap = function () {
+ wrap() {
return new LatLng(this.lat, wrap(this.lng, -180, 180));
-};
-
-// constructs LatLng from an array if necessary
-
-LatLng.convert = function (a) {
- if (a instanceof LatLng) {
- return a;
- }
- if (Array.isArray(a)) {
- return new LatLng(a[0], a[1]);
- }
- return a;
-};
+ }
+}
diff --git a/src/utils/lib_geo/lat_lng_bounds.js b/src/utils/lib_geo/lat_lng_bounds.js
index 9c6d6b0..069c53c 100644
--- a/src/utils/lib_geo/lat_lng_bounds.js
+++ b/src/utils/lib_geo/lat_lng_bounds.js
@@ -1,72 +1,72 @@
-'use strict';
+import LatLng from './lat_lng';
-module.exports = LatLngBounds;
-
-var LatLng = require('./lat_lng');
-
-function LatLngBounds(sw, ne) {
- if (!sw) return;
-
- var latlngs = ne ? [sw, ne] : sw;
-
- for (var i = 0, len = latlngs.length; i < len; i++) {
- this.extend(latlngs[i]);
- }
-}
-
-LatLngBounds.prototype = {
-
- // extend the bounds to contain the given point or bounds
- extend: function (obj) {
- var sw = this._sw,
- ne = this._ne,
- sw2, ne2;
-
- if (obj instanceof LatLng) {
- sw2 = obj;
- ne2 = obj;
-
- } else if (obj instanceof LatLngBounds) {
- sw2 = obj._sw;
- ne2 = obj._ne;
-
- if (!sw2 || !ne2) return this;
-
- } else {
- return obj ? this.extend(LatLng.convert(obj) || LatLngBounds.convert(obj)) : this;
- }
-
- if (!sw && !ne) {
- this._sw = new LatLng(sw2.lat, sw2.lng);
- this._ne = new LatLng(ne2.lat, ne2.lng);
-
- } else {
- sw.lat = Math.min(sw2.lat, sw.lat);
- sw.lng = Math.min(sw2.lng, sw.lng);
- ne.lat = Math.max(ne2.lat, ne.lat);
- ne.lng = Math.max(ne2.lng, ne.lng);
- }
-
- return this;
- },
-
- getCenter: function () {
- return new LatLng((this._sw.lat + this._ne.lat) / 2, (this._sw.lng + this._ne.lng) / 2);
- },
-
- getSouthWest: function () { return this._sw; },
- getNorthEast: function () { return this._ne; },
- getNorthWest: function () { return new LatLng(this.getNorth(), this.getWest()); },
- getSouthEast: function () { return new LatLng(this.getSouth(), this.getEast()); },
-
- getWest: function () { return this._sw.lng; },
- getSouth: function () { return this._sw.lat; },
- getEast: function () { return this._ne.lng; },
- getNorth: function () { return this._ne.lat; }
-};
-
-// constructs LatLngBounds from an array if necessary
-LatLngBounds.convert = function (a) {
+export default class LatLngBounds {
+ static convert = (a) => {
if (!a || a instanceof LatLngBounds) return a;
return new LatLngBounds(a);
-};
+ }
+
+ constructor(sw, ne) {
+ if (!sw) return;
+
+ const latlngs = ne ? [sw, ne] : sw;
+
+ for (let i = 0, len = latlngs.length; i < len; i++) {
+ this.extend(latlngs[i]);
+ }
+ }
+
+ extend(obj) {
+ const sw = this._sw;
+ const ne = this._ne;
+ let sw2;
+ let ne2;
+
+ if (obj instanceof LatLng) {
+ sw2 = obj;
+ ne2 = obj;
+ } else if (obj instanceof LatLngBounds) {
+ sw2 = obj._sw;
+ ne2 = obj._ne;
+
+ if (!sw2 || !ne2) return this;
+ } else {
+ return obj
+ ? this.extend(LatLng.convert(obj) || LatLngBounds.convert(obj))
+ : this;
+ }
+
+ if (!sw && !ne) {
+ this._sw = new LatLng(sw2.lat, sw2.lng);
+ this._ne = new LatLng(ne2.lat, ne2.lng);
+
+ } else {
+ sw.lat = Math.min(sw2.lat, sw.lat);
+ sw.lng = Math.min(sw2.lng, sw.lng);
+ ne.lat = Math.max(ne2.lat, ne.lat);
+ ne.lng = Math.max(ne2.lng, ne.lng);
+ }
+
+ return this;
+ }
+
+ getCenter = () => new LatLng(
+ (this._sw.lat + this._ne.lat) / 2,
+ (this._sw.lng + this._ne.lng) / 2)
+
+ getSouthWest = () => this._sw
+
+ getNorthEast = () => this._ne
+
+ getNorthWest = () => new LatLng(this.getNorth(), this.getWest())
+
+ getSouthEast = () => new LatLng(this.getSouth(), this.getEast())
+
+ getWest = () => this._sw.lng
+
+ getSouth = () => this._sw.lat
+
+ getEast = () => this._ne.lng
+
+ getNorth = () => this._ne.lat
+}
diff --git a/src/utils/lib_geo/transform.js b/src/utils/lib_geo/transform.js
index c9c585f..6294d80 100644
--- a/src/utils/lib_geo/transform.js
+++ b/src/utils/lib_geo/transform.js
@@ -1,121 +1,133 @@
-
-const LatLng = require('./lat_lng');
-const Point = require('point-geometry');
-const wrap = require('./wrap.js').wrap;
-
+import LatLng from './lat_lng';
+import Point from 'point-geometry';
+import { wrap } from './wrap.js';
// A single transform, generally used for a single tile to be scaled, rotated, and zoomed.
+export default class Transform {
+ constructor(tileSize, minZoom, maxZoom) {
+ this.tileSize = tileSize || 512; // constant
-function Transform(tileSize, minZoom, maxZoom) {
- this.tileSize = tileSize || 512; // constant
+ this._minZoom = minZoom || 0;
+ this._maxZoom = maxZoom || 52;
- this._minZoom = minZoom || 0;
- this._maxZoom = maxZoom || 52;
+ this.latRange = [-85.05113, 85.05113];
- this.latRange = [-85.05113, 85.05113];
+ this.width = 0;
+ this.height = 0;
+ this.zoom = 0;
+ this.center = new LatLng(0, 0);
+ this.angle = 0;
+ }
- this.width = 0;
- this.height = 0;
- this.zoom = 0;
- this.center = new LatLng(0, 0);
- this.angle = 0;
-}
+ get minZoom() {
+ return this._minZoom;
+ }
-Transform.prototype = {
- get minZoom() { return this._minZoom; },
set minZoom(zoom) {
this._minZoom = zoom;
this.zoom = Math.max(this.zoom, zoom);
- },
+ }
+
+ get maxZoom() {
+ return this._maxZoom;
+ }
- get maxZoom() { return this._maxZoom; },
set maxZoom(zoom) {
this._maxZoom = zoom;
this.zoom = Math.min(this.zoom, zoom);
- },
+ }
get worldSize() {
return this.tileSize * this.scale;
- },
+ }
get centerPoint() {
return new Point(0, 0); // this.size._div(2);
- },
+ }
get size() {
return new Point(this.width, this.height);
- },
+ }
get bearing() {
return -this.angle / Math.PI * 180;
- },
+ }
+
set bearing(bearing) {
this.angle = -wrap(bearing, -180, 180) * Math.PI / 180;
- },
+ }
+
+ get zoom() {
+ return this._zoom;
+ }
- get zoom() { return this._zoom; },
set zoom(zoom) {
- zoom = Math.min(Math.max(zoom, this.minZoom), this.maxZoom);
- this._zoom = zoom;
- this.scale = this.zoomScale(zoom);
- this.tileZoom = Math.floor(zoom);
- this.zoomFraction = zoom - this.tileZoom;
- },
+ const zoomV = Math.min(Math.max(zoom, this.minZoom), this.maxZoom);
+ this._zoom = zoomV;
+ this.scale = this.zoomScale(zoomV);
+ this.tileZoom = Math.floor(zoomV);
+ this.zoomFraction = zoomV - this.tileZoom;
+ }
- zoomScale: function(zoom) { return Math.pow(2, zoom); },
- scaleZoom: function(scale) { return Math.log(scale) / Math.LN2; },
+ zoomScale(zoom) {
+ return Math.pow(2, zoom);
+ }
- project: function(latlng, worldSize) {
+ scaleZoom(scale) {
+ return Math.log(scale) / Math.LN2;
+ }
+
+ project(latlng, worldSize) {
return new Point(
this.lngX(latlng.lng, worldSize),
this.latY(latlng.lat, worldSize));
- },
+ }
- unproject: function(point, worldSize) {
+ unproject(point, worldSize) {
return new LatLng(
this.yLat(point.y, worldSize),
this.xLng(point.x, worldSize));
- },
+ }
get x() {
return this.lngX(this.center.lng);
- },
+ }
+
get y() {
return this.latY(this.center.lat);
- },
+ }
- get point() { return new Point(this.x, this.y); },
+ get point() {
+ return new Point(this.x, this.y);
+ }
// lat/lon <-> absolute pixel coords convertion
- lngX: function(lon, worldSize) {
+ lngX(lon, worldSize) {
return (180 + lon) * (worldSize || this.worldSize) / 360;
- },
+ }
+
// latitude to absolute y coord
- latY: function(lat, worldSize) {
- var y = 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360));
+ latY(lat, worldSize) {
+ const y = 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360));
return (180 - y) * (worldSize || this.worldSize) / 360;
- },
+ }
- xLng: function(x, worldSize) {
+ xLng(x, worldSize) {
return x * 360 / (worldSize || this.worldSize) - 180;
- },
- yLat: function(y, worldSize) {
- var y2 = 180 - y * 360 / (worldSize || this.worldSize);
+ }
+
+ yLat(y, worldSize) {
+ const y2 = 180 - y * 360 / (worldSize || this.worldSize);
return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
- },
+ }
-
- locationPoint: function(latlng) {
- var p = this.project(latlng);
+ locationPoint(latlng) {
+ const p = this.project(latlng);
return this.centerPoint._sub(this.point._sub(p)._rotate(this.angle));
- },
+ }
- pointLocation: function(p) {
- var p2 = this.centerPoint._sub(p)._rotate(-this.angle);
+ pointLocation(p) {
+ const p2 = this.centerPoint._sub(p)._rotate(-this.angle);
return this.unproject(this.point.sub(p2));
- },
-
-
-};
-
-module.exports = Transform;
+ }
+}
diff --git a/src/utils/lib_geo/wrap.js b/src/utils/lib_geo/wrap.js
index 9789b00..6a83e3d 100644
--- a/src/utils/lib_geo/wrap.js
+++ b/src/utils/lib_geo/wrap.js
@@ -1,6 +1,4 @@
-'use strict';
-
-exports.wrap = function (n, min, max) {
- var d = max - min;
- return n === max ? n : ((n - min) % d + d) % d + min;
-};
+export function wrap(n, min, max) {
+ const d = max - min;
+ return n === max ? n : ((n - min) % d + d) % d + min;
+}
diff --git a/src/utils/loaders/google_map_loader.js b/src/utils/loaders/google_map_loader.js
index cc7db98..8684e9f 100644
--- a/src/utils/loaders/google_map_loader.js
+++ b/src/utils/loaders/google_map_loader.js
@@ -3,7 +3,7 @@ let $script_ = null;
let _loadPromise;
// TODO add libraries language and other map options
-module.exports = function googleMapLoader(apiKey) {
+export default function googleMapLoader(apiKey) {
if (!$script_) {
$script_ = require('scriptjs');
}
@@ -34,12 +34,14 @@ module.exports = function googleMapLoader(apiKey) {
const apiKeyString = apiKey ? `&key=${apiKey}` : '';
- $script_(`https://maps.googleapis.com/maps/api/js?callback=_$_google_map_initialize_$_${apiKeyString}`, () => {
- if (typeof window.google === 'undefined') {
- reject(new Error('google map initialization error (not loaded)'));
- }
- });
+ $script_(
+ `https://maps.googleapis.com/maps/api/js?callback=_$_google_map_initialize_$_${apiKeyString}`,
+ () => {
+ if (typeof window.google === 'undefined') {
+ reject(new Error('google map initialization error (not loaded)'));
+ }
+ });
});
return _loadPromise;
-};
+}