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

Google Maps für Einsatzorte #114

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Code Climate improvements
  • Loading branch information
jhbriese committed Oct 6, 2017
commit dce28819b6bca6013aadfa3fc23d9923e56401ab
42 changes: 23 additions & 19 deletions src/Frontend/ReportList.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,19 @@ private function constructList($reports, $args)
$this->insertTableHeader();
}

if( $this->options->isGMapActivate() && $this->showMap) {
$latLon = explode(",", $this->options->getGMapDefaultPos() );
$mapstring = "<style>#map-canvas {height: 300px; margin-bottom: 30px; position: relative; overflow: hidden; transform: translateZ(0px); background-color: rgb(229, 227, 223);}</style>";
$mapstring .= "<div class='einsatzliste-map'>";
$mapstring .= "<div id='map-canvas'></div>";
$mapstring .= "</div>";
$mapstring .= "<div style='clear:both'></div>";
$mapstring .= "<script>";
$mapstring .= "google.maps.event.addDomListener(window, 'load', initializeMap(" . $latLon[0] . ", " . $latLon[1] . ", 10));";
$mapstring .= "</script>";
if ($this->options->isGMapActivate() && $this->showMap) {
$latLon = explode(",", $this->options->getGMapDefaultPos());
$mapstring = "<style>#map-canvas {height: 300px; margin-bottom: 30px; position: relative;";
$mapstring .= " overflow: hidden; transform: translateZ(0px); background-color: rgb(229, 227, 223);}";
$mapstring .= "</style>";
$mapstring .= "<div class='einsatzliste-map'>";
$mapstring .= "<div id='map-canvas'></div>";
$mapstring .= "</div>";
$mapstring .= "<div style='clear:both'></div>";
$mapstring .= "<script>";
$mapstring .= "google.maps.event.addDomListener(window, 'load', initializeMap(" . $latLon[0] . ", ";
$mapstring .= $latLon[1] . ", 10));";
$mapstring .= "</script>";

echo "$mapstring";
}
Expand Down Expand Up @@ -356,17 +359,18 @@ private function insertRow($report)
}
$this->string .= '</td>';
}
if( $this->options->isGMapActivate() && $this->showMap && $report->getGmapsLocation() != "") {
$latLon = explode(",", $report->getGmapsLocation());
$timeOfAlerting = $report->getTimeOfAlerting();
$infoContent = '<h1>' . get_the_title($report->getPostId()) . '</h1><p>' . $timeOfAlerting->format('d.m.Y H:i') . '</p><p>' . $report->getLocation() . '</p>';
$marker = '<script>';
$marker .= 'addMarker( ' . $latLon[0] . ', ' . $latLon[1] . ' , "' . $infoContent . '" )';
$marker .= '</script>';
$this->string .= $marker;
if ($this->options->isGMapActivate() && $this->showMap && $report->getGmapsLocation() != "") {
$latLon = explode(",", $report->getGmapsLocation());
$timeOfAlerting = $report->getTimeOfAlerting();
$infoContent = '<h1>' . get_the_title($report->getPostId()) . '</h1><p>';
$infoContent .= $timeOfAlerting->format('d.m.Y H:i') . '</p><p>';
$infoContent .= $report->getLocation() . '</p>';
$marker = '<script>';
$marker .= 'addMarker( ' . $latLon[0] . ', ' . $latLon[1] . ' , "' . $infoContent . '" )';
$marker .= '</script>';
$this->string .= $marker;
}
$this->string .= '</tr>';

}

/**
Expand Down
37 changes: 18 additions & 19 deletions src/einsatzverwaltung-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ public function enqueueEditScripts($hook)
Core::VERSION
);

if($this->options->isGMapActivate())
{
wp_enqueue_script( 'einsatzvw_GoogleMap' );
wp_enqueue_script(
'einsatzverwaltung-gmap',
$this->core->scriptUrl . 'einsatzverwaltung-gmaps.js'
);
if ($this->options->isGMapActivate()) {
wp_enqueue_script('einsatzvw_GoogleMap');
wp_enqueue_script(
'einsatzverwaltung-gmap',
$this->core->scriptUrl . 'einsatzverwaltung-gmaps.js'
);
}
}

Expand Down Expand Up @@ -237,8 +236,7 @@ public function displayMetaBoxEinsatzdetails($post)
esc_attr($einsatzort)
);

if($this->options->isGMapActivate())
{
if ($this->options->isGMapActivate()) {
$this->echoGMap($gmapslocation);
}

Expand Down Expand Up @@ -281,26 +279,27 @@ private function echoInputText($label, $name, $value, $placeholder = '', $size =
*/
private function echoGMap($location)
{
if(!empty($location ))
{
$latLon = explode(",",$location);
}
else
{
$latLon = explode(",",$this->options->getGMapDefaultPos());
if (!empty($location )) {
$latLon = explode(",", $location);
} else {
$latLon = explode(",", $this->options->getGMapDefaultPos());
}

echo '<tr><td>';
echo '<label for="einsatzverwaltung_location">Koordinate</label>';
echo '</td><td style="width: 100%;">';
echo '<input type="text" id="einsatzverwaltung_location" name="einsatzverwaltung_location" value="' . $location . '" size="20" readonly/>';
echo '<a class="button" id="einsatzverwaltung_get_location" onClick="geocodeAddress(document.getElementById(\'einsatzverwaltung_einsatzort\').value , \'einsatzverwaltung_location\')"><i class="fa fa-map-marker"></i></a>';
echo '<input type="text" id="einsatzverwaltung_location" name="einsatzverwaltung_location" value="';
echo $location . '" size="20" readonly/>';
echo '<a class="button" id="einsatzverwaltung_get_location"';
echo 'onClick="geocodeAddress(document.getElementById(\'einsatzverwaltung_einsatzort\').value ,';
echo ' \'einsatzverwaltung_location\')"><i class="fa fa-map-marker"></i></a>';
echo '</td></tr>';
echo '<tr><td colspan="2">';
echo '<div id="map-canvas" style="height: 400px;"></div>';
echo '</td></tr>';
echo '<script>';
echo ' google.maps.event.addDomListener(window, "load", initializeMap(' . $latLon[0] . ', ' . $latLon[1] . '));';
echo ' google.maps.event.addDomListener(window, "load", initializeMap(';
echo $latLon[0] . ', ' . $latLon[1] . '));';
echo '</script>';
}

Expand Down
10 changes: 5 additions & 5 deletions src/einsatzverwaltung-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function onDeactivation()
public function onInit()
{
$this->registerTypes();
$this->registerScripts();
$this->registerScripts();
$this->addRewriteRules();
if ($this->options->isFlushRewriteRules()) {
flush_rewrite_rules();
Expand Down Expand Up @@ -422,15 +422,15 @@ private function registerTypes()
*/
private function registerScripts()
{
if( $this->options->isGMapActivate() ) {
if ($this->options->isGMapActivate()) {
/* Google Maps */
$protocal = is_ssl() ? 'https://' : 'http:https://';
$url = add_query_arg( array(
$url = add_query_arg(array(
'key' => $this->options->getGMapAPI(),
), "{$protocal}maps.googleapis.com/maps/api/js");
wp_register_script( 'einsatzvw_GoogleMap', $url );
wp_register_script('einsatzvw_GoogleMap', $url);
}
}
}

private function addRewriteRules()
{
Expand Down
29 changes: 14 additions & 15 deletions src/einsatzverwaltung-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ public function enqueueStyleAndScripts()
);
wp_add_inline_style('einsatzverwaltung-frontend', ReportList::getDynamicCss());

if($this->options->isGMapActivate())
{
wp_enqueue_script( 'einsatzvw_GoogleMap' );
wp_enqueue_script(
'einsatzverwaltung-gmap',
$this->core->scriptUrl . 'einsatzverwaltung-gmaps.js'
);
if ($this->options->isGMapActivate()) {
wp_enqueue_script('einsatzvw_GoogleMap');
wp_enqueue_script(
'einsatzverwaltung-gmap',
$this->core->scriptUrl . 'einsatzverwaltung-gmaps.js'
);
}
}

Expand Down Expand Up @@ -175,17 +174,18 @@ public function getEinsatzberichtMap($post)
{
$report = new IncidentReport($post);
$location = $report->getGmapsLocation();
if($this->options->isGMapActivate() && $location)
{
$latLon = explode(",",$location);
if ($this->options->isGMapActivate() && $location) {
$latLon = explode(",", $location);

$mapstring = "<style>#map-canvas {height: 300px; position: relative; overflow: hidden; transform: translateZ(0px); background-color: rgb(229, 227, 223);}</style>";
$mapstring = "<style>#map-canvas {height: 300px; position: relative; overflow: hidden;";
$mapstring .= " transform: translateZ(0px); background-color: rgb(229, 227, 223);}</style>";
$mapstring .= "<div class='einsatzliste-map'>";
$mapstring .= "<div id='map-canvas'></div>";
$mapstring .= "</div>";
$mapstring .= "<div style='clear:both'></div>";
$mapstring .= "<script>";
$mapstring .= "google.maps.event.addDomListener(window, 'load', initializeMap(" . $latLon[0] . ", " . $latLon[1] . "));";
$mapstring .= "google.maps.event.addDomListener(window, 'load', initializeMap(";
$mapstring .= $latLon[0] . ", " . $latLon[1] . "));";
$mapstring .= "addMarker( " . $latLon[0] . ", " . $latLon[1] . ", '" . $report->getLocation() . "', true )";
$mapstring .= "</script>";

Expand Down Expand Up @@ -234,9 +234,8 @@ public function renderContent($content)
$header = $this->getEinsatzberichtHeader($post, true, true);
$content = $this->prepareContent($content);
$map = "";
if($this->options->isGMapActivate())
{
$map = $this->getEinsatzberichtMap($post);
if ($this->options->isGMapActivate()) {
$map = $this->getEinsatzberichtMap($post);
}

return $header . $map . '<hr>' . $content;
Expand Down
4 changes: 2 additions & 2 deletions src/einsatzverwaltung-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public function registerSettings()
register_setting(
'einsatzvw_settings',
'einsatzvw_gmap_default_pos'
);
);
register_setting(
'einsatzvw_settings',
'einsatzvw_list_annotations_color_off',
Expand Down Expand Up @@ -357,7 +357,7 @@ private function addSettingsFields()
array($this, 'echoSettingsGmap'),
self::EVW_SETTINGS_SLUG,
'einsatzvw_settings_einsatzberichte'
);
);
add_settings_field(
'einsatzvw_settings_columns',
'Spalten der Einsatzliste',
Expand Down