How to add legends in map canvas when exported to PDF ol5refresh the map Ol3 (Openlayers3)nothing is...

Life insurance that covers only simultaneous/dual deaths

Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?

What does おとこえしや mean?

Who is our nearest neighbor

Potentiometer like component

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Draw arrow on sides of triangle

Is a lawful good "antagonist" effective?

Best mythical creature to use as livestock?

Deleting missing values from a dataset

Is it ok to include an epilogue dedicated to colleagues who passed away in the end of the manuscript?

Excess Zinc in garden soil

Force user to remove USB token

Does Linux have system calls to access all the features of the file systems it supports?

Why do Australian milk farmers need to protest supermarkets' milk price?

Is King K. Rool's down throw to up-special a true combo?

Can "semicircle" be used to refer to a part-circle that is not a exact half-circle?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

Can infringement of a trademark be pursued for using a company's name in a sentence?

Am I not good enough for you?

Why must traveling waves have the same amplitude to form a standing wave?

Good allowance savings plan?

Time dilation for a moving electronic clock

What is the difference between "shut" and "close"?



How to add legends in map canvas when exported to PDF ol5


refresh the map Ol3 (Openlayers3)nothing is displayed in my ol3 mapHow to set the maxBound for the map in OL3How print map in ol3 with top resolution?OL3 how group feature?ol3 OSM map stylingHow can I make these two MapServer WMS layers align correctly with each other in OpenLayers?How to add map layer of Italy in map canvas in standalone QGIS applicationHow to give user input scale to export map in pdf ol3how to fix scale 1:4000 to export map in PDF ol3













1















Here is my code to export map in PDF and map is successfully exported to PDF
Now i want to add legends in map canvas but i do not know how to do that.



    var exportElement =  document.getElementById("export-pdf");
exportElement.addEventListener('click', function(e) {

exportElement.disabled = true;
document.body.style.cursor = 'progress';

var format = document.getElementById('format').value;
var resolution = document.getElementById('resolution').value;
var buttonLabelElement = document.getElementById('button-label');
var label = buttonLabelElement.innerText;
var scale = 8000;

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);

var dim = dims[format];
var width = Math.round(dim[0] * resolution / 25.4);
var height = Math.round(dim[1] * resolution / 25.4);
var size = map.getSize();
var extent = map.getView().calculateExtent(size);

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapResolutionAtEquator = mapView.getResolution();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);
var mapResolutionFactor = mapResolutionAtEquator / mapPointResolution;
var pdf_name = dist + "_" + tahsil + "_"+village+ ".pdf";
map.once('rendercomplete', function(event) {

buttonLabelElement.innerText = label;
var canvas = event.context.canvas;
var data = canvas.toDataURL('image/jpeg');
var pdf = new jsPDF('landscape', undefined, format);
pdf.addImage(data, 'JPEG', 0, 0, dim[0], dim[1]);
pdf.save(pdf_name);
map.setSize(size);
map.getView().fit(extent, size);
map.renderSync();
exportElement.disabled = false;
document.body.style.cursor = 'auto';
});


var printPointResolution = (scale * 25.4) /(resolution * 1000);
var printResolutionAtEquator = mapResolutionFactor * printPointResolution;
var printZoom = mapView.getZoomForResolution(printResolutionAtEquator);

map.setSize([width, height]);
mapView.setZoom(printZoom);
map.renderSync();
}, false);









share|improve this question

























  • If your legend is an image take a look at step 2 in this answer stackoverflow.com/questions/41805963/…

    – Mike
    yesterday











  • my legends is not an image its just a color that shows boundary of district and village.

    – sanju verma
    yesterday











  • So it's a layer?

    – TomazicM
    yesterday











  • Question title mentions ol3. Code above uses getZoomForResolution method, so it's at least for ol4.

    – TomazicM
    yesterday











  • Yes TomazicM i edited the question for ol5.

    – sanju verma
    13 secs ago
















1















Here is my code to export map in PDF and map is successfully exported to PDF
Now i want to add legends in map canvas but i do not know how to do that.



    var exportElement =  document.getElementById("export-pdf");
exportElement.addEventListener('click', function(e) {

exportElement.disabled = true;
document.body.style.cursor = 'progress';

var format = document.getElementById('format').value;
var resolution = document.getElementById('resolution').value;
var buttonLabelElement = document.getElementById('button-label');
var label = buttonLabelElement.innerText;
var scale = 8000;

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);

var dim = dims[format];
var width = Math.round(dim[0] * resolution / 25.4);
var height = Math.round(dim[1] * resolution / 25.4);
var size = map.getSize();
var extent = map.getView().calculateExtent(size);

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapResolutionAtEquator = mapView.getResolution();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);
var mapResolutionFactor = mapResolutionAtEquator / mapPointResolution;
var pdf_name = dist + "_" + tahsil + "_"+village+ ".pdf";
map.once('rendercomplete', function(event) {

buttonLabelElement.innerText = label;
var canvas = event.context.canvas;
var data = canvas.toDataURL('image/jpeg');
var pdf = new jsPDF('landscape', undefined, format);
pdf.addImage(data, 'JPEG', 0, 0, dim[0], dim[1]);
pdf.save(pdf_name);
map.setSize(size);
map.getView().fit(extent, size);
map.renderSync();
exportElement.disabled = false;
document.body.style.cursor = 'auto';
});


var printPointResolution = (scale * 25.4) /(resolution * 1000);
var printResolutionAtEquator = mapResolutionFactor * printPointResolution;
var printZoom = mapView.getZoomForResolution(printResolutionAtEquator);

map.setSize([width, height]);
mapView.setZoom(printZoom);
map.renderSync();
}, false);









share|improve this question

























  • If your legend is an image take a look at step 2 in this answer stackoverflow.com/questions/41805963/…

    – Mike
    yesterday











  • my legends is not an image its just a color that shows boundary of district and village.

    – sanju verma
    yesterday











  • So it's a layer?

    – TomazicM
    yesterday











  • Question title mentions ol3. Code above uses getZoomForResolution method, so it's at least for ol4.

    – TomazicM
    yesterday











  • Yes TomazicM i edited the question for ol5.

    – sanju verma
    13 secs ago














1












1








1








Here is my code to export map in PDF and map is successfully exported to PDF
Now i want to add legends in map canvas but i do not know how to do that.



    var exportElement =  document.getElementById("export-pdf");
exportElement.addEventListener('click', function(e) {

exportElement.disabled = true;
document.body.style.cursor = 'progress';

var format = document.getElementById('format').value;
var resolution = document.getElementById('resolution').value;
var buttonLabelElement = document.getElementById('button-label');
var label = buttonLabelElement.innerText;
var scale = 8000;

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);

var dim = dims[format];
var width = Math.round(dim[0] * resolution / 25.4);
var height = Math.round(dim[1] * resolution / 25.4);
var size = map.getSize();
var extent = map.getView().calculateExtent(size);

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapResolutionAtEquator = mapView.getResolution();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);
var mapResolutionFactor = mapResolutionAtEquator / mapPointResolution;
var pdf_name = dist + "_" + tahsil + "_"+village+ ".pdf";
map.once('rendercomplete', function(event) {

buttonLabelElement.innerText = label;
var canvas = event.context.canvas;
var data = canvas.toDataURL('image/jpeg');
var pdf = new jsPDF('landscape', undefined, format);
pdf.addImage(data, 'JPEG', 0, 0, dim[0], dim[1]);
pdf.save(pdf_name);
map.setSize(size);
map.getView().fit(extent, size);
map.renderSync();
exportElement.disabled = false;
document.body.style.cursor = 'auto';
});


var printPointResolution = (scale * 25.4) /(resolution * 1000);
var printResolutionAtEquator = mapResolutionFactor * printPointResolution;
var printZoom = mapView.getZoomForResolution(printResolutionAtEquator);

map.setSize([width, height]);
mapView.setZoom(printZoom);
map.renderSync();
}, false);









share|improve this question
















Here is my code to export map in PDF and map is successfully exported to PDF
Now i want to add legends in map canvas but i do not know how to do that.



    var exportElement =  document.getElementById("export-pdf");
