commit 871fc17b2c0078a8880f5232bbd3d5f345fd6b02
parent ad7b4563d671e1bf0ad546702eb74886b3fb7f68
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Tue, 31 Jan 2017 02:28:05 +0300
[wikimapia] show place details on click
Diffstat:
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/lib/leaflet.layer.wikimapia/index.js b/src/lib/leaflet.layer.wikimapia/index.js
@@ -1,6 +1,7 @@
import L from 'leaflet';
import {WikimapiaLoader} from './wikimapia-loader';
import './style.css';
+import {openPopupWindow} from 'lib/popup-window';
function isPointInPolygon(polygon, p) {
@@ -186,7 +187,11 @@ L.Wikimapia = L.GridLayer.extend({
},
onClick: function(e) {
-
+ const place = this.getPlaceAtMousePos(e);
+ if (place) {
+ const url = `http://wikimapia.org/${place.id}/ru/`;
+ openPopupWindow(url, 568, 'wikimapia-details');
+ }
},
getPlaceAtLatlng: function(latlng, places) {
diff --git a/src/lib/popup-window/index.js b/src/lib/popup-window/index.js
@@ -0,0 +1,27 @@
+function openPopupWindow(url, width, uniqName = null) {
+ var left, top, height,
+ screenLeft = screen.availLeft || 0,
+ screenTop = screen.availTop || 0,
+ bordersWidth = 8;
+ // if browser window is in the right half of screen, place new window on left half
+ if (window.screenX - screenLeft - bordersWidth * 1.5 > width) {
+ left = window.screenX - width - bordersWidth * 1.5;
+ // if browser window is in the left half of screen, place new window on right half
+ } else if (window.screenX + window.outerWidth + width + bordersWidth * 1.5 < screenLeft + screen.availWidth) {
+ left = window.screenX + window.outerWidth + bordersWidth;
+ // if screen is small or browser window occupies whole screen, place new window on top of current window
+ } else {
+ left = window.screenX + window.outerWidth / 2 - width / 2;
+ if (left < 0) {
+ left = 0;
+ }
+ }
+ top = window.screenY;
+ height = window.innerHeight;
+ var features = 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top;
+ features += ',resizable,scrollbars';
+ window.open(url, uniqName, features)
+ .focus();
+}
+
+export {openPopupWindow};
+\ No newline at end of file