| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
 | import _ from 'lodash'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
export default class OlMap extends Component{
  constructor(props){
    super(props)
  }
  fetchApiURL(id){
    const origin = window.location.origin
    const path = window.location.pathname.split('/', 3).join('/')
    return origin + path + "/autocomplete_stop_areas/" + id + "/around?target_type=zdep"
  }
  componentDidUpdate(prevProps, prevState){
    if(prevProps.value.olMap.isOpened == false && this.props.value.olMap.isOpened == true){
      var source = new ol.source.Vector({
        format: new ol.format.GeoJSON(),
        url: this.fetchApiURL(this.props.value.stoparea_id)
      })
      var feature = new ol.Feature({
        geometry: new ol.geom.Point(ol.proj.fromLonLat([parseFloat(this.props.value.longitude), parseFloat(this.props.value.latitude)]))
      })
      var defaultStyles = new ol.style.Style({
        image: new ol.style.Circle(({
          radius: 4,
          fill: new ol.style.Fill({
            color: '#004d87'
          })
        }))
      })
      var selectedStyles = new ol.style.Style({
        image: new ol.style.Circle(({
          radius: 6,
          fill: new ol.style.Fill({
            color: '#da2f36'
          })
        }))
      })
      var centerLayer = new ol.layer.Vector({
        source: new ol.source.Vector({
          features: [feature]
        }),
        style: selectedStyles,
        zIndex: 2
      })
      var vectorLayer = new ol.layer.Vector({
        source: source,
        style: defaultStyles,
        zIndex: 1
      });
      var map = new ol.Map({
        target: 'stoppoint_map' + this.props.index,
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          }),
          vectorLayer,
          centerLayer
        ],
        controls: [ new ol.control.ScaleLine() ],
        interactions: ol.interaction.defaults({
          dragPan: false,
          doubleClickZoom: false,
          shiftDragZoom: false,
          mouseWheelZoom: false
        }),
        view: new ol.View({
          center: ol.proj.fromLonLat([parseFloat(this.props.value.longitude), parseFloat(this.props.value.latitude)]),
          zoom: 18
        })
      });
      // Selectable marker
      var select = new ol.interaction.Select({
        style: selectedStyles
      });
      map.addInteraction(select);
      select.on('select', function(e) {
        feature.setStyle(defaultStyles);
        centerLayer.setZIndex(0);
        if(e.selected.length != 0) {
          if(e.selected[0].getGeometry() == feature.getGeometry()) {
            if(e.selected[0].style_.image_.fill_.color_ != '#da2f36'){
              feature.setStyle(selectedStyles);
              centerLayer.setZIndex(2);
              e.preventDefault()
              return false
            }
          }
          let data = _.assign({}, e.selected[0].getProperties(), {geometry: undefined});
          this.props.onSelectMarker(this.props.index, data)
        } else {
          this.props.onUnselectMarker(this.props.index)
        }
      }, this);
    }
  }
  render() {
    if (this.props.value.olMap.isOpened) {
      return (
        <div className='map_container'>
          <div className='map_metas'>
            <p>
              <strong>{this.props.value.olMap.json.name}</strong>
            </p>
            <p>
              <strong>{I18n.t('routes.edit.map.stop_point_type')} : </strong>
              {this.props.value.olMap.json.area_type}
            </p>
            <p>
              <strong>{I18n.t('routes.edit.map.short_name')} : </strong>
              {this.props.value.olMap.json.short_name}
            </p>
            <p>
              <strong>{I18n.t('id_reflex')} : </strong>
              {this.props.value.olMap.json.user_objectid}
            </p>
            <p><strong>{I18n.t('routes.edit.map.coordinates')} : </strong></p>
            <p style={{paddingLeft: 10, marginTop: 0}}>
              <em>{I18n.t('routes.edit.map.proj')}.: </em>WSG84<br/>
              <em>{I18n.t('routes.edit.map.lat')}.: </em>{this.props.value.olMap.json.latitude} <br/>
              <em>{I18n.t('routes.edit.map.lon')}.: </em>{this.props.value.olMap.json.longitude}
            </p>
            <p>
              <strong>{I18n.t('routes.edit.map.postal_code')} : </strong>
              {this.props.value.olMap.json.zip_code}
            </p>
            <p>
              <strong>{I18n.t('routes.edit.map.city')} : </strong>
              {this.props.value.olMap.json.city_name}
            </p>
            <p>
              <strong>{I18n.t('routes.edit.map.comment')} : </strong>
              {this.props.value.olMap.json.comment}
            </p>
            {(this.props.value.stoparea_id != this.props.value.olMap.json.stoparea_id) &&(
              <div className='btn btn-outline-primary btn-sm'
                onClick= {() => {this.props.onUpdateViaOlMap(this.props.index, this.props.value.olMap.json)}}
              >{I18n.t('actions.select')}</div>
            )}
          </div>
            <div className='map_content'>
              <div id={"stoppoint_map" + this.props.index} className='map'></div>
            </div>
        </div>
      )
    } else {
      return false
    }
  }
}
OlMap.propTypes = {
}
 |