Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
emptymap.js
Advanced tools
A module that helps in navigation of map like pan, zoom and rotation but does nothing itself.
A module that help in navigation of map like pan, zoom and rotation but does nothing itself.
emptymap.js takes advantage of CSS/SVG transform property. If you render your geojson data (spatial data) on HTML page in form of SVG then this module can easily help in pan, zoom and rotate the SVG map. On SVG drag, pinch and rotate this module calculate the transformation matrix value to be applied to SVG to take effect of the events. The module also calculate the transformation matrix for div that contains map tiles as img tag.
npm install emptymap.js
To initiate the instance we need to pass the map SVG/div size and projection extent. In case of spherical (web) mercator projection no need to pass the extent as this is default projection.
var EmptyMap = require('emptymap.js');
size = {width: 714, height: 400},
view = {
"center":[-9655821.34064295,4238014.557249293],
"zoom":4,
"rotation":-15
},
em;
em = new EmptyMap(size);
//set the initial view
em.setView({
view: veiw,
callback: function(err,result) {
if(err) {
console.log(err);
return;
}
//get SVG map layer (where id='svgmap')
var svgLayer = document.getElemetnById('svgmap');
svgLayer.setAttribute('transform', 'matrix('+result.matrix.join(', ')+')');
//get map tile layer (where id='tilemap')
var tileLayer = document.getElementById('tilemap');
tileLayer.style.transform = 'matrix('+ result.tileMatrix.join(',') + ')';
// and of course you need to load the tiles for this rotated view
}
});
// now lets pinch and rotate the map
em.applyDeltaScaleRotation({
position: [300, 200],
rotation: 30, // in degree clock wise positive
factor: 2, // scale (pinch) factor
callback: function(err,result) {
if(err) {
console.log(err);
return;
}
//get SVG map layer (where id='svgmap')
var svgLayer = document.getElemetnById('svgmap');
svgLayer.setAttribute('transform', 'matrix('+result.matrix.join(', ')+')');
//get map tile layer (where id='tilemap')
var tileLayer = document.getElementById('tilemap');
tileLayer.style.transform = 'matrix('+ result.tileMatrix.join(',') + ')';
// and of course you need to load the tiles for this rotated view
}
});
#####constructor(viewportSize [,options])
Creates emptymap.js instance with maps div's viewportSize
and other otpions
viewportSize
is object with maps div width and height in pixel
{
width: number
height: number
}
options:
different options are as follows:
projExtent
projection extents default spherical mercator extent
projExt: {
left: number
right: number
bottom: number
top: number
}
tileSize
i.e. whole projection extent should fit into one square tile, default is 256
view
object with center, zoom/resolution and rotation
view: {
cneter: [x,y], // default [0,0]
zoom: integer, // default is 0
resolution: numbe, // zoom takes precedence over resolution
// if both are present
rotation: number, // in degree default is 0
}
callback
function that should accept error
and current map state
while state has following values:
{
matrix: array of 6 tranformation coeficients for svg map
tileMatrix: array of 6 transformation coeficient for tile map
map: reference the map itself
}
callback usage:
callback: function(error , state) {
if(error) {
consol.log(error);
return;
}
// map state can be set as
//get SVG map layer (where id='svgmap')
var svgLayer = document.getElemetnById('svgmap');
svgLayer.setAttribute('transform', 'matrix('+result.matrix.join(', ')+')');
//get map tile layer (where id='tilemap')
var tileLayer = document.getElementById('tilemap');
tileLayer.style.transform = 'matrix('+ result.tileMatrix.join(',') + ')';
}
.setView(params)
Sets a view to the map whereas params are:
this
for callback function.applyDeltaMove(params)
Pans the map by given viewport pixel values for x and y direction. params
are:
this
for callback function.applyDeltaScaleRotation(params)
Scale and rotate the map, params
are:
this
for callback function.resetTileMatrix(params)
Reset tile map matrix so that only rotation transformation is applied, as scale and pan would be null for tile map. This function can be called after every transition/event pan, pinch (scale) and rotate. During transition/event tileMatrix can be applied to tile layer. Generally callback of this function should also check if tiles need to be loaded for current map state. params
are:
this
for callback function.getCenter
Returns viewport center coordinates as an array of x and y in projected coordinate system.
.getResolution
Returns current resolution of the map.
.getRotation
Returns current rotation of the map in degree (clockwise positive)
.getZoom
Returns current zoom level of the map.
.getNearestZoom
When map state is at fractional zoom it returns the nearest non-fractional zoom value.
.getView
Return current map state object as:
{
cetner: array of [x,y]
resolution: float
zoom: float
rotation: float in degrees (clockwise positive)
}
.getExtent
Returns viewport corner coordinates as an array of four x and y coordinates in projected coordinate system.
.toLongLat([x,y])
Converts viewport pixel coordinates to maps projected coordinates ([x,y]).
.toViewport([x,y])
Converts maps projected coordinates to viewport pixel coordinates ([x,y]).
Note: To set center, resolution/zoom and rotation use setView as:
var view = em.getView();
view.rotation = 25;
em.setView({
view: view,
callback: function(error, state) {
if(error) {
console.log(errro);
return;
}
// set matrices to required layers
}
});
```
## developing
Once you run
```npm install```
then for running test
```npm run test```
and to create build
```npm run build```
## license
This project is licensed under the terms of the MIT license.
FAQs
A module that helps in navigation of map like pan, zoom and rotation but does nothing itself.
The npm package emptymap.js receives a total of 53 weekly downloads. As such, emptymap.js popularity was classified as not popular.
We found that emptymap.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.