exportElement.addEventListener('click', function(e) {

exportElement.disabled = true;
document.body.style.cursor = 'progress';

var format = document.getElementById('format').value;
var resolution = document.getElementById('resolution').value;
var buttonLabelElement = document.getElementById('button-label');
var label = buttonLabelElement.innerText;
var scale = 8000;

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);

var dim = dims[format];
var width = Math.round(dim[0] * resolution / 25.4);
var height = Math.round(dim[1] * resolution / 25.4);
var size = map.getSize();
var extent = map.getView().calculateExtent(size);

var mapView = map.getView();
var mapProjection = mapView.getProjection();
var mapResolutionAtEquator = mapView.getResolution();
var viewCenter = mapView.getCenter();
var mapResolutionAtEquator = mapView.getResolution();
var mapPointResolution = ol.proj.getPointResolution(mapProjection, mapResolutionAtEquator, viewCenter);
var mapResolutionFactor = mapResolutionAtEquator / mapPointResolution;
var pdf_name = dist + "_" + tahsil + "_"+village+ ".pdf";
map.once('rendercomplete', function(event) {

buttonLabelElement.innerText = label;
var canvas = event.context.canvas;
var data = canvas.toDataURL('image/jpeg');
var pdf = new jsPDF('landscape', undefined, format);
pdf.addImage(data, 'JPEG', 0, 0, dim[0], dim[1]);
pdf.save(pdf_name);
map.setSize(size);
map.getView().fit(extent, size);
map.renderSync();
exportElement.disabled = false;
document.body.style.cursor = 'auto';
});


var printPointResolution = (scale * 25.4) /(resolution * 1000);
var printResolutionAtEquator = mapResolutionFactor * printPointResolution;
var printZoom = mapView.getZoomForResolution(printResolutionAtEquator);

map.setSize([width, height]);
mapView.setZoom(printZoom);
map.renderSync();
}, false);






openlayers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 min ago







sanju verma

















asked yesterday









sanju vermasanju verma

388




388













  • If your legend is an image take a look at step 2 in this answer stackoverflow.com/questions/41805963/…

    – Mike
    yesterday











  • my legends is not an image its just a color that shows boundary of district and village.

    – sanju verma
    yesterday











  • So it's a layer?

    – TomazicM
    yesterday











  • Question title mentions ol3. Code above uses getZoomForResolution method, so it's at least for ol4.

    – TomazicM
    yesterday











  • Yes TomazicM i edited the question for ol5.

    – sanju verma
    13 secs ago



















  • If your legend is an image take a look at step 2 in this answer stackoverflow.com/questions/41805963/…

    – Mike
    yesterday











  • my legends is not an image its just a color that shows boundary of district and village.

    – sanju verma
    yesterday











  • So it's a layer?

    – TomazicM
    yesterday











  • Question title mentions ol3. Code above uses getZoomForResolution method, so it's at least for ol4.

    – TomazicM
    yesterday











  • Yes TomazicM i edited the question for ol5.

    – sanju verma
    13 secs ago

















If your legend is an image take a look at step 2 in this answer stackoverflow.com/questions/41805963/…

– Mike
yesterday





If your legend is an image take a look at step 2 in this answer stackoverflow.com/questions/41805963/…

– Mike
yesterday













my legends is not an image its just a color that shows boundary of district and village.

– sanju verma
yesterday





my legends is not an image its just a color that shows boundary of district and village.

– sanju verma
yesterday













So it's a layer?

– TomazicM
yesterday





So it's a layer?

– TomazicM
yesterday













Question title mentions ol3. Code above uses getZoomForResolution method, so it's at least for ol4.

– TomazicM
yesterday





Question title mentions ol3. Code above uses getZoomForResolution method, so it's at least for ol4.

– TomazicM
yesterday













Yes TomazicM i edited the question for ol5.

– sanju verma
13 secs ago





Yes TomazicM i edited the question for ol5.

– sanju verma
13 secs ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315190%2fhow-to-add-legends-in-map-canvas-when-exported-to-pdf-ol5%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f315190%2fhow-to-add-legends-in-map-canvas-when-exported-to-pdf-ol5%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Щит и меч (фильм) Содержание Названия серий | Сюжет |...

is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

Meter-Bus Содержание Параметры шины | Стандартизация |...