Skip to content

Commit 13e25b4

Browse files
authored
Merge pull request #175 from contactashish13/issue-174-1
add maps key setting in the geomap type #174
2 parents 8e53b0d + 4876f86 commit 13e25b4

File tree

5 files changed

+110
-75
lines changed

5 files changed

+110
-75
lines changed

classes/Visualizer/Module/Chart.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ public function renderChartPages() {
258258
* Handle data and settings page
259259
*/
260260
private function _handleDataAndSettingsPage() {
261+
if ( isset( $_POST['map_api_key'] ) ) {
262+
update_option( 'visualizer-map-api-key', $_POST['map_api_key'] );
263+
}
261264
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) {
262265
if ( $this->_chart->post_status == 'auto-draft' ) {
263266
$this->_chart->post_status = 'publish';
@@ -297,6 +300,7 @@ private function _handleDataAndSettingsPage() {
297300
'charts' => array(
298301
'canvas' => $data,
299302
),
303+
'map_api_key' => get_option( 'visualizer-map-api-key' ),
300304
) );
301305
$render = new Visualizer_Render_Page_Data();
302306
$render->chart = $this->_chart;
@@ -421,7 +425,9 @@ public function uploadData() {
421425
}
422426
}
423427
$render->render();
424-
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
428+
if ( ! ( defined( 'VISUALIZER_DO_NOT_DIE' ) && VISUALIZER_DO_NOT_DIE ) ) {
429+
defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit();
430+
}
425431
}
426432

427433
/**

classes/Visualizer/Module/Frontend.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public function renderChart( $atts ) {
152152
// enqueue visualizer render and update render localizations
153153
wp_enqueue_script( 'visualizer-render' );
154154
wp_localize_script( 'visualizer-render', 'visualizer', array(
155-
'charts' => $this->_charts,
155+
'charts' => $this->_charts,
156+
'map_api_key' => get_option( 'visualizer-map-api-key' ),
156157
) );
157158

158159
// return placeholder div

classes/Visualizer/Render/Sidebar/Type/Geo.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ protected function _toHTML() {
5454
*/
5555
protected function _renderMapSettings() {
5656
self::_renderGroupStart( esc_html__( 'Map Settings', 'visualizer' ) );
57+
58+
self::_renderSectionStart( esc_html__( 'API', 'visualizer' ), false );
59+
self::_renderSectionDescription(
60+
sprintf( esc_html__( 'Add the Google Maps API key (Click %1$shere%2$s to get the key)', 'visualizer' ), '<a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">', '</a>' )
61+
);
62+
63+
self::_renderTextItem(
64+
esc_html__( 'API Key', 'visualizer' ),
65+
'map_api_key',
66+
get_option( 'visualizer-map-api-key' ),
67+
'',
68+
''
69+
);
70+
71+
self::_renderSectionEnd();
72+
5773
self::_renderSectionStart( esc_html__( 'Region', 'visualizer' ), false );
5874
self::_renderSectionDescription(
5975
esc_html__( 'Configure the region area to display on the map. (Surrounding areas will be displayed as well.) Can be one of the following:' , 'visualizer' ) .

js/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
}
201201
};
202202

203-
g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"]});
203+
g.charts.load("current", {packages: ["corechart", "geochart", "gauge", "table", "timeline"], mapsApiKey: v.map_api_key});
204204
g.charts.setOnLoadCallback(function() {
205205
gv = g.visualization;
206206
v.render();

0 commit comments

Comments
 (0)