Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { create as createMarker } from "../lib/marker";
- export default class Map extends Component {
- constructor() {
- super(...arguments);
- this.markers = {};
- }
- componentWillReceiveProps(nextProps) {
- this.upsertMarker("car", nextProps["car"]);
- this.upsertMarker("pickup", nextProps["pickup"]);
- this.upsertMarker("dropoff", nextProps["dropoff"]);
- this.upsertMarker("extrastop", nextProps["extrastop"]);
- }
- upsertMarker(type, data) {
- if (data) {
- // Если данные – нужно показать маркер
- if (!this.markers[type]) {
- // Еще нет маркера на карте – создем его
- this.markers[type] = createMarker(type, data);
- this.markers[type].attach(map);
- } else {
- // Уже есть маркер на карте – обновляем его
- this.markers[type].setProps(data);
- }
- } else {
- // Данных нет, убираем его с карты и удаляем
- this.markers[type].detach();
- delete this.markers[type];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement