Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds target control #301

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/helpers/gtt_map_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def map_tag(map: nil, layers: map&.layers,
data[:popup] = popup if popup
data[:upload] = upload
data[:collapsed] = collapsed if collapsed
data[:geocoding] = true if Setting.plugin_redmine_gtt['enable_geocoding_on_map'] == 'true'
data[:target] = true if Setting.plugin_redmine_gtt['default_target_enabled'] == 'true'

uid = "ol-" + rand(36**8).to_s(36)

Expand Down
6 changes: 6 additions & 0 deletions app/views/settings/gtt/_general.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@settings['default_map_fit_maxzoom_level'],
:size => 10) %>
</p>

</div>

<div class="box tabular settings">
Expand All @@ -66,6 +67,11 @@
<div class="box tabular settings">
<h3><%= l(:select_other_gtt_settings) %></h3>

<p>
<%= content_tag(:label, l(:label_default_target_enabled)) %>
<%= check_box_tag 'settings[default_target_enabled]', true, @settings[:default_target_enabled] %>
</p>

<p>
<%= content_tag(:label, l(:label_hide_map_for_invalid_geom)) %>
<%= check_box_tag 'settings[hide_map_for_invalid_geom]', 1, Setting.plugin_redmine_gtt['hide_map_for_invalid_geom'] %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ de:
label_enable_geojson_upload_on_issue_map: Aktivieren von GeoJSON-Upload auf der
Themenkarte
label_enable_geocoding_on_map: Geokodierung auf der Karte aktivieren
label_default_target_enabled: "Show target on map center"
select_default_status_color: 'Auswahl der Standard-Statusfarbe:'
select_default_map_settings: 'Standardmäßige Kartenvoreinstellungen festlegen:'
select_edit_geometry_settings: 'Einstellungen für die Geometriebearbeitung:'
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ en:
label_editable_geometry_types_on_issue_map: "Editable geometry types on issue map"
label_enable_geojson_upload_on_issue_map: "Enable GeoJSON upload on issue map"
label_enable_geocoding_on_map: "Enable geocoding on map"
label_default_target_enabled: "Show target on map center"

select_other_gtt_settings: "Other GTT settings"
label_hide_map_for_invalid_geom: "Hide issue map for invalid geometry"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ja:
label_editable_geometry_types_on_issue_map: "チケット地図上で編集可能なジオメトリ種別"
label_enable_geojson_upload_on_issue_map: "チケット地図上でGeoJSONアップロードを有効化"
label_enable_geocoding_on_map: "地図上でジオコーディングを有効化"
label_default_target_enabled: "Show target on map center"

select_other_gtt_settings: "GTTのその他の設定"
label_hide_map_for_invalid_geom: "位置情報が登録されていない時に地図を隠す"
Expand Down
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'default_map_maxzoom_level' => 19,
'default_map_fit_maxzoom_level' => 17,
'vector_minzoom_level' => 0,
'default_target_enabled' => false,
'default_geocoder_options' => '{}',
'editable_geometry_types_on_issue_map' => ["Point"],
'enable_geojson_upload_on_issue_map' => false,
Expand Down
31 changes: 31 additions & 0 deletions src/components/gtt-client/init/controls.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { FullScreen, Rotate } from 'ol/control';
import { Style, RegularShape, Stroke } from 'ol/style';
import Bar from 'ol-ext/control/Bar';
import Button from 'ol-ext/control/Button';
import LayerPopup from 'ol-ext/control/LayerPopup';
import LayerSwitcher from 'ol-ext/control/LayerSwitcher';
import Target from 'ol-ext/control/Target';
import Notification from 'ol-ext/control/Notification';
import { position } from 'ol-ext/control/control';

Expand Down Expand Up @@ -124,6 +126,34 @@ function addLayerSwitcherOrPopup(instance: any): void {
}
}

/**
* Adds target control to instance map.
* @param instance
*/
function addTargetControl(instance: any): void {
if (instance.contents.target) {
// Adjust the radius and stroke width for high DPI devices
const pixelRatio = window.devicePixelRatio || 1;
const adjustedRadius = 11 / pixelRatio;
const adjustedStrokeWidth = 3 / pixelRatio;

instance.map.addControl(new Target({
composite: 'overlay',
style: new Style({
image: new RegularShape({
points: 4,
radius: adjustedRadius,
radius2: 0,
stroke: new Stroke({
color: 'rgba(220,26,26,0.7)',
width: adjustedStrokeWidth
})
})
}),
}));
}
}

/**
* Adds notification control
* @param {any} instance
Expand All @@ -146,6 +176,7 @@ export function initControls(this: any): void {
addFullScreenAndRotateControls(this);
addMaximizeControl(this);
handleMapRotation(this);
addTargetControl(this);

if (this.contents.edit) {
setControls.call(this, this.contents.edit.split(' '));
Expand Down
Loading