Leaflet and Tangram conctenated into a single script file - gruntjs

I am trying to concat leaflet and tangram source codes into a single script file using grunt to include it in an api which I am trying to make based on both leaflet and tangram. If I include the leaflet and tangram js files using different script tags in the html, the code works perfectly. But If i concat them using grunt and use a single script file I get the following error:
ReferenceError: window is not defined
The example code which I tried to run is as follows:
var map = L.map('map').setView([12.96,77.58],14);
var layer = Tangram.leafletLayer({
scene: '../scene/scene.yaml',
});
layer.addTo(map);
var marker = L.marker([12.96,77.58]).addTo(map);
Any kind of help is very much appreciated. Thank you

The webworkers that tangram uses require tangram to be included on the page as 'tangram.min.js' or 'tangram.debug.js'
It looks like that will be fixed at some point soon, but for now you will have to include it seperately.

Related

Is it possible to interact with elements of the RStudio IDE itself using R code?

Is it possible to interact with the RStudio application using R code inside it? I mean interactions like opening a file in a card, creating a tab for a new unsaved file or changing some text inside an opened tab.
I know a very similar thing can be obtained by just simply creating a new text file or changing its content with R but this way it doesn't interact anyway with the RStudio app itself.
Some context: I was thinking of a tool that could automate inserting some reprexes / snippets of code which could work as a line of code that, when run from a file, replaces itself with a block of code or make a new unsaved file tab and put some code inside it. And yes, I know a very similar thing can be achieved other ways (e.g. simply copying the intended code block into the clipboard) but I'm curious and exploring the possibilities.
Thanks to the link provided by Konrad Rudolph I managed to find the answer myself.
There is a package called rstudioapi built into the RStudio that allows many different functionalities and doesn't require using plugins or addins.
All the features can be found in the official manual.
Opening a new unsaved file tab with some code in it can be obtained by running:
rstudioapi::documentNew(
"example code here",
type = "r",
position = rstudioapi::document_position(0, 0),
execute = FALSE
)
Inserting code can be easily done with insertText(text = "") which inserts text at the current position of the text cursor.
Changing one line into another can be obtained with the combination of getActiveDocumentContext(), which returns among others the document content and the selection range which is basically equivalent to the cursor position. Then the changing itself can be done with modifyRange() respectively to the cursor position and/or the document content.
That allows many possibilities including for example some smoother automation of the workflow.

How to see all the code from the Example on pub.dev/packages

When looking at the Examples in the pub.dev/packages, the code for some contained with one page, while the more advanced ones are not showing all the code. For example, in the firebase_auth package, the Example shows the main.dart file, while the most important code is probably at the other two imported files:
import './register_page.dart';
import './signin_page.dart';
My question - How do I see the two files?
Thanks, Gal.
You can use this package by call some function and use IDE to jump to definition for example command + click in VS code.
Or you can open library file in directory flutter_dir/.pub-cache/hosted/pub.dartlang.org/name_of_lib/lib

In R how can I find in which file is a function defined

when I develop a package I find myself trying to find in which file is a function defined.
Say I some R file (of a package my_package) I see
fun <- myFun(...)
{
# some stuff
test <- someOtherFunction(...)
}
Is there an easy way to find in which file the function someOtherFunction is defined ?
Something like findFunction(name='someOtherFunction', package='my_package')
If you are looking to open the file in Rstudio in a quicker way.
You can use the Rstudio Go to file/function... to open a file that contains a function. This is useful when you have custom function written in a file or navigating around the modules.
Scroll to the tab Code
Code --> Go to file/function...
and enter the function name to locate the file with that function and open it.
You can use the default shortcut provided Ctrl+. or alternatively using the Tools tab Modify Keyboard Shortcuts and set up something it Ctrl O.

How to generate vector tiles and how to display it in leaflet

My data consists of many elements and attibutes, so I can't send entire json to client-side because it's too slow reading and displaying data.
At this point I need to make tiles from data. I have worked with tippecanoe, and it's so good but it "only" generates *.mbtiles (vector data inside *.pbf), and Leaflet 1.0.2 can't work with this format, so I tried to extract into zoom folders z/x/y with mbutil, but it seems that resulted *.pbf tiles are not correct because I've tried with Mapbox gl js and doesn't work well.
So first question is:
someone know how can I generate *.pbf tiles correctly from geojson files? I've tried some of options showed here: awesome-vector-tiles
And someone know if there's some plugin for Leaflet 1.0.2 that can work with vector tiles in *.mbtiles, *.pbf or *.json?
I've tried with mapbox-gl-leaflet, vectorgrid and tangram.
Thank you very much for your help
You can serve Mapbox vector tiles from a Tippecanoe generated .mbtiles file using TileServer-GL. Using Docker makes this task even easier.
Assuming you have already generated a file called geo.mbtiles using Tippecanoe in your current directory:
docker run -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl geo.mbtiles
This will spin up a server, and it will give you an endpoint that serves .pbf vector tiles. These can be rendered with Mapbox GL, Leaflet.VectorGrid, etc.
You can use tippecanoe with the -e option to generate *.pbf files in the proper directory structure. See https://github.com/mapbox/tippecanoe#output-tileset
https://github.com/tangrams/tangram
Tangram: WebGL Maps for Vector Data
you can display vector tiles using this JS library with leaflet
Thanks

R - Execute a function in a file

There is a R file and there is a function getInfo() in it.
I want to run this function in that script file alone.
Is that possible ?
I know running the script command on the file and then running the function name will help.
But then it will also run the rest of stuffs from the script file which i dont want.
What is the best way out here
When you use source on a script file, all the code in that file will be loaded into the R session currently active. Any code that is not in a function, will be executed. I see two options:
Put the function in a seperate source file, or even a package if the number of functions grows.
Set a global R variable using option and retrieve its value in the file to be sourced using getOption, making the execution of the non-function code dependend on this option. This does require you to always set this option before sourcing the file, in any project you use it in.
I would go for option 1.

Resources