function processMapTemplate($mapId, $templateName) { global $db; $folderName = generateRandomString(16); $path = '../downloads/html-template/' . $folderName . '/'; $map = getMapById($mapId); if ($map) { $shapes = getShapesByMapId($mapId); $defaulLayer = getLayerById($map['layers_id']); $defaulLayer = "L.tileLayer('" . $defaulLayer['url'] . "', {maxZoom: 18, id: '" . $defaulLayer['lkey'] . "', token: '" . $defaulLayer['accesstoken'] . "', attribution: '" . $defaulLayer['attribution'] . "'+mbAttribution})"; $baseLayers = array(); $res = pg_query($db, "SELECT * FROM layers WHERE id IN (SELECT layers_id FROM groups_has_layers WHERE groups_id = " . (int) $map['groups_id'] . ")") or die("Database Error"); if (pg_num_rows($res) > 0) { while ($data = pg_fetch_assoc($res)) { $baseLayers[] = "'" . $data['name'] . "': L.tileLayer('" . $data['url'] . "', {maxZoom: 18, id: '" . $data['lkey'] . "', token: '" . $data['accesstoken'] . "', attribution: '" . $data['attribution'] . "'+mbAttribution})"; } } $baseLayers = implode(",", $baseLayers); //$content = file_get_contents('map/html-template/'.$templateName.'/index.html'); $content = file_get_contents('map/view.tpl'); $geoJSON = array("type" => "FeatureCollection", "features" => array()); if (is_array($shapes) && count($shapes) > 0) { $i = 0; foreach ($shapes as $shape) { $geoJSON['features'][$i] = array("type" => "Feature", "properties" => json_decode($shape['properties']), "geometry" => array("type" => $shape['type'], "coordinates" => json_decode($shape['coordinates'])), "style" => json_decode($shape['style']), "customProperties" => json_decode($shape['customproperties'])); $i++; } } else { $first_lat = 0; $first_lng = 0; } $map['mapcenter'] = str_replace(array("[", "]"), "", $map['mapcenter']); $match = explode(",", $map['mapcenter']); $first_lat = (double) $match[0]; $first_lng = (double) $match[1]; $jsonString = json_encode($geoJSON); $search = array('[#HEIGHT#]', '[#HEIGHT_UNIT#]', '[#WIDTH#]', '[#WIDTH_UNIT#]', '[#ZOOM#]', '[#SET_MARKER#]', '[#SHOW_SIDEBAR#]', '[#BUTTON_STYLE#]', '[#JSON_STRING#]', '[#LAT#]', '[#LNG#]', '[#BASEURL#]', '[#CDNURL#]', '[#MAIN_DOMAIN#]', '[#SITE_NAME_FORMATED#]', '[#DEFAULT_LAYER#]', '[#BASE_LAYERS_ARRAY#]', '[#FILTERED_COLUMNS#]', '[#CLUSTER#]', '[#OVERLAY_ENABLE#]', '[#OVERLAY_TITLE#]', '[#OVERLAY_BLURB#]', '[#OVERLAY_CONTENT#]', '[#LEGEND_ENABLE#]', '[#LEGEND_CONTENT#]', '[#IMAGE_OVERLAYS#]', '[#MAP_ID#]', '[#SHOW_EXPORT#]', '[#SHOW_MEASURE#]', '[#SHOW_MINIMAP#]', '[#SHOW_SEARCH#]', '[#SHOW_FILELAYER#]', '[#SHOW_PLAYBACK#]', '[#GPX_TRACKS#]', '[#SHOW_STATIC_SIDEBAR#]', '[#STATIC_SIDEBAR_CONTENT#]', '[#SHOW_SVG#]', '[#MAP_BOUNDS#]'); $replace = array('800', 'px', '100', '%', $map['zoom'], $map['defaultopen'] == 't' ? 'true' : 'false', $map['showsidebar'] == 't' ? 'true' : 'false', $map['button_style'], $jsonString, $first_lat, $first_lng, BASEURL, CDNURL, MAIN_DOMAIN, SITE_NAME_FORMATED, $defaulLayer, $baseLayers, $map['filteredcolumns'], $map['cluster'] == 't' ? 'true' : 'false', $map['overlay_enable'] == 't' ? 'true' : 'false', htmlentities($map['overlay_title']), htmlentities($map['overlay_blurb']), htmlentities($map['overlay_content']), $map['legend_enable'] == 't' ? 'true' : 'false', htmlentities($map['legend_content']), $map['image_overlays'], $map['id'], $map['show_export'] == 't' ? 'true' : 'false', $map['show_measure'] == 't' ? 'true' : 'false', $map['show_minimap'] == 't' ? 'true' : 'false', $map['show_search'] == 't' ? 'true' : 'false', $map['show_filelayer'] == 't' ? 'true' : 'false', $map['show_playback'] == 't' ? 'true' : 'false', $map['gpx_tracks'], $map['show_static_sidebar'] == 't' ? 'true' : 'false', $map['static_sidebar_content'], $map['show_svg'] == 't' ? 'true' : 'false', $map['map_bounds']); $map_content = str_replace($search, $replace, $content); /* it's whole compiled view.tpl */ $shell_out = shell_exec("mkdir " . $path . " 2>&1"); if ($shell_out == "") { shell_exec("cp -r map/html-template/{$templateName}/ {$path} 2>&1"); $content = file_get_contents($path . $templateName . "/index.html"); $content = str_replace("[#MAP_CONTENT#]", $map_content, $content); file_put_contents($path . $templateName . "/index.html", $content); shell_exec("\n\t\t\t\t\tcd {$path}\n\t\t\t\t\tzip -r {$templateName} {$templateName}/ 2>&1\n\t\t\t\t"); $zipFile = file_get_contents("{$path}{$templateName}.zip"); shell_exec("rm -r {$path}"); return $zipFile; } exit; } else { die("Map Not Found!"); } }
<a class="btn btn-info" href="http://docs.mapfig.com/" target="_blank" title="Launch Help Wizard"><i class="fa fa-question-circle"></i> Launch Help Wizard</a> </td> --> </tr> </tbody> </table> </div> <a id="map_settings_action" href="#"><i class="fa fa-angle-down" style="padding: 10px 2px 10px 17px;"></i>Map Settings</a> </div> <div class="col-lg-12" style="overflow: auto; margin-top: 50px;"> <?php global $db; $defaulLayer = getLayerById($map['layers_id']); $defaulLayer = "L.tileLayer('" . $defaulLayer['url'] . "', {maxZoom: 18, id: '" . $defaulLayer['lkey'] . "', token: '" . $defaulLayer['accesstoken'] . "', attribution: '" . $defaulLayer['attribution'] . "'+mbAttribution})"; $baseLayers = array(); $res = pg_query($db, "SELECT * FROM layers WHERE id IN (SELECT layers_id FROM groups_has_layers WHERE groups_id = " . (int) $map['groups_id'] . ")") or die("Database Error"); if (pg_num_rows($res) > 0) { while ($data = pg_fetch_assoc($res)) { $baseLayers[] = "'" . $data['name'] . "': L.tileLayer('" . $data['url'] . "', {maxZoom: 18, id: '" . $data['lkey'] . "', token: '" . $data['accesstoken'] . "', attribution: '" . $data['attribution'] . "'+mbAttribution})"; } } $baseLayers = implode(",", $baseLayers); $content = file_get_contents('map/preview.tpl'); $geoJSON = array("type" => "FeatureCollection", "features" => array()); if (is_array($shapes) && count($shapes) > 0) { $i = 0; foreach ($shapes as $shape) { $geoJSON['features'][$i] = array("type" => "Feature", "properties" => json_decode($shape['properties']), "geometry" => array("type" => $shape['type'], "coordinates" => json_decode($shape['coordinates'])), "style" => json_decode($shape['style']), "customProperties" => json_decode($shape['customproperties']));
} else { if ($name == "projects_id") { $value = (int) $value; if ((int) $value < 0) { $dontSave = true; } } } } } } } if ($error == "" || $dontSave) { updateMap($maps_id, $user['id'], $name, $value); if ($name == "layers_id") { $defaulLayer = getLayerById((int) $value); $defaulLayer = array('url' => $defaulLayer['url'], 'key' => $defaulLayer['lkey'], 'attribution' => $defaulLayer['attribution']); echo json_encode($defaulLayer); } else { if ($name == "groups_id") { global $db; $baseLayers = array(); $res = pg_query($db, "SELECT * FROM layers WHERE id IN (SELECT layers_id FROM groups_has_layers WHERE groups_id = " . (int) $value . ")") or die("Database Error"); if (pg_num_rows($res) > 0) { while ($data = pg_fetch_assoc($res)) { $baseLayers[] = array('name' => $data['name'], 'url' => $data['url'], 'key' => $data['lkey'], 'attribution' => $data['attribution']); } } echo json_encode($baseLayers); } }