cursor: cursor helper

This commit is contained in:
muerwre 2018-12-03 19:15:14 +07:00
parent cfe3b5ec8c
commit 3771e5d338
4 changed files with 61 additions and 7 deletions

32
src/components/Cursor.jsx Normal file
View file

@ -0,0 +1,32 @@
import React from 'react';
import { Icon } from '$components/panels/Icon';
import { MODES } from '$constants/modes';
type Props = {
mode: String,
}
export class Cursor extends React.PureComponent<Props, void> {
componentDidMount() {
window.addEventListener('mousemove', this.moveCursor);
}
moveCursor = e => {
if (!e.clientX || !e.clientY) return;
const { clientX, clientY } = e;
this.cursor.style.transform = `translate3d(${clientX}px, ${clientY}px, 0)`;
};
render() {
const { mode } = this.props;
return (
<div className="cursor-tooltip" ref={el => { this.cursor = el; }}>
{ mode === MODES.ROUTER && <Icon icon="icon-router" />}
{ mode === MODES.POLY && <Icon icon="icon-poly" />}
</div>
);
}
};

View file

@ -2,7 +2,7 @@
const TILEMAPS = { const TILEMAPS = {
WATERCOLOR: { WATERCOLOR: {
name: 'Watercolor', name: 'Watercolor',
url: 'http://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg', url: 'https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg',
range: [1, 2, 3, 4], range: [1, 2, 3, 4],
}, },
DGIS: { DGIS: {
@ -12,27 +12,27 @@ const TILEMAPS = {
}, },
DEFAULT: { DEFAULT: {
name: 'OpenStreetMap', name: 'OpenStreetMap',
url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
range: ['a', 'b', 'c'], range: ['a', 'b', 'c'],
}, },
DARQ: { DARQ: {
name: 'Darq', name: 'Darq',
url: 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', url: 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
range: [1, 2, 3, 4], range: [1, 2, 3, 4],
}, },
BLANK: { BLANK: {
name: 'Blanque', name: 'Blanque',
url: 'http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', url: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
range: [1, 2, 3, 4], range: [1, 2, 3, 4],
}, },
HOT: { HOT: {
name: 'Hot', name: 'Hot',
url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', url: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
range: ['a', 'b', 'c'], range: ['a', 'b', 'c'],
}, },
SAT: { SAT: {
name: 'Google Sattelite', name: 'Google Sattelite',
url: 'http://mt{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}', url: 'https://mt{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',
range: [0, 1, 2, 3], range: [0, 1, 2, 3],
}, },
YMAP: { YMAP: {

View file

@ -11,10 +11,12 @@ import { bindActionCreators } from 'redux';
import { hot } from 'react-hot-loader'; import { hot } from 'react-hot-loader';
import { Renderer } from '$components/renderer/Renderer'; import { Renderer } from '$components/renderer/Renderer';
import { hideRenderer } from '$redux/user/actions'; import { hideRenderer } from '$redux/user/actions';
import { Cursor } from '$components/Cursor';
type Props = { type Props = {
renderer_active: Boolean, renderer_active: Boolean,
hideRenderer: Function, hideRenderer: Function,
mode: String,
} }
const Component = (props: Props) => ( const Component = (props: Props) => (
@ -23,13 +25,16 @@ const Component = (props: Props) => (
<UserLocation /> <UserLocation />
<UserPanel /> <UserPanel />
<EditorPanel /> <EditorPanel />
<Cursor mode={props.mode} />
{ props.renderer_active && <Renderer onClick={props.hideRenderer} /> } { props.renderer_active && <Renderer onClick={props.hideRenderer} /> }
</div> </div>
); );
const mapStateToProps = ({ user }) => ({ const mapStateToProps = ({ user }) => ({
renderer_active: user.renderer.renderer_active renderer_active: user.renderer.renderer_active,
mode: user.mode,
}); });
const mapDispatchToProps = dispatch => bindActionCreators({ hideRenderer }, dispatch); const mapDispatchToProps = dispatch => bindActionCreators({ hideRenderer }, dispatch);
export const App = connect(mapStateToProps, mapDispatchToProps)(hot(module)(Component)); export const App = connect(mapStateToProps, mapDispatchToProps)(hot(module)(Component));

View file

@ -51,3 +51,20 @@ body {
.danger { .danger {
color: @color_danger; color: @color_danger;
} }
.cursor-tooltip {
position: fixed;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
z-index: 10;
pointer-events: none;
svg {
width: 20px;
height: 20px;
stroke-width: 4;
fill: @blue_secondary;
}
}