Skip to content

Commit

Permalink
Generate with a single command the last map you created
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiesigner committed Jan 13, 2020
1 parent 6ffd266 commit 58c491b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Map Generator.sketchplugin/Contents/Sketch/generic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import 'common.js';

function GenericMap () {}

GenericMap.prototype.generateLastMap = function (context) {
if (!checkCount(context)) {
return;
} else {
if (!checkLayerType(context)) {
return;
} else {
var layer = context.selection[0];
var lastService = getPreferences('lastservice', '');
var lastUrl = getPreferences('lasturl', '');
var lastAddress = getPreferences('lastaddress', '');
var lastZoom = getPreferences('lastzoom', '');

if (lastService && lastUrl && lastAddress && lastZoom) {
fillLayerWithImage(lastUrl, layer, context, lastService);
setLayerName(layer, lastAddress, lastZoom);
} else {
context.document.showMessage('⚠️ Please generate a map first.');
}
}
}
};
5 changes: 5 additions & 0 deletions Map Generator.sketchplugin/Contents/Sketch/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ GoogleMap.prototype.generateMap = function (values, context, window) {
var layerSizes = layer.frame();
var imageUrl = 'https://maps.googleapis.com/maps/api/staticmap?center=' + encodeURIComponent(values.address) + '&zoom=' + values.zoom + '&size=' + parseInt([layerSizes width]) + 'x' + parseInt([layerSizes height]) + '&maptype=' + values.type + '&scale=2' + this.parseStyle(values.style, context) + '&key=' + key;

setPreferences('lastservice', this.service);
setPreferences('lasturl', imageUrl);
setPreferences('lastaddress', values.address);
setPreferences('lastzoom', values.zoom);

fillLayerWithImage(imageUrl, layer, context, this.service);
setLayerName(layer, values.address, values.zoom);
this.previewMap(values, context);
Expand Down
10 changes: 10 additions & 0 deletions Map Generator.sketchplugin/Contents/Sketch/main.cocoascript
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "google.js";
@import "mapbox.js";
@import "generic.js";

/**
* Run the Google service provider.
Expand Down Expand Up @@ -34,3 +35,12 @@ function runMapboxToken () {
var mapbox = new MapboxMap();
mapbox.openTokenWindow();
}

/**
* Recreate the last generated map.
* @param {Sketch context} context
*/
function runGenericPreviousMap (context) {
var generic = new GenericMap();
generic.generateLastMap(context);
}
12 changes: 10 additions & 2 deletions Map Generator.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@
"handler": "runMapboxToken",
"identifier": "scriptMapboxToken",
"shortcut": "shift cmd u"
},
{
"script": "main.cocoascript",
"name": "Generate previous Map",
"handler": "runGenericPreviousMap",
"identifier": "scriptPreviousMap",
"shortcut": "shift cmd p"
}
],
"menu" : {
"items" : [
"scriptGoogle",
"scriptGoogleMapsKey",
"scriptMapbox",
"scriptMapboxToken"
"scriptMapboxToken",
"scriptPreviousMap"
],
"title" : "Map Generator"
},
Expand All @@ -45,7 +53,7 @@
"icon": "icon.png",
"identifier" : "io.eduardogomez.sketch.map-generator",
"appcast": "https://raw.githubusercontent.com/eddiesigner/sketch-map-generator/master/appcast.xml",
"version" : "3.5.2",
"version" : "3.5.3",
"description" : "Sketch plugin to fill a layer with a map generated from a given location using Google Maps and Mapbox",
"authorEmail" : "[email protected]",
"name" : "Map Generator"
Expand Down
5 changes: 5 additions & 0 deletions Map Generator.sketchplugin/Contents/Sketch/mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ MapboxMap.prototype.generateMap = function (values, context, window) {

var imageUrl = 'https://api.mapbox.com/styles/v1/' + username + '/' + style + '/static/' + position.lon + ',' + position.lat + ',' + values.zoom + ',0,0/' + parseInt([layerSizes width]) + 'x' + parseInt([layerSizes height]) + '@2x?access_token=' + token;

setPreferences('lastservice', this.service);
setPreferences('lasturl', imageUrl);
setPreferences('lastaddress', values.address);
setPreferences('lastzoom', values.zoom);

fillLayerWithImage(imageUrl, layer, context, this.service);
setLayerName(layer, values.address, values.zoom);
this.previewMap(values, context);
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Voila! Your shape will be filled with a map.

## What’s new?

* ⚡️ You can generate with a single command the last map you created. Just hit <kbd>Cmd</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> and you're done.
* 👉🏼 If you use Mapbox, now you can use your own custom styles!
* 🔥 Map preview! Now you can see a live preview before generating a map.
* 📍 You can move the map preview, drag a pin to pick a location and change the zoom with no effort. You can still change the address settings as before if you wish.
Expand Down
11 changes: 11 additions & 0 deletions appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,16 @@
</description>
<enclosure url="https://github.com/eddiesigner/sketch-map-generator/archive/v3.5.2.zip" sparkle:version="3.5.2" />
</item>
<item>
<title>Version 3.5.3</title>
<description>
<![CDATA[
<ul>
<li>⚡️ Now you can generate with a single command the last map you created. Just hit [cmd] + [shift] + [p]</li>
</ul>
]]>
</description>
<enclosure url="https://github.com/eddiesigner/sketch-map-generator/archive/v3.5.3.zip" sparkle:version="3.5.3" />
</item>
</channel>
</rss>

0 comments on commit 58c491b

Please sign in to comment.