Skip to content

Commit

Permalink
TILES-3943 Add route case (#556)
Browse files Browse the repository at this point in the history
* TILES-3943 Add route case

* fix UML label

* Fix review

* fix remove project link

* fix review

* Update src/DGAttribution/src/DGAttribution.js

Co-authored-by: itanka9 <[email protected]>

* fix update

* Update src/DGAttribution/src/DGAttribution.js

Co-authored-by: Mstislav Zhivodkov <[email protected]>

* fix

* fix init link

Co-authored-by: Andrey Kuznecov <[email protected]>
Co-authored-by: itanka9 <[email protected]>
Co-authored-by: Mstislav Zhivodkov <[email protected]>
  • Loading branch information
4 people authored Dec 16, 2021
1 parent ce016b5 commit c9953d6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 40 deletions.
4 changes: 2 additions & 2 deletions config.main.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

"trafficLayerMinZoom": 10,
"trafficLayerUpdateInterval": 300000,

"openLink": "http://2gis.{domain}/{projectCode}/center/{center}/zoom/{zoom}/openLink=true",
"ppLink2gis": "{gislink}/directions/tab/{rsType}/points/{point}?m={center}%2F{zoom}&openLink=true",
"openLink2gis": "{gislink}/?m={center}%2F{zoom}&openLink=true",
"ppnotLink": "http://2gis.{domain}/{projectCode}/center/{center}/zoom/{zoom}/routeTab/rsType/{rsType}/to/{point}╎{name}",
"photosLink": "http://2gis.{domain}/photos/{id}",

Expand Down
3 changes: 2 additions & 1 deletion src/DGAttribution/lang/ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ DG.Control.Attribution.Dictionary.ar = {
license_agreement: 'إتفاقية ترخيص',
work_on: 'يعمل بتطبيق 2GIS',
work_on_with_osm: 'API 2GIS',
open_on: 'Open in 2GIS'
open_on: 'Open in 2GIS',
route_on: 'Route on 2GIS'
};
3 changes: 2 additions & 1 deletion src/DGAttribution/lang/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ DG.Control.Attribution.Dictionary.ru = {
license_agreement: 'Лицензионное соглашение',
work_on: 'Работает на API 2ГИС',
work_on_with_osm: 'API 2ГИС',
open_on: 'Открыть в 2ГИС'
open_on: 'Открыть в 2ГИС',
route_on: 'Доехать с 2ГИС'
};
12 changes: 2 additions & 10 deletions src/DGAttribution/skin/basic/less/dg-mapcopyright.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@
position: relative;
display: inline-block;
box-sizing: border-box;
text-align: center;
text-align: left;
text-decoration: none;
font-family: suisseintl;
line-height: 14px;
font-style: normal;
font-weight: 600;
font-size: 9px;
cursor: pointer;
transition: all .1s;
height: 22px;
min-width: 101px;

.no-touch &:hover {
transition: all .2s; /* @TODO: all? */
Expand Down Expand Up @@ -98,11 +98,3 @@
.dg-attribution__open2gis-button_name_open:before {
.notRepeatableBgWithSizes('DGAttribution_pin');
}

@font-face {
font-family: suisseintl;
src: url(/fonts/SuisseIntl-SemiBold.ttf) format('truetype');
font-display: swap;
font-weight: 600;
font-style: normal;
}
103 changes: 78 additions & 25 deletions src/DGAttribution/src/DGAttribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,42 @@ DG.Control.Attribution.include({
copyright_logo: 'http://info.2gis.ru/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_apilink: 'http://api.2gis.ru/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_license: 'http://law.2gis.ru/api-rules/',
open_link: 'http://2gis.ru',
},

it: {
copyright_logo: 'http://2gis.it/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_apilink: 'http://2gis.it/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_license: 'http://law.2gis.it/licensing-agreement/'
copyright_license: 'http://law.2gis.it/licensing-agreement/',
open_link: 'http://2gis.ru',
},

cz: {
copyright_logo: 'http://praha.2gis.cz/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_apilink: 'http://praha.2gis.cz/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_license: 'http://law.2gis.cz/api-rules/'
copyright_license: 'http://law.2gis.cz/api-rules/',
open_link: 'http://2gis.ru',
},

cl: {
copyright_logo: 'http://santiago.2gis.cl/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_apilink: 'http://santiago.2gis.cl/?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_license: 'http://law.2gis.cl/api-rules/'
copyright_license: 'http://law.2gis.cl/api-rules/',
open_link: 'http://2gis.ru',
},

cy: {
copyright_logo: 'http://info.2gis.com.cy/lemesos?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_apilink: 'http://info.2gis.com.cy/lemesos?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_license: 'http://law.2gis.com.cy/api-rules/'
copyright_license: 'http://law.2gis.com.cy/api-rules/',
open_link: 'http://2gis.ru',
},

ae: {
copyright_logo: 'http://info.2gis.ae/dubai?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_apilink: 'http://info.2gis.ae/dubai?utm_source=copyright&utm_medium=map&utm_campaign=partners',
copyright_license: 'http://law.2gis.ae/api-rules/',
open_link: 'http://2gis.ae',
}
};
/* eslint-enable camelcase */
Expand All @@ -51,12 +57,51 @@ DG.Control.Attribution.include({
return dictionary[countryCode][linkType];
},

_markerToRoute: undefined,
_markers: [],

_checkMarkerLayers: function() {
this._markerToRoute = this._markers.length != 1 ? undefined : this._markers[0];
this._update();
},

_mapEvents: {

layeradd: function(e) {
if (e.layer instanceof DG.Marker) {
this._markers.push(e.layer)
if (this._markers.length <= 2) {
this._checkMarkerLayers();
}
}
},

layerremove: function(e) {
if (e.layer instanceof DG.Marker) {
var currentMarkers = [];
for (var i = 0; i < this._markers.length; i++) {
if (this._markers[i] !== e.layer) {
currentMarkers.push(this._markers[i])
}
}
this._markers = currentMarkers;
if (this._markers.length <= 1) {
this._checkMarkerLayers();
}
}
},

},

onAdd: function(map) {
if (!map._copyright) {
map._copyright = true;
this._first = true;
}
this._logotype = map.options.logotype;
this._open2gis = this._getLink('open_link')

this._map.on(this._mapEvents, this);

map.attributionControl = this;
this._container = DG.DomUtil.create('div', 'dg-attribution');
Expand All @@ -70,22 +115,21 @@ DG.Control.Attribution.include({

this._update();

var self = this;
DG.DomEvent
.on(this._container, 'touchstart', function(e) {
if (e.target.href === self._open2gis) {
self._open2gis = self._getOpenUrl();
e.target.href = self._open2gis
}
})
.on(this._container, 'touchstart', this._updateLink, this)
return this._container;
},

_updateLink: function(e) {
if (e.target.name === 'linkButton') {
this._open2gis = this._getOpenUrl();
e.target.href = this._open2gis;
}
},

_update: function(lang, osm, countryCode) {
if (!this._map) { return; }

this._open2gis = this._getOpenUrl();

if (typeof osm !== 'undefined') {
this._osm = osm;
}
Expand Down Expand Up @@ -119,17 +163,21 @@ DG.Control.Attribution.include({
this._container.innerHTML = copyright + prefixAndAttribs.join(' | ');

},


_getOpenUrl: function() {
if (!this._map.projectDetector) {
return '';
}
var project = this._map.projectDetector.getProject();
if (!project) {
return '';
if (this._markerToRoute) {
return DG.Util.template(DG.config.ppLink2gis, {
'gislink': this._getLink('open_link'),
'center': this._map.getCenter().lng + ',' + this._map.getCenter().lat,
'zoom': this._map.getZoom(),
'rsType': this._map.getZoom() > 11 ? 'bus' : 'car',
'point': this._markerToRoute._latlng.lng + ',' + this._markerToRoute._latlng.lat
});
}
return DG.Util.template(DG.config.openLink, {
'domain': project.domain,
'projectCode': project.code,

return DG.Util.template(DG.config.openLink2gis, {
'gislink': this._getLink('open_link'),
'center': this._map.getCenter().lng + ',' + this._map.getCenter().lat,
'zoom': this._map.getZoom(),
});
Expand All @@ -139,18 +187,23 @@ DG.Control.Attribution.include({
var btn =
{
name: 'open',
label: this.t('open_on'),
label: this._markerToRoute ? this.t('route_on') : this.t('open_on'),
}

// Do not show link button if button don't have translate to current language or map options logotype set true
var isHideButton = btn.label == 'open_on' || btn.label == 'route_on' || this._logotype;

return {
'osm': this._osm,
'logotype': this.t('open_on') == 'open_on' || this._logotype,
'logotype': isHideButton,
'work_on': this.t('work_on'),
'work_on_with_osm': this.t('work_on_with_osm'),
'lang': lang,
'copyright_apilink': this._getLink('copyright_apilink'),
'copyright_license': this._getLink('copyright_license'),
'copyright_logo': this._getLink('copyright_logo'),
'open2gis_link': this._open2gis,
'open2gis_name': 'linkButton',
'license_agreement': this.t('license_agreement'),
'dir': lang !== 'ar' ? 'ltr' : 'rtl',
'btn': btn
Expand All @@ -168,4 +221,4 @@ DG.Map.addInitHook(function() {
if (!this._copyright) {
DG.control.attribution().addTo(this);
}
});
});
2 changes: 1 addition & 1 deletion src/DGAttribution/templates/copyright.dust
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="dg-attribution__button-wrapper">
<a class="dg-attribution__open2gis-button_name_{name} dg-attribution__open2gis-button dg-attribution__open2gis-icon-button"
{?open2gis_link}
href={open2gis_link} target="_blank"
href={open2gis_link} target="_blank" name={open2gis_name}
{:else}
href="javascript:void(0)"
{/open2gis_link}
Expand Down

0 comments on commit c9953d6

Please sign in to comment.