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 (
{this.props.value.olMap.json.name}
{I18n.t('routes.edit.map.stop_point_type')} : {this.props.value.olMap.json.area_type}
{I18n.t('routes.edit.map.short_name')} : {this.props.value.olMap.json.short_name}
{I18n.t('id_reflex')} : {this.props.value.olMap.json.user_objectid}
{I18n.t('routes.edit.map.coordinates')} :
              {I18n.t('routes.edit.map.proj')}.: WSG84
              {I18n.t('routes.edit.map.lat')}.: {this.props.value.olMap.json.latitude} 
              {I18n.t('routes.edit.map.lon')}.: {this.props.value.olMap.json.longitude}
            
{I18n.t('routes.edit.map.postal_code')} : {this.props.value.olMap.json.zip_code}
{I18n.t('routes.edit.map.city')} : {this.props.value.olMap.json.city_name}
{I18n.t('routes.edit.map.comment')} : {this.props.value.olMap.json.comment}
{(this.props.value.stoparea_id != this.props.value.olMap.json.stoparea_id) &&(