Commit 13670eae authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

set initial position and save to kml

parent f82317de
/*
*! -----------------------------------------------------------------------------**
*! FILE NAME : modify_kml.js
*! DESCRIPTION: Sends modified map data to the server
*! Copyright (C) 2011 Elphel, Inc.
*!
*! -----------------------------------------------------------------------------**
*!
*! This program is free software: you can redistribute it and/or modify
*! it under the terms of the GNU General Public License as published by
*! the Free Software Foundation, either version 3 of the License, or
*! (at your option) any later version.
*!
*! This program is distributed in the hope that it will be useful,
*! but WITHOUT ANY WARRANTY; without even the implied warranty of
*! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*! GNU General Public License for more details.
*!
*! You should have received a copy of the GNU General Public License
*! along with this program. If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*!
*/
function generateKML(nodes){
var return_string = "<kml xmlns='http://earth.google.com/kml/2.2'>\n<Document>\n";
for(var i in nodes) {
return_string += [
'<PhotoOverlay>',
' <name>'+nodes[i].name+'</name>',
' <description>'+nodes[i].description+'</description>',
' <visibility>'+(nodes[i].visibility?1:0)+'</visibility>',
' <Camera>',
' <longitude>'+nodes[i].longitude+'</longitude>',
' <latitude>'+nodes[i].latitude+'</latitude>',
' <altitude>'+nodes[i].altitude+'</altitude>',
' <heading>'+nodes[i].heading+'</heading>',
' <tilt>'+nodes[i].tilt+'</tilt>',
' <roll>'+nodes[i].roll+'</roll>',
' </Camera>',
' <Icon>',
' <href>'+nodes[i].href+'</href>',
' </Icon>'].join('\n');
if (typeof(nodes[i].v3d)!='undefined') {
return_string += [
' <ExtendedData>',
' <Visibility3d>'].join('\n');
for (var j in nodes[i].v3d) {
return_string +=
' <v3Range>';
if (typeof(nodes[i].v3d[j].from)!='undefined'){
return_string +=
' <from>'+nodes[i].v3d[j].from+'</from>';
}
if (typeof(nodes[i].v3d[j].to) !='undefined'){
return_string +=
' <to>'+ nodes[i].v3d[j].to+ '</to>';
}
return_string +=
' </v3Range>';
}
return_string += [
' </Visibility3d>',
' </ExtendedData>'].join('\n');
}
return_string += [
'',
'</PhotoOverlay>'].join('\n');
}
return_string +=
'\n</Document>\n</kml>';
return return_string;
}
function postKmlData(filename, xml) {
$.ajax({
url: "modify_kml.php?kml="+filename,
type: "POST",
dataType: "xml",
data: xml,
async:true,
complete: function(response){
//do nothing
},
contentType: "text/xml; charset=\"utf-8\""
});
}
\ No newline at end of file
......@@ -277,3 +277,34 @@ html, body, #x3d_wrapper {
bottom:2px;
}
/*button with icon*/
.ic{
width:27px;
height:27px;
padding:0px;
border:1px solid gray;
border-radius: 2px;
user-select:none;
cursor: pointer;
}
.ic:hover {
background-color: rgba(240,240,240,1);
}
.ic:active{
background-color: rgba(200,200,200,1);
}
.ic:focus {outline:0;}
/*icon*/
.icim{
margin:0px;
padding:0px;
width:25px;
height:25px;
user-select:none;
}
......@@ -58,7 +58,12 @@ var SETTINGS = {
'path' : "1487451413_967079",
'version': "v1",
'experimental': false,
'edit': false
'edit': false,
'files': {
'x3d':"",
'x3d_background':"",
'kml':"",
}
// 'kml' : "scene.kml"
}
......@@ -93,6 +98,10 @@ $(function(){
parseURL();
SETTINGS.files.x3d = SETTINGS.basepath+"/"+SETTINGS.path+"/"+SETTINGS.version+"/"+SETTINGS.path+".x3d";
SETTINGS.files.x3d_background = SETTINGS.basepath+"/"+SETTINGS.path+"/"+SETTINGS.version+"/"+SETTINGS.path+"-texture-bgnd-ext.jpeg"
SETTINGS.files.kml = SETTINGS.basepath+"/"+SETTINGS.path+"/"+SETTINGS.path+".kml";
title_init();
help_init();
menu_init();
......@@ -124,8 +133,8 @@ function light_init(){
var x3delement = $("#x3d_id").find("scene");
var model_url = SETTINGS.basepath+"/"+SETTINGS.path+"/"+SETTINGS.version+"/"+SETTINGS.path+".x3d";
var model_back_url = SETTINGS.basepath+"/"+SETTINGS.path+"/"+SETTINGS.version+"/"+SETTINGS.path+"-texture-bgnd-ext.jpeg";
var model_url = SETTINGS.files.x3d;
var model_back_url = SETTINGS.files.x3d_background;
var model = $([
'<group>',
......@@ -148,7 +157,7 @@ function light_init(){
x3delement.append(model);
$.ajax({
url: SETTINGS.basepath+"/"+SETTINGS.path+"/"+SETTINGS.path+".kml",
url: SETTINGS.files.kml,
success: function(response){
var longitude = parseFloat($(response).find("Camera").find("longitude").text());
......@@ -174,6 +183,21 @@ function light_init(){
fov: fov || 0,
});
// store kml
// this data changes only in leaflet's edit location mode
Data.camera.kml = {
latitude: latitude || 0,
longitude: longitude || 0,
altitude: altitude || 0,
heading: heading || 0,
tilt: tilt || 0,
roll: roll || 0,
name : $(response).find("name").text(),
description : $(response).find("Camera").find("description").text(),
visibility : $(response).find("visibility").text(),
href : $(response).find("Icon").find("href").text()
};
var element = document.getElementById('x3d_id');
Scene = new X3DOMObject(element,Data,{});
......@@ -227,6 +251,20 @@ function reset_to_initial_position(){
fov: fov || 0,
});
// store kml
Data.camera.kml = {
latitude: latitude || 0,
longitude: longitude || 0,
altitude: altitude || 0,
heading: heading || 0,
tilt: tilt || 0,
roll: roll || 0,
name : $(response).find("name").text(),
description : $(response).find("Camera").find("description").text(),
visibility : $(response).find("visibility").text(),
href : $(response).find("Icon").find("href").text()
};
Map.marker.setHeading(heading);
Map.marker.setBasePoint(new L.LatLng(latitude,longitude));
Map.marker._syncMeasureMarkersToBasePoint();
......@@ -237,6 +275,7 @@ function reset_to_initial_position(){
}
});
}
function map_resize_init(){
......@@ -636,6 +675,10 @@ function leaf_mousemove_lc(){
Data.camera.heading = Camera._heading*180/Math.PI;
Data.camera.latitude = Camera._latlng.lat;
Data.camera.longitude = Camera._latlng.lng;
Data.camera.kml.heading = Camera._heading*180/Math.PI;
Data.camera.kml.latitude = Camera._latlng.lat;
Data.camera.kml.longitude = Camera._latlng.lng;
//update initial location and heading
x3d_initial_camera_placement();
......
......@@ -94,6 +94,8 @@ function menu_init(){
reset_view_init();
align_init();
work_with_kml_init();
}
function crosshair_init(){
......@@ -144,3 +146,16 @@ function reset_view_init(){
}
function work_with_kml_init(){
$("#savekml").on('click',function(){
var output = generateKML([Data.camera.kml]);
postKmlData(SETTINGS.files.kml, output);
});
$("#restorekml").on('click',function(){
$("#reset_view").click();
});
}
<?php
/*
*! -----------------------------------------------------------------------------**
*! FILE NAME : modify_kml.php
*! REVISION : 1.0
*! DESCRIPTION: save changes to a file.
*! Copyright (C) 2011 Elphel, Inc.
*!
*! -----------------------------------------------------------------------------**
*! This program is free software: you can redistribute it and/or modify
*! it under the terms of the GNU General Public License as published by
*! the Free Software Foundation, either version 3 of the License, or
*! (at your option) any later version.
*!
*! This program is distributed in the hope that it will be useful,
*! but WITHOUT ANY WARRANTY; without even the implied warranty of
*! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*! GNU General Public License for more details.
*!
*! You should have received a copy of the GNU General Public License
*! along with this program. If not, see <http://www.gnu.org/licenses/>.
*!
*! It means that the program's users have the four essential freedoms:
*!
*! * The freedom to run the program, for any purpose (freedom 0).
*! * The freedom to study how the program works, and change it to make it do what you wish (freedom 1).
*! Access to the source code is a precondition for this.
*! * The freedom to redistribute copies so you can help your neighbor (freedom 2).
*! * The freedom to distribute copies of your modified versions to others (freedom 3).
*!
*! By doing this you can give the whole community a chance to benefit from your changes.
*! Access to the source code is a precondition for this.
*! -----------------------------------------------------------------------------**
*/
require_once("call_filter.php");
$target_filename = $_GET['kml'];
if (!is_file($target_filename)){
die("-1");
}else{
if (substr($target_filename,-4,4)!=".kml"){
die("-2");
}
}
$target_xml = simplexml_load_file($target_filename);
$changes_xml = simplexml_load_file('php://input');
$new_PhotoOverlay = $changes_xml->Document->PhotoOverlay;
$old_PhotoOverlay = $target_xml->Document->PhotoOverlay;
foreach ($new_PhotoOverlay as $new_node) {
foreach ($old_PhotoOverlay as $old_node) {
$old_str = "{$old_node->Icon->href}";
$new_str = "{$new_node->Icon->href}";
//if ("{$new_node->Icon->href}"=="{$old_node->Icon->href}") {
if (strstr($new_str,$old_str)!=false) {
$old_node->name = $new_node->name;
$old_node->description = $new_node->description;
$old_node->visibility = $new_node->visibility;
if (!isset($old_node->Camera)) $old_node->Camera= $new_node->Camera;
$old_node->Camera->latitude = $new_node->Camera->latitude;
$old_node->Camera->longitude = $new_node->Camera->longitude;
$old_node->Camera->altitude = $new_node->Camera->altitude;
$old_node->Camera->heading = $new_node->Camera->heading;
$old_node->Camera->tilt = $new_node->Camera->tilt;
$old_node->Camera->roll = $new_node->Camera->roll;
if (!isset($old_node->ExtendedData) && isset($old_node->ExtendedData)) $old_node->ExtendedData= $new_node->ExtendedData;
if (isset($new_node->ExtendedData->Visibility3d->v3Range)) {
$old_node->ExtendedData->Visibility3d = $new_node->ExtendedData->Visibility3d;
/*
for ($nr=0; $nr<$new_node->ExtendedData->Visibility3d->v3Range->count();$nr++) {
$old_node->ExtendedData->Visibility3d->v3Range[$nr]= $new_node->ExtendedData->Visibility3d->v3Range[$nr];
if (isset($new_node->ExtendedData->Visibility3d->v3Range[$nr]->from)) $old_node->ExtendedData->Visibility3d->v3Range[$nr]->from=$new_node->ExtendedData->Visibility3d->v3Range[$nr]->from;
if (isset($new_node->ExtendedData->Visibility3d->v3Range[$nr]->to))$old_node->ExtendedData->Visibility3d->v3Range[$nr]->to= $new_node->ExtendedData->Visibility3d->v3Range[$nr]->to;
}
*/
$nr=0;
foreach ($new_node->ExtendedData->Visibility3d->children() as $child) {
$old_node->ExtendedData->Visibility3d->v3Range[$nr]= $child;
if (isset($child->from)) $old_node->ExtendedData->Visibility3d->v3Range[$nr]->from=$child->from;
if (isset($child->to))$old_node->ExtendedData->Visibility3d->v3Range[$nr]->to= $child->to;
$nr++;
}
}
break;
}
}
}
file_put_contents($target_filename, $target_xml->asXML());
echo "ok";
?>
......@@ -39,6 +39,8 @@
<script type='text/javascript' src='js/ui_align.js'></script>
<script type='text/javascript' src='js/util_functions.js'></script>
<script type='text/javascript' src='js/kml.js'></script>
<!-- endbuild -->
</head>
......@@ -118,11 +120,23 @@
<tr>
<td>&nbsp;</td>
</tr>
<tr class='edit'>
<td>
Initial location and heading:
</td>
<td>
<button id='restorekml' class='ic donothide' title='restore'><img src='js/images/ic_file_download_black_48dp_1x.png' class='icim donothide'/></button>
<button id='savekml' class='ic donothide' title='save'><img src='js/images/ic_file_upload_black_48dp_1x.png' class='icim donothide'/></button>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr class='experimental'>
<td>
<button id='align_0' class='experimental donothide'>Align0</button>
<button id='align_1' class='experimental donothide'>Align1</button>
<button id='align_2' class='experimental donothide'>Align2</button>
<button id='align_0' class='donothide'>Align0</button>
<button id='align_1' class='donothide'>Align1</button>
<button id='align_2' class='donothide'>Align2</button>
</td>
</tr>
<tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment