Last active
December 17, 2015 03:09
-
-
Save springmeyer/5541440 to your computer and use it in GitHub Desktop.
marker cache api in node-mapnik
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MarkerCache is a singleton so does not need to be created | |
var mc = mapnik.MarkerCache; | |
// size | |
// should always report `2` since there are `2` built-in markers (ellipse and arrow) | |
mc.size(); | |
// keys | |
// should report the keys of the `2` built-in markers | |
> mc.keys(); | |
['shape://arrow', 'shape://ellipse'] | |
// clear | |
// will clear all markers except built-in markers | |
mc.clear(); | |
// put | |
// can put either images or svg objects | |
// image | |
var image = mapnik.Image.open('./path/to/file.png'); | |
mc.put('./path/to/file.png',image); | |
// svg | |
var svg = mapnik.SVG.open('./path/to/graphics.svg'); | |
mc.put('./path/to/graphics.svg'); | |
// can also load from strings and use custom key | |
var im_mem_image = mapnik.Image.fromString(png_buffer); | |
mc.put(crypto.createHash('md5').update(png_buffer).digest("hex"),in_mem_image); | |
// remove | |
// will remove a cache entry by key name and return true if successfully removed | |
var found = mc.remove('./path/to/file.png'); | |
// get | |
// can get an Image or SVG object out of the cache | |
var image_copy = mc.get('./path/to/file.png'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment