Skip to content

Commit

Permalink
feat(control): add marker
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Aug 9, 2019
1 parent 45ec241 commit 39e870a
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 13 deletions.
6 changes: 3 additions & 3 deletions demos/hz.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
zIndex: 2
})
.source(data)
.size(2)
.size(1)
.color('#ff893a')
.animate({
enable:false,
enable:true,
interval:0.2,
duration:5,
trailLength:0.1
trailLength:0.2
})
.render();
});
Expand Down
15 changes: 11 additions & 4 deletions demos/taxi.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@
maxZoom: 18
});
scene.on('loaded', () => {
$.get('https://gw.alipayobjects.com/os/rmsportal/kNDVHmyUWAKhWmWXmjxM.json', data => {
$.get('https://gw.alipayobjects.com/os/basement_prod/40ef2173-df66-4154-a8c0-785e93a5f18e.json', data => {
scene.LineLayer({
zIndex: 2
})
.source(data)
//.color('#F08D41')
.size([2, 0])
.shape('line')
.color('#ff893a')
.animate({enable:true})
//.render();
.animate({
enable:true,
interval:0.2,
duration:5,
trailLength:0.1
})
.render();
});

$.get('https://gw.alipayobjects.com/os/rmsportal/vmvAxgsEwbpoSWbSYvix.json', data => {
buildLayer = scene.PolygonLayer({
zIndex: 2
Expand Down
5 changes: 5 additions & 0 deletions demos/vector2.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
"标注": layer3,
};
const layerContr = new L7.Control.Layers({overlayers}).addTo(scene);
const popup = new L7.Popup({anchor:'left'}).setText('hello world')
const marker = new L7.Marker({color:'red'})
.setLnglat([104.838088,34.075889 ])
.setPopup(popup)
.addTo(scene);

});

Expand Down
145 changes: 145 additions & 0 deletions src/component/css/l7.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
.l7-marker {
position: absolute;
top: 0;
left: 0;
z-index: 5;
}
.l7-popup-anchor-top,
.l7-popup-anchor-top-left,
.l7-popup-anchor-top-right {
-webkit-flex-direction: column;
flex-direction: column;
}

.l7-popup-anchor-bottom,
.l7-popup-anchor-bottom-left,
.l7-popup-anchor-bottom-right {
-webkit-flex-direction: column-reverse;
flex-direction: column-reverse;
}

.l7-popup-anchor-left {
-webkit-flex-direction: row;
flex-direction: row;
}

.l7-popup-anchor-right {
-webkit-flex-direction: row-reverse;
flex-direction: row-reverse;
}
.l7-popup {
position: absolute;
top: 0;
Expand All @@ -14,6 +43,122 @@
border: 10px solid transparent;
z-index: 1;
}
.l7-popup-anchor-top .l7-popup-tip {
-webkit-align-self: center;
align-self: center;
border-top: none;
border-bottom-color: #fff;
}

.l7-popup-anchor-top-left .l7-popup-tip {
-webkit-align-self: flex-start;
align-self: flex-start;
border-top: none;
border-left: none;
border-bottom-color: #fff;
}

.l7-popup-anchor-top-right .l7-popup-tip {
-webkit-align-self: flex-end;
align-self: flex-end;
border-top: none;
border-right: none;
border-bottom-color: #fff;
}

.l7-popup-anchor-bottom .l7-popup-tip {
-webkit-align-self: center;
align-self: center;
border-bottom: none;
border-top-color: #fff;
}

.l7-popup-anchor-bottom-left .l7-popup-tip {
-webkit-align-self: flex-start;
align-self: flex-start;
border-bottom: none;
border-left: none;
border-top-color: #fff;
}

.l7-popup-anchor-bottom-right .l7-popup-tip {
-webkit-align-self: flex-end;
align-self: flex-end;
border-bottom: none;
border-right: none;
border-top-color: #fff;
}

.l7-popup-anchor-left .l7-popup-tip {
-webkit-align-self: center;
align-self: center;
border-left: none;
border-right-color: #fff;
}

.l7-popup-anchor-right .l7-popup-tip {
-webkit-align-self: center;
align-self: center;
border-right: none;
border-left-color: #fff;
}

.l7-popup-close-button {
position: absolute;
right: 0;
top: 0;
border: 0;
border-radius: 0 3px 0 0;
cursor: pointer;
background-color: transparent;
}

.l7-popup-close-button:hover {
background-color: rgba(0, 0, 0, 0.05);
}

.l7-popup-content {
position: relative;
background: #fff;
border-radius: 3px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
padding: 10px 10px 15px;
pointer-events: auto;
}

.l7-popup-anchor-top-left .l7-popup-content {
border-top-left-radius: 0;
}

.l7-popup-anchor-top-right .l7-popup-content {
border-top-right-radius: 0;
}

.l7-popup-anchor-bottom-left .l7-popup-content {
border-bottom-left-radius: 0;
}

.l7-popup-anchor-bottom-right .l7-popup-content {
border-bottom-right-radius: 0;
}

.l7-popup-track-pointer {
display: none;
}

.l7-popup-track-pointer * {
pointer-events: none;
user-select: none;
}

.l7-map:hover .l7-popup-track-pointer {
display: flex;
}

.l7-map:active .l7-popup-track-pointer {
display: none;
}

.l7-popup-close-button {
position: absolute;
right: 0;
Expand Down
146 changes: 146 additions & 0 deletions src/component/marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import Base from '../core/base';
import { bindAll } from '../util/event';
import { applyAnchorClass, anchorTranslate } from '../util/anchor';
import * as DOM from '../util/dom';
export default class Marker extends Base {
constructor(cfg) {
super({
element: '', // DOM element
anchor: 'center',
offset: [ 0, 0 ],
color: '#2f54eb',
draggable: false,
...cfg

});
bindAll([
'_update',
'_onMove',
'_onUp',
'_addDragHandler',
'_onMapClick'
], this);
this._init();
}
_init() {
let element = this.get('element');
if (!element) {
this._defaultMarker = true;
element = DOM.create('div');
this.set('element', element);
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttributeNS(null, 'display', 'block');
svg.setAttributeNS(null, 'height', '48px');
svg.setAttributeNS(null, 'width', '48px');
svg.setAttributeNS(null, 'viewBox', '0 0 1024 1024');

const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttributeNS(null, 'd', 'M512 490.666667C453.12 490.666667 405.333333 442.88 405.333333 384 405.333333 325.12 453.12 277.333333 512 277.333333 570.88 277.333333 618.666667 325.12 618.666667 384 618.666667 442.88 570.88 490.666667 512 490.666667M512 85.333333C346.88 85.333333 213.333333 218.88 213.333333 384 213.333333 608 512 938.666667 512 938.666667 512 938.666667 810.666667 608 810.666667 384 810.666667 218.88 677.12 85.333333 512 85.333333Z');
path.setAttributeNS(null, 'fill', this.get('color'));
svg.appendChild(path);
element.appendChild(svg);

}
DOM.addClass(element, 'l7-marker');
element.addEventListener('dragstart', e => {
e.preventDefault();
});
element.addEventListener('click', e => {
e.preventDefault();
this._onMapClick();
});
applyAnchorClass(element, this.get('anchor'), 'marker');

this._popup = null;

}
addTo(scene) {
this.remove();
this._scene = scene;
this._scene.getContainer().appendChild(this.get('element'));
this._scene.on('camerachange', this._update);
this.setDraggable(this.get('draggable'));
this._update();
// this._scene.on('click', this._onMapClick);
return this;
}

remove() {
if (this._scene) {
this._scene.off('click', this._onMapClick);
this._scene.off('move', this._update);
this._scene.off('moveend', this._update);
this._scene.off('mousedown', this._addDragHandler);
this._scene.off('touchstart', this._addDragHandler);
this._scene.off('mouseup', this._onUp);
this._scene.off('touchend', this._onUp);
delete this._scene;
}
DOM.remove(this.get('element'));
if (this._popup) this._popup.remove();
return this;
}
setLnglat(lngLat) {
this._lngLat = lngLat;
if (this._popup) this._popup.setLnglat(this._lngLat);
return this;
}
getLngLat() {
return this._lngLat;
}

getElement() {
return this.get('element');
}

setPopup(popup) {
this._popup = popup;
if (this._lngLat) this._popup.setLnglat(this._lngLat);
return this;
}

togglePopup() {
const popup = this._popup;
if (!popup) return this;
else if (popup.isOpen()) popup.remove();
else popup.addTo(this._scene);
return this;
}

getPopup() {
return this._popup;
}

getOffset() {

}

setDraggable() {

}

isDraggable() {
return this._draggable;
}
_update() {
if (!this._scene) return;
this._updatePosition();
DOM.setTransform(this.get('element'), `${anchorTranslate[ this.get('anchor')]}`);

}
_onMapClick() {
this._scene.emit('click'); // 触发map点击事件,关闭其他popup
const element = this.get('element');

if (this._popup && element) {
this.togglePopup();
}
}
_updatePosition() {
if (!this._scene) { return; }
const pos = this._pos = this._scene.lngLatToContainer(this._lngLat);
this.get('element').style.left = pos.x + 'px';
this.get('element').style.top = pos.y + 'px';

}
}
Loading

0 comments on commit 39e870a

Please sign in to comment